oxc/crates
DonIsaac 7a75e0f8a7 refactor(linter): use diagnostic codes in lint rules (#4349)
> This PR is (unfortunately) quite large, but all changes are needed in tandem for this to work properly.

## What This PR Does

Updates the linter to populate diagnostics reported by rules with error codes statically derived from `RuleMeta` + `RuleEnum`.

Doing so required changing how we handle vitest rules. I know @mysterven was hoping to refactor that part of the code, and I think this approach is an improvement (but could probably be cleaned up further).

## Changes

### 1. Auto-Populate Error Codes
`LintContext` now sets an error code scope + error code number for diagnostics reported by lint rules. `LintContext` will not clobber existing codes set by rules, allowing for rule-specific override behavior (e.g. to use `eslint-plugin-react-hooks` as an error scope).

In order to accomplish this, I had to update every diagnostic factory for every rule. While doing this I found some incorrect error messages, or messages that could be easily improved. This is where a large majority of the snapshot diffs come from. Additionally, I was able to reduce string allocations from `format!` usages in diagnostic factories, especially within jest rules.

### 2. Framework and Library Detection
This PR adds `FrameworkFlags`, which specify what (if any) set of libraries and frameworks are being used by a project and/or file. They are passed in two ways:

1. `LintOptions` can specify a set of `framework_hints` that apply to the entire target codebase. Right now these are always empty, but I'm thinking in the future we could sniff `package.json`. It may be helpful for enabling/disabling default rules.
2. When `Linter` gets run on a file, framework information is sniffed from the `LintContext`. Right now, we are only checking for `vitest` imports in `ModuleRecord` and test path prefixes from `source_path`. It may be useful to do something similar for React/NextJS rules in the future. I know that [next/no-html-link-for-pages](https://nextjs.org/docs/messages/no-html-link-for-pages) could benefit greatly from this.
2024-07-20 03:35:00 +00:00
..
oxc Release crates v0.21.0 (#4344) 2024-07-18 14:39:07 +08:00
oxc_allocator Release crates v0.21.0 (#4344) 2024-07-18 14:39:07 +08:00
oxc_ast feat(linter): add typescript-eslint/no-extraneous-class (#4357) 2024-07-19 15:56:30 -04:00
oxc_ast_macros Release crates v0.21.0 (#4344) 2024-07-18 14:39:07 +08:00
oxc_cfg Release crates v0.21.0 (#4344) 2024-07-18 14:39:07 +08:00
oxc_codegen fix(codegen,mangler): do not print shorthand for ObjectProperty (#4350) 2024-07-18 16:26:33 +00:00
oxc_diagnostics refactor(linter): use diagnostic codes in lint rules (#4349) 2024-07-20 03:35:00 +00:00
oxc_index Release crates v0.21.0 (#4344) 2024-07-18 14:39:07 +08:00
oxc_isolated_declarations fix(ast): visit Programs hashbang field first (#4368) 2024-07-19 16:27:51 +00:00
oxc_js_regex
oxc_language_server refactor(linter): use diagnostic codes in lint rules (#4349) 2024-07-20 03:35:00 +00:00
oxc_linter refactor(linter): use diagnostic codes in lint rules (#4349) 2024-07-20 03:35:00 +00:00
oxc_macros refactor(linter): use diagnostic codes in lint rules (#4349) 2024-07-20 03:35:00 +00:00
oxc_mangler Release crates v0.21.0 (#4344) 2024-07-18 14:39:07 +08:00
oxc_minifier Release crates v0.21.0 (#4344) 2024-07-18 14:39:07 +08:00
oxc_module_lexer Release crates v0.21.0 (#4344) 2024-07-18 14:39:07 +08:00
oxc_parser fix(ast): visit Programs hashbang field first (#4368) 2024-07-19 16:27:51 +00:00
oxc_prettier chore: remove unsafe_code = "warn" rust lint 2024-07-15 10:39:08 +08:00
oxc_semantic refactor(semantic): visit_program visit hashbang field (#4370) 2024-07-19 16:32:32 +00:00
oxc_sourcemap fix(sourcemap): avoid negative line if token_chunks has same prev_dst_line (#4348) 2024-07-19 18:14:35 +08:00
oxc_span fix: impl PartialEq<str> for CompactStr (#4352) 2024-07-19 16:39:10 +00:00
oxc_syntax fix(transformer/typescript): unexpectedly removed class binding from ExportNamedDeclaration (#4351) 2024-07-18 16:44:38 +00:00
oxc_transformer Release crates v0.21.0 (#4344) 2024-07-18 14:39:07 +08:00
oxc_traverse fix(ast): visit Programs hashbang field first (#4368) 2024-07-19 16:27:51 +00:00
oxc_wasm refactor(linter): use diagnostic codes in lint rules (#4349) 2024-07-20 03:35:00 +00:00