add-lint-rule
Skill247 starsChanged 24 days agoMITView on GitHub
Add a new built-in lint rule to the Panache linter — wire it into
3 other projects use a version of this.
Adopted by
Most recently taken up by
- purplefish-ai/factory-factorytheir own version, first seen Nov 15, 2026
- DataDog/dd-trace-dotnettheir own version, first seen Nov 2, 2026
- UnknownPlatypus/djangofmttheir own version, first seen Oct 9, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- DataDog/dd-trace-dotnet★ 573same name
- UnknownPlatypus/djangofmt★ 105same name
- purplefish-ai/factory-factory★ 54same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository11 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- add-syntax-constructSkill
- commonmark-conformanceSkill
- external-toolsSkill
- html-conformanceSkill
- linter-investigationSkill
- math-parser-formatterSkill
- pandoc-ir-migrateSkill
- perf-investigationSkill
- smoke-test-triageSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 5 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Use this skill when asked to add a new built-in lint rule (warning, error, or info), regardless of whether it ships with an auto-fix.
- Very specific: line 76
Add a new variant, its is_satisfied branch, and its description in src/linter/docs.rs only if no existing one fits.
- Distinctive: line 99
When adding parser support, test it independently and confirm that existing CST snapshots remain unchanged if the refactor preserves …
- Very specific: line 152
Add pub mod <rule_name>; to src/linter/rules.rs (alphabetical, with the rest of the pub mod list).
- Very specific: line 154
Add one Box::new(rules::<rule_name>::<Name>Rule) entry to all_rules() in src/linter.rs.
- Very specific: line 161
Put the explanation in src/linter/rules/docs/<rule-name>.md and return it from description() using include_str!
- Very specific: line 172
Add an example of any auto-fix.
- Distinctive: line 174
Do not write diagnostic text or fixed output by hand.
- Very specific: line 175
Run task docs:rules, then review docs/reference/_linter-rules.qmd.
- Very specific: line 177
Update any illustrative references in docs/guide/linting.qmd if needed.
- Distinctive: line 193
Do keep diagnostic spans tight (point at the offending construct, not the whole line/paragraph) — this drives both the CLI caret and LSP …
- Very specific: line 195
Do put rule logic in the rule module.
- Distinctive: line 203
Don't: add a fix that changes prose semantics.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Use this skill when asked to add a new built-in lint rule (warning, error, or info), regardless of whether it ships with an auto-fix.
Scope boundaries
- Built-in lint rules only. External-linter integrations (black, flake8, etc.)
live in
src/linter/external_linters*and are out of scope here. - Rule logic walks the parser CST/AST. Preserve correct parsing and formatting
behavior when adding diagnostics. Parser support refactors are appropriate
when they expose information the rule needs through a typed wrapper in
crates/panache-parser/src/syntax/or the existing diagnostic channel. Keep rule codes, severity, selection, and fixes in the linter. - Malformed syntax may correctly fall back to
TEXT, so a rule that only visits recognized construct nodes can miss it. If the syntax already has a parser recognizer, reuse it through a typed syntax helper instead of adding another scanner in the rule. Account for token boundaries, multiline constructs, and container prefixes when returning host-aligned ranges, and preserve literal and escaped contexts. - LSP and CLI consume diagnostics through the same
LintRunner. The rule must not emit CLI-formatted strings; it producesDiagnosticvalues and the shared rendering paths handle presentation.
Key files
src/linter/rules.rs—Ruletrait (note the requiredmetadata()method), theRuleMeta/DiagnosticCode/Requirementtypes,RuleRegistry, and thepub modlist. Every new rule module is declared here.src/linter/rules/<rule_name>.rs— one file per rule. Contains thepub struct <Name>Ruleplus itsimpl Rule(includingmetadata()) and unit tests.src/linter.rs—all_rules()lists every rule once;default_registry()is data-driven: it filtersall_rules()by each rule'sRuleMeta::{requires, default_on}andconfig.lint. There is no per-ruleifguard to add.builtin_rule_metadata()exposes the metadata for tests.src/linter/diagnostics.rs—Diagnostic,Severity,Location,Edit,Fix,DiagnosticNoteKind. The full builder API for diagnostics.src/syntax.rs— re-exportsSyntaxKind,SyntaxNode, and typed AST wrappers frompanache_parser::syntax.tests/linting.rs+tests/linting/<rule_name>.{md,qmd,Rmd}— integration test fixtures. Pattern: a focused fixture file plus a#[test]that filters diagnostics bycodeand asserts count, span, and (if present) fix shape.src/linter/rules/docs/<rule-name>.md— authored rule explanations, loaded by each rule'sdescription(). Keep these focused on the warning's effect and how to resolve it, without parser internals or development logs.src/linter/docs.rs—Example, executable example setup, and the reference renderer.docs/reference/_linter-rules.qmdis generated bytask docs:rulesand included bydocs/reference/linter-rules.qmd; never edit it by hand.tests/linter_rules_docs.rs— checks every rule and code has an example, verifies expected codes and severities, checks fix behavior and anchors, and rejects stale generated output.docs/guide/linting.qmd— user-facing prose guide; links to the reference and lists the default[lint.rules]keys. Update the example key list there too.
Workflow
- Pick the rule name (kebab-case) — this is the diagnostic
code, the config key under[lint.rules], and the slug used in URLs/help text. It must be unique and stable: renaming it is a breaking config change. Match tone of existing names (heading-hierarchy,duplicate-reference-labels,adjacent-footnote-refs). - Decide gating before writing code — these become fields on the rule's
RuleMeta, the single source of truth for both registration and the docs:- Severity:
Warningis the default;Erroronly for genuinely broken output;Infois reserved. A rule with several codes can mix severities; declare each inRuleMeta::codes. requires: theRequirementvariant matching the syntax or flavor the rule needs. Add a new variant, itsis_satisfiedbranch, and its description insrc/linter/docs.rsonly if no existing one fits.default_on:truefor rules that run unless disabled;falsefor opt-in rules (registered only viais_rule_explicitly_enabled, documented with aDefault: Offfield).- Auto-fix: only ship a
Fixwhen the replacement is unambiguous and preserves intent. If multiple resolutions are valid (rename vs delete vs merge), omit the fix and explain why in the docs. SetRuleMeta::auto_fixaccordingly.
- Severity:
- Write a failing test first (TDD per
AGENTS.md). Either:- a unit test inside the new module under
#[cfg(test)] mod tests, usingcrate::parser::parse(input, Some(config.clone()))and callingRule::check_tree(&tree, input, &config, metadata).check_treeis the default trait method that builds a one-offLintIndexfor just this rule's declared interests and runs it — tests use it becauseRule::checkitself takes a&LintContext, which the runner (not tests) constructs. or - an integration fixture under
tests/linting/<rule_name>.{md,qmd,Rmd}and a#[test]intests/linting.rsthat callslint_file(...)and filters byd.code == "<rule-name>". Cover the positive case, the negative ("should not flag") case, and any edge case the rule explicitly handles. When adding parser support, test it independently and confirm that existing CST snapshots remain unchanged if the refactor preserves parsing behavior.
- a unit test inside the new module under
- Implement the rule in
src/linter/rules/<rule_name>.rs:- Rules do not walk the tree themselves. The runner does one shared
tree.preorder_with_tokens()pass and buckets nodes bySyntaxKind; declare which kinds you want vianode_interests()and read your bucket withcx.nodes(KIND)instead oftree.descendants(). This keeps a lint pass at one traversal no matter how many rules exist. - Cast bucket nodes to typed wrappers where available
(
cx.nodes(SyntaxKind::LINK).iter().cloned().filter_map(Link::cast)) — typed wrappers are preferred wherever they exist. For multi-kind rules, list every kind innode_interests()and iterate each bucket. - To scan
TEXTtokens (e.g. byte-pattern checks), returntruefromwants_text_tokens()and iteratecx.text_tokens(). - Salsa-index-backed rules (those that use
symbol_usage_index_from_tree(.., cx.tree, ..)and never read a bucket) leavenode_interests()at its empty default. - Build
LocationwithLocation::from_range(range, input)orLocation::from_node(node, input). - For auto-fixes, prefer insertions (zero-width
TextRange::new(p, p)) and replacements over a precise span rather than rewriting whole nodes. Multi-edit fixes are allowed but must be independent — they are applied in source order. - Honor the trait shape exactly. Implement
metadata()(required), declare interests, then take a&LintContext(which bundlestree/input/config/metadata/index):fn metadata(&self) -> RuleMeta { RuleMeta { name: "<rule-name>", default_on: true, requires: Requirement::Always, auto_fix: false, codes: const { &[DiagnosticCode::warning("<rule-name>")] }, } } fn node_interests(&self) -> &'static [SyntaxKind] { &[SyntaxKind::LINK] // omit (defaults to &[]) for index-backed rules } fn check(&self, cx: &LintContext) -> Vec<Diagnostic> { let input = cx.input; // also cx.tree / cx.config / cx.metadata as needed // ... iterate cx.nodes(SyntaxKind::LINK) ... }codesis&'static [DiagnosticCode]; wrap the array in aconst { … }block (the::warning/::error/::infoconst constructors are not rvalue-promotable on their own). Import the new types alongside the trait:use crate::linter::rules::{DiagnosticCode, LintContext, Requirement, Rule, RuleMeta};.
- Rules do not walk the tree themselves. The runner does one shared
- Wire it up (no
if-guard — registration is data-driven frommetadata()):- Add
pub mod <rule_name>;tosrc/linter/rules.rs(alphabetical, with the rest of thepub modlist). - Add one
Box::new(rules::<rule_name>::<Name>Rule)entry toall_rules()insrc/linter.rs.default_registry()filters that list by the rule'sRuleMeta::{requires, default_on}andconfig.lint, so the gating you declared in step 2 takes effect automatically — there is nothing else to edit. (Opt-out via[lint.rules]is handled centrally for every rule.)
- Add
- Add the rule's description and executable examples:
- Put the explanation in
src/linter/rules/docs/<rule-name>.mdand return it fromdescription()usinginclude_str!. Explain what is wrong, why it affects the document, and how to resolve it. For multiple codes, usecode_description()for any extra explanation each code needs. - Implement
examples()under#[cfg(not(target_arch = "wasm32"))]. Return aconst { &[Example::new(source, &["expected-code"])] }fromcrate::linter::docs. Every declared code needs an example that emits it; each example must emit exactly its expected set of codes. - Examples default to the Quarto flavor. Use
.flavor(...),.config(...), and.companions(...)for other dialects, settings, or bibliography files. The runner selects only the documented rule and reads no personal config. - Add an example of any auto-fix. Use
.unsafe_fixes()only when explicitly demonstrating an unsafe fix; the generated page labels its command. Do not write diagnostic text or fixed output by hand. - Run
task docs:rules, then reviewdocs/reference/_linter-rules.qmd. Metadata fields and anchors are generated directly fromRuleMeta. - Update any illustrative references in
docs/guide/linting.qmdif needed.
- Put the explanation in
- Validate in this order:
- Targeted:
cargo test --lib <rule_name>,cargo test --test linting <test_name>, andcargo test --test linter_rules_docs(catches docs/metadata drift). - CLI smoke check on a copy of the fixture:
cargo run --quiet -- lint /tmp/<fixture>.mdandcargo run --quiet -- lint --fix /tmp/<fixture>.md(verify the file contents after--fix). - Full:
cargo check --workspace,cargo test --workspace,cargo clippy --workspace --all-targets --all-features -- -D warnings,cargo fmt -- --check.
- Targeted:
Dos and don'ts
- Do keep diagnostic spans tight (point at the offending construct, not the whole line/paragraph) — this drives both the CLI caret and LSP underlines.
- Do put rule logic in the rule module. Shared cross-rule helpers belong
in
src/linter/(e.g. viacrate::salsa::symbol_usage_index_from_tree), not duplicated. - Do respect ignore directives implicitly —
LintRunner::run_with_metadataalready filters by ignored ranges, so the rule emits unconditionally. - Don't emit CLI strings, ANSI codes, or
eprintln!from a rule. ReturnDiagnosticvalues and let the renderer handle output. - Don't rely on lexically scanning
input. Walk the CST/AST. - Don't add a fix that changes prose semantics. If the user's intent is ambiguous, omit the fix.
- Don't rename an existing rule code to fix a typo without a migration plan — the code is part of the user-facing config surface.
Report-back format
When done, report:
- Rule name (code), severity, and whether it ships an auto-fix.
- The
Requirementanddefault_onit declares inRuleMeta. - New files (rule module, fixture) and updated files (
rules.rs,linter.rsall_rules(),linting.rs, the rule description, and generated catalog). - Targeted test names (including
linter_rules_docs) and CLI fix smoke-test outcome. - Full-suite validation results (
cargo test --workspace, clippy, fmt).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

