/eslint-pattern-rules:eslint-pattern-rulesfrom eslint-pattern-rules
Turn a codebase's own conventions into custom ESLint or oxlint rules with RuleTester tests, and suggest well-known lint rules it is missing. Use when the user wants a custom ESLint or oxlint rule or local plugin, asks which of their patterns, ADRs or CLAUDE.md / AGENTS.md instructions could become lint rules, asks which clean-code, bug-prevention, security or test rules the project lacks, or wants to enforce a convention the code mostly follows. Not for fixing existing lint errors; for backend languages use backend-pattern-rules instead.
Ships in eslint-pattern-rules. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
A convention is what the codebase already mostly does, or what one of its decision records chose. This skill encodes one convention per rule, so the majority pattern becomes the only pattern. The project's code and decisions are the source of truth, and the user settles every design choice. Nothing is written until the user has picked it.
A rule also saves context: a convention written as prose in CLAUDE.md or AGENTS.md is read by every agent session, while a rule costs nothing until it is broken.
Count and locate with rg -c / rg -n, always with a path (in scripts, rg without one waits on stdin) (with several -g globs the last matching one wins, so put exclusions like -g '!*.spec.ts' after the includes), and open a file only for details a count can't give.
Look each of these up rather than asking:
eslint.config.*, .eslintrc*) or oxlint (.oxlintrc.json, .oxlintrc.jsonc, oxlint.config.ts, oxlint in the lint script).
oxlint without ESLint: read references/oxlint.md now and apply its differences in steps 2, 4 and 5; with ESLint at all, follow this file as written.node -p "require('eslint/package.json').version". v9+ uses the flat APIs, v8 the legacy ones.
When node_modules is missing, ask before installing dependencies (npm ci --ignore-scripts with a lockfile, npm install --ignore-scripts --no-package-lock without one, both git-ignored); without them, report every count that needs ESLint as "not counted".tsconfig.json paths, and test runner..yo-rc.json, .jhipster/, .openapi-generator/, @Generated, or DO NOT EDIT headers, and the source folders each generator owns.
A rule still guards new code there, but existing hits are fixed in the generator's template or blueprint, not by hand: say so for each hit in generated code.docs/adr/, docs/decisions/, notes/decisions/, ADR-*.md, CONTRIBUTING.CLAUDE.md, AGENTS.md and GEMINI.md in the repo, .github/copilot-instructions.md, .github/instructions/*.md, .cursor/rules/, .cursorrules, .windsurfrules.Done when you can state each of these in one line.
references/discovery.md and follow it. It covers the scan of code, decision records and agent docs, the general rules from references/general-rules.md, what is already enforced, risk, the mode question (automatic or manual), and the selection dialog.Under oxlint, built-in rules and their counting follow references/oxlint.md.
A built-in rule wins when it can express the convention (no-restricted-syntax, no-restricted-imports, max-params, or a rule from an installed plugin). Offer its exact config as the candidate. Once picked, add it to the ESLint config, scoped by files, and verify it with the project's own ESLint run instead of steps 4 and 5. A custom rule earns its place when the logic needs scope, paths, options, a tailored message or a fix.
A built-in rule carries its message in its config: give every no-restricted-syntax, no-restricted-imports, no-restricted-globals and no-restricted-properties entry a message as step 3 describes, because the default message only names the selector, the import or the name, and check that the project's ESLint run shows it.
Done when every convention you will build has its good examples and its full violation list.
For each rule, work through these, skipping whatever the code already answers:
p["then"]), and fully qualified or global-qualified access (globalThis.Date.now(), window.fetch(...)).files globs. Use rule options only when the logic itself depends on paths (layer A must not import layer B). Folder names live in config or options, so the rule fits any layout.schema and a default that fits the project, such as aliases read from tsconfig.json.fix when behavior is provably unchanged, suggest when a human should confirm, none otherwise.gen-<name>).
The message says what is wrong, what to write instead, and where the rule comes from (ADR 0043, or the agent doc it replaces), in one sentence: once its agent-doc line is gone, the message is all an agent sees.Ask with AskUserQuestion, in rounds of up to 4 questions whose prerequisites are settled. Put your recommended answer first and label it "(Recommended)". Show a real code example in the question or in an option's preview. Without the tool, ask the same rounds as a numbered list in chat.
When the rule was selected automatically, or nobody can answer, answer with your recommendations and take the safer side: suggest over fix and the narrower scope.
Severity: always error.
With no open hits the rule goes in the main config, because nothing old breaks; with open hits it goes in the suggestions layer (step 4), so CI stays green while agent feedback loops, which block only on errors, still show it on new code.
Step 7 puts these answers to the user.
Done when every question has an answer and you know who gave it.
Under oxlint, the folder, registration, suggestions layer and tests follow references/oxlint.md, and nothing is installed: the package.json rules below about installing ESLint or parsers are for the ESLint path only. The rule object and its gotchas below stay the same.
Each rule is exactly two files, both prefixed gen- so generated rules stay distinct from hand-written ones:
<rules-dir>/gen-<name>.js
<rules-dir>/gen-<name>.test.js
<rules-dir> is the existing custom-rules folder, or else eslint-rules/ at the repo root. The rule id is local/gen-<name>. Hand-written rules stay as they are. If the folder has a rules index, add the new rule to it in the index's existing style.
Write plain JS in the project's module format, one convention per rule. Comment only where the logic is non-obvious, and leave out doc blocks and meta.docs. The gotchas that bite here:
meta.schema is always set ([] for no options): v9 rejects options a rule has no schema for.:function, decide on :function:exit), not by walking node.parent or re-traversing a body per match, which goes O(n²) on large files.ImportDeclaration, ImportExpression, ExportNamed/AllDeclaration with a source, and require(). They match the resolved target path (relative specifiers resolved against context.filename, aliases from tsconfig paths), with separators normalised to /.sourceCode.parserServices.defineTemplateBodyVisitor, guarded for its absence. Type-aware logic is guarded on parserServices?.program, so the rule degrades instead of crashing where type info is not configured.describe/it. Under vitest without globals or under node:test, assign RuleTester.describe, RuleTester.it and RuleTester.itOnly first, and place the test file where the runner's include pattern finds it.Build the tests from the real code:
valid: the convention and every allowed edge case.invalid: each kind of violation, with its messageId plus output (or output: null).package.json stays byte-identical whenever ESLint is installed, directly or through another tool. A parser the project lacks goes into your report as an install command with an exact version on every package (npm i -D --save-exact @typescript-eslint/[email protected]), and the tests use syntax the installed parsers can read. try-rule.mjs still checks .ts and .vue files without those parsers. Only when ESLint is absent altogether, install eslint plus the parsers the project's languages need:
npm i -D --save-exact [email protected], pnpm add -D -E, yarn add -D --exact or bun add -d --exacteslint, typescript-eslint, @typescript-eslint/parser, vue-eslint-parser, svelte-eslint-parser, astro-eslint-parserRun tools from node_modules/.bin/ or with npx --no-install.
Register the rule in the ESLint config yourself, without asking: it is part of building the rule, not a design choice. Add only what the rule needs and leave every other entry as it is:
plugins: {local: ...} entry), otherwise add plugins: {local: {rules: {'gen-<name>': rule}}}. Enable 'local/gen-<name>' at the agreed severity and options, in a config object scoped by the agreed files..eslintrc: register it through the project's existing local-rules mechanism (eslint-plugin-local-rules, --rulesdir). When there is none, the registration would need a new package, so leave the config as it is and put the snippet and its install command in the report.Suggestions layer, for a rule the existing code breaks.
At error in the main config it would fail CI on day one; at warning nobody sees it, since feedback loops block only on errors.
So it goes into a second config at error and stays out of the main one:
eslint.config.suggestions.mjs beside the main config, importing it and adding one object with the suggestion rules, scoped by their files:
import base from './eslint.config.mjs';
export default [...base, { name: 'suggestions', files: ['src/**/*.ts'], rules: { 'local/gen-<name>': 'error' } }];
Spread the main config the way its export is built (an array, defineConfig(...), tseslint.config(...)), and register the local plugin in the main config, so it is defined once..eslintrc: .eslintrc.suggestions.cjs holding only the suggestion rules; eslint -c .eslintrc.suggestions.cjs merges it over the project's own config.npx --no-install eslint -c <suggestions config> <files>; CI keeps running the main config.
package.json stays byte-identical, so propose a lint:suggestions script in the report.Under oxlint, use try-oxlint.mjs and the project's oxlint as references/oxlint.md describes.
node <skill-dir>/scripts/try-rule.mjs <rules-dir>/gen-<name>.js [paths...] [--options '<json>'] [--fix-dry-run]
valid test and a rule fix, then a rerun. Report any file type the "Parsers" line lists as skipped or only partly checked.local/gen-<name>; for a suggestion rule, run it with -c <suggestions config>, and run the main config once more to confirm it reports nothing new.Done when the tests pass, every hit is accounted for, the project's ESLint reports the rule, and its message names its source.
Only for a rule built or enabled in this run and verified (a custom rule through step 5, a config change through the project's own ESLint run), and only for the agent-doc lines that state the convention it now enforces.
A rule in the suggestions layer counts: a feedback loop that runs the suggestions config shows it on every changed line.
Without such a loop, say in the question that only people who run the suggestions config see it.
The cleanup always asks, in both modes: it changes a doc.
In manual mode, ask one AskUserQuestion per rule; in automatic mode, ask the lines of every built rule in one call after the builds.
Quote each line with its file and line number:
Data fetching: hooks only (enforced by local/gen-<name>).: recommended when the convention shapes code before it is written, so an agent that never saw it would build the wrong thing and redo it.
The pointer goes where the agent will load it: a CLAUDE.md in the folder the rule applies to, or an instructions file with an applyTo glob for those paths.
A pointer left only in a file the agent has to follow a link to read is not seen up front, so propose the place in the same question.Before recommending a delete, make sure the rule's message carries what the line said, plus the ADR link if there is one. A built-in rule whose tool has no message field, or whose message does not carry the line, never gets the delete option: offer the pointer or keep. Edit the doc only as answered, and never touch a line no verified rule covers. With nobody to answer, change no doc and list the lines in the report.
Done when every covered line is answered or listed.
Keep it short:
lint:suggestions script, and that each rule moves to the main config once its hits reach 0codemyrules feedback loop; without it a broken rule only surfaces in CI, after the sessionIf you answered design questions on the user's behalf, close with one AskUserQuestion round that presents those answers, with yours as the first option. Apply the changes, then rerun step 5 for that rule.
With nobody to answer, end the report with those answers as a numbered list instead, each with its reason and the alternative.
agents/openai.yaml (opens in a new tab)references/discovery.md (opens in a new tab)references/general-rules.md (opens in a new tab)references/oxlint.md (opens in a new tab)references/pattern-catalog.md (opens in a new tab)scripts/test/try-oxlint.test.mjs (opens in a new tab)scripts/try-oxlint.mjs (opens in a new tab)scripts/try-rule.mjs (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
eslint-pattern-rules@codemyrules is listed by clirimajeti/codemyrules — review the source before installing
npx claudepluginhub clirimajeti/codemyrules --plugin eslint-pattern-rules