-
-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(linter)!: support plugins in oxlint config files (#6088)
> Closes #5046 This PR migrates the linter crate and oxlint app to use the new `LinterBuilder` API. This PR has the following effects: 1. `plugins` in oxlint config files are now supported 2. irons out weirdness when using CLI args and config files together. CLI args are now always applied on top of config file settings, overriding them. # Breaking Changes Before, config files would override rules set in CLI arguments. For example, running this command: ```sh oxlint -A correctness -c oxlintrc.json ``` With this config file ```jsonc // oxlintrc.json { "rules": { "no-const-assign": "error" } } ``` Would result in a single rule, `no-const-assign` being turned on at an error level with all other rules disabled (i.e. set to "allow"). Now, **CLI arguments will override config files**. That same command with the same config file will result with **all rules being disabled**. ## Details For a more in-depth explanation, assume we are running the below command using the `oxlintrc.json` file above: ```sh oxlint -A all -W correctness -A all -W suspicious -c oxlintrc.json ``` ### Before > Note: GitHub doesn't seem to like deeply nested lists. Apologies for the formatting. Here was the config resolution process _before_ this PR: <details><summary>Before Steps</summary> 1. Start with a default set of filters (["correctness", "warn"]) if no filters were passed to the CLI. Since some were, the filter list starts out empty. 2. Apply each filter taken from the CLI from left to right. When a filter allows a rule or category, it clears the configured set of rules. So applying those filters looks like this a. start with an empty list `[]` b. `("all", "allow")` -> `[]` c. `("correctness", "warn")` -> `[ <correctness rules> ]` d. `("all", "allow")` -> `[]` e. `("suspicious", "warn")` -> `[ <suspicious rules> ]`. This is the final rule set for this step 3. Apply overrides from `oxlintrc.json`. This is where things get a little funky, as mentioned in point 2 of what this PR does. At this point, all rules in the rules list are only from the CLI. a. If a rule is only set in the CLI and is not present in the config file, there's no effect b. If a rule is in the config file but not the CLI, it gets inserted into the list. c. If a rule is already in the list and in the config file i. If the rule is only present once (e.g. `"no-loss-of-precision": "error"`), unconditionally override whatever was in the CLI with what was set in the config file ii. If the rule is present twice (e.g. `"no-loss-of-precision": "off", "@typescript-eslint/no-loss-of-precision": "error"`), a. if all rules in the config file are set to `allow`, then turn the rule off b. If one of them is `warn` or `deny`, then update the currently-set rule's config object, but _leave its severity alone_. So, for our example, the final rule set would be `[<all suspicious rules: "warn">, no-const-assign: "error"]` </details> ### After Rule filters were completely re-worked in a previous PR. Now, lint filters aren't kept on hand-only the rule list is. <details><summary>After Steps</summary> 1. Start with the default rule set, which is all correctness rules for all enabled plugins (`[<all correctness rules: "warn">]`) 2. Apply configuration from `oxlintrc.json` _first_. a. If the rule is warn/deny exists in the list already, update its severity and config object. If it's not in the list, add it. b. If the rule is set to allow, remove it from the list. The list is now `[<all correctness rules except no-const-assign: "warn">, no-const-assign: "error"]`. 3. Apply each filter taken from the CLI from left to right. This works the same way as before. So, after they're applied, the list is now `[<suspicous rules: "warn">]` </details>
- Loading branch information
Showing
16 changed files
with
317 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"plugins": ["import"], | ||
"rules": { | ||
"import/no-default-export": "error", | ||
"import/namespace": "allow" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as foo from './foo'; | ||
// ^ import/namespace | ||
|
||
console.log(foo); | ||
|
||
// import/no-default-export | ||
export default function foo() {} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.