lint-creator
Installation
SKILL.md
Adding a dylint to tooling/lints
Before writing anything
- Check whether clippy already covers the pattern (search https://rust-lang.github.io/rust-clippy/master/). If it does, stop and report that to the user instead of writing a redundant lint.
Layout
- One module per lint:
src/<lint_name>.rs, declared insrc/lib.rs. - Register the lint in
register_lintsinsrc/lib.rs: add it to thelint_store.register_lints(&[...])slice and add aregister_late_passcall. - Use
src/notify_in_render.rsas the template:rustc_session::declare_lint!with### What it does/### Why is this bad?doc sections,impl_lint_pass!, and aLateLintPassimpl that bails early withlet ... else/ early returns. - Do NOT copy the diagnostics style of
shared_string_from_str_literalinlib.rs— it predates the rules below (it emits a machine-applicable suggestion). The two lints living directly inlib.rsalso predate the one-module-per-lint rule. - Reuse the helpers in
src/render_helpers.rs(is_directly_in_render_method,is_gpui_context) for render/gpui checks.
Diagnostics rules
- Flag only; never suggest how to fix, and never use
Applicability::MachineApplicable. - Keep detection and reporting as simple as possible: prefer
span_lintwith a one-sentence message overspan_lint_and_thenwith notes. - Skip macro-expanded code (
expr.span.from_expansion()).