templates/skills/languages/javascript/SKILL.md
Execute these commands after EVERY implementation (see AGENT_AUTOMATION module for full workflow).
npx skillsauth add hivellm/rulebook JavaScriptInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
CRITICAL: Execute these commands after EVERY implementation (see AGENT_AUTOMATION module for full workflow).
# Complete quality check sequence:
npm run lint # Linting (0 warnings required)
npm run format # Code formatting
npm test # All tests (100% pass required)
npm run test:coverage # Coverage check (95%+ required)
npm run build # Build verification (if applicable)
# Security audit:
npm audit --production # Vulnerability scan
npm outdated # Check outdated deps
CRITICAL: Use modern JavaScript (ES2022+) with strict linting and testing.
"type": "module" in package.json{
"name": "your-package",
"version": "1.0.0",
"description": "Package description",
"type": "module",
"main": "./dist/index.js",
"exports": {
".": {
"import": "./dist/index.js"
}
},
"files": [
"dist",
"README.md",
"LICENSE"
],
"scripts": {
"build": "esbuild src/index.js --bundle --platform=node --outfile=dist/index.js",
"test": "vitest --run",
"test:watch": "vitest",
"test:coverage": "vitest --coverage",
"lint": "eslint src/**/*.js tests/**/*.js",
"lint:fix": "eslint src/**/*.js tests/**/*.js --fix",
"format": "prettier --write 'src/**/*.js' 'tests/**/*.js'",
"format:check": "prettier --check 'src/**/*.js' 'tests/**/*.js'"
},
"engines": {
"node": ">=18.0.0"
},
"devDependencies": {
"eslint": "^9.19.0",
"prettier": "^3.4.0",
"vitest": "^2.1.0",
"@vitest/coverage-v8": "^2.1.0",
"esbuild": "^0.24.0"
}
}
CRITICAL: After implementing ANY feature, you MUST run these commands in order.
IMPORTANT: These commands MUST match your GitHub Actions workflows to prevent CI/CD failures!
# Pre-Commit Checklist (MUST match .github/workflows/*.yml)
# 1. Lint (MUST pass with no warnings - matches workflow)
npm run lint
# 2. Format check (matches workflow - use check, not write!)
npm run format:check
# or: npx prettier --check 'src/**/*.js' 'tests/**/*.js'
# 3. Run all tests (MUST pass 100% - matches workflow)
npm test
# 4. Build (if applicable - matches workflow)
npm run build
# 5. Check coverage (MUST meet threshold)
npm run test:coverage
# If ANY fails: ❌ DO NOT COMMIT - Fix first!
If ANY of these fail, you MUST fix the issues before committing.
Why This Matters:
prettier --write locally but prettier --check in CI = failureeslint.config.jsExample eslint.config.js:
import js from '@eslint/js';
export default [
js.configs.recommended,
{
files: ['src/**/*.js', 'tests/**/*.js'],
languageOptions: {
ecmaVersion: 2022,
sourceType: 'module',
globals: {
console: 'readonly',
process: 'readonly',
},
},
rules: {
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'no-console': 'off', // Allow console in Node.js
'prefer-const': 'error',
'no-var': 'error',
},
},
];
.prettierrc.jsonExample .prettierrc.json:
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2,
"arrowParens": "always"
}
/tests directoryvitest or vitest --watch for developmentnpm test command MUST include --run flag
package.json: "test": "vitest --run"npm run test:watchExample test structure:
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { myFunction } from '../src/module.js';
describe('myFunction', () => {
let testData;
beforeEach(() => {
testData = { value: 'test' };
});
afterEach(() => {
// Cleanup
});
it('should return expected value', () => {
const result = myFunction(testData);
expect(result).toBe('expected');
});
it('should throw on invalid input', () => {
expect(() => myFunction(null)).toThrow('Invalid input');
});
});
CRITICAL: Separate fast tests from slow/S2S tests.
Problem: Mixing fast unit tests with slow integration tests or tests requiring external servers causes:
Solution: Isolate S2S and slow tests using environment variables and tags.
S2S (Server-to-Server) Tests:
Slow Tests:
Fast Tests (Regular Unit Tests):
1. Mark S2S/slow tests with conditional execution:
// tests/integration/database.test.js
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { setupDatabase, teardownDatabase } from './test-helpers.js';
// Only run if RUN_S2S_TESTS environment variable is set
const runS2STests = process.env.RUN_S2S_TESTS === '1';
const describeS2S = runS2STests ? describe : describe.skip;
describeS2S('Database Integration', () => {
beforeAll(async () => {
await setupDatabase();
});
afterAll(async () => {
await teardownDatabase();
});
it('should connect to database', async () => {
const result = await query('SELECT 1');
expect(result).toBeDefined();
}, { timeout: 30000 }); // 30 second timeout for S2S tests
});
2. Mark slow tests similarly:
// tests/slow/file-processing.test.js
const runSlowTests = process.env.RUN_SLOW_TESTS === '1';
const describeSlow = runSlowTests ? describe : describe.skip;
describeSlow('Large File Processing', () => {
it('should process 1GB file', async () => {
const result = await processLargeFile('large-file.dat');
expect(result).toBeDefined();
}, { timeout: 60000 }); // 60 second timeout
});
3. Organize tests by speed:
tests/
├── unit/ # Fast tests (< 100ms) - DEFAULT
│ ├── parser.test.js
│ └── validator.test.js
├── integration/ # S2S tests (require servers)
│ ├── database.test.js
│ └── api.test.js
└── slow/ # Slow tests (> 5 seconds)
└── file-processing.test.js
4. Add npm scripts in package.json:
{
"scripts": {
"test": "vitest --run",
"test:watch": "vitest",
"test:s2s": "RUN_S2S_TESTS=1 vitest --run",
"test:slow": "RUN_SLOW_TESTS=1 vitest --run",
"test:all": "RUN_S2S_TESTS=1 RUN_SLOW_TESTS=1 vitest --run"
}
}
Windows users: Use cross-env for environment variables:
npm install --save-dev cross-env
{
"scripts": {
"test:s2s": "cross-env RUN_S2S_TESTS=1 vitest --run",
"test:slow": "cross-env RUN_SLOW_TESTS=1 vitest --run"
}
}
{ timeout: 30000 } for S2S testsRUN_S2S_TESTS and RUN_SLOW_TESTSFast test (runs by default):
// tests/unit/calculator.test.js
import { describe, it, expect } from 'vitest';
import { add, multiply } from '../src/calculator.js';
describe('Calculator', () => {
it('should add numbers', () => {
expect(add(2, 3)).toBe(5);
});
it('should multiply numbers', () => {
expect(multiply(2, 3)).toBe(6);
});
});
S2S test (skipped by default):
// tests/integration/api.test.js
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
const runS2STests = process.env.RUN_S2S_TESTS === '1';
const describeS2S = runS2STests ? describe : describe.skip;
describeS2S('API Integration', () => {
let server;
beforeAll(async () => {
// Start server on port 3001
server = await startTestServer(3001);
});
afterAll(async () => {
await server.close();
});
it('should fetch users from API', async () => {
const response = await fetch('http://localhost:3001/users');
expect(response.status).toBe(200);
const data = await response.json();
expect(Array.isArray(data)).toBe(true);
}, { timeout: 30000 });
});
Running tests:
# Fast tests only (default - for development and CI)
npm test
# Include S2S tests (manual or scheduled CI)
npm run test:s2s
# Include slow tests
npm run test:slow
# All tests (nightly builds)
npm run test:all
import/export)"type": "module" in package.json.js extensions in imports for Node.js compatibilityrequire/module.exports) in new codeExample:
// Good: ES modules with .js extension
import { myFunction } from './my-module.js';
import fs from 'node:fs';
export { myFunction };
export default class MyClass {}
// Bad: CommonJS
const { myFunction } = require('./my-module');
module.exports = { myFunction };
Example:
export class ValidationError extends Error {
constructor(message, field) {
super(message);
this.name = 'ValidationError';
this.field = field;
}
}
export async function fetchData(url) {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
return await response.json();
} catch (error) {
if (error instanceof TypeError) {
throw new ValidationError('Invalid URL', 'url');
}
throw error;
}
}
Example:
/**
* Processes the input data and returns a formatted result.
*
* @param {string} input - The input string to process
* @param {Object} [options] - Optional processing options
* @param {boolean} [options.trim=false] - Whether to trim whitespace
* @returns {string} The processed string in uppercase
* @throws {ValidationError} If input is empty
*
* @example
* ```javascript
* const result = process('hello', { trim: true });
* console.log(result); // 'HELLO'
* ```
*/
export function process(input, options = {}) {
if (!input) {
throw new ValidationError('Input cannot be empty', 'input');
}
const processed = options.trim ? input.trim() : input;
return processed.toUpperCase();
}
Example:
// Good: Async/await with error handling
export async function processMultiple(urls) {
try {
const results = await Promise.all(
urls.map(url => fetchData(url))
);
return results;
} catch (error) {
console.error('Failed to process URLs:', error);
throw error;
}
}
// Bad: Callback hell
function processMultipleCallback(urls, callback) {
let results = [];
urls.forEach((url, i) => {
fetchDataCallback(url, (err, data) => {
if (err) return callback(err);
results.push(data);
if (i === urls.length - 1) callback(null, results);
});
});
}
CRITICAL: Use consistent package manager across team.
package-lock.json, pnpm-lock.yaml, or yarn.lock)
setup-node with cache: 'npm' requires lockfile to be committedpackage-lock.json and use npm ci in workflowsCheck for latest versions:
npm view <package> versionsDependency Guidelines:
"1.2.3")"^1.2.3")npm audit for securityCRITICAL: GitHub Actions cache: 'npm' requires package-lock.json to be committed.
Must include GitHub Actions workflows for:
Testing (javascript-test.yml):
Linting (javascript-lint.yml):
npm run lintnpm run format:checkBuild (javascript-build.yml):
npm run buildproject/
├── package.json # Package manifest
├── package-lock.json # Lockfile (MUST commit for CI cache)
├── eslint.config.js # ESLint configuration
├── .prettierrc.json # Prettier configuration
├── vitest.config.js # Test configuration
├── README.md # Project overview
├── LICENSE # Project license
├── src/
│ ├── index.js # Main entry point
│ └── ...
├── tests/ # Test files
├── dist/ # Build output (gitignored)
└── docs/ # Documentation
===) over loose equality (==)var (use const or let)== (use ===)node_modules/.env filesnpm audit regularly.env files (add to .gitignore)Example .env:
API_KEY=your-secret-key
DATABASE_URL=postgres://localhost/db
Load with:
import 'dotenv/config';
const apiKey = process.env.API_KEY;
<!-- JAVASCRIPT:END -->research
Author a rulebook task spec interactively — research, draft, ask the user clarifying questions, confirm, then create the tasks in rulebook ready for /rulebook-driver. Use when the user wants to plan/spec a feature before implementing.
development
Behavioral guidelines to reduce common LLM coding mistakes — overcomplication, sloppy refactors, hidden assumptions, weak goals. Use when writing, reviewing, or refactoring code. Auto-applies; invoke explicitly via /karpathy-guidelines or 'follow karpathy discipline'.
data-ai
Autonomous AI agent loop for iterative task implementation (@hivehub/rulebook ralph)
data-ai
Use SQL Server for enterprise relational data storage with advanced features, high availability, and Windows integration.