Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(linter)!: support plugins in oxlint config files #6088

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DonIsaac
Copy link
Collaborator

@DonIsaac DonIsaac commented Sep 26, 2024

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:

oxlint -A correctness -c oxlintrc.json

With this config file

// 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:

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:

Before Steps
  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"]

After

Rule filters were completely re-worked in a previous PR. Now, lint filters aren't kept on hand-only the rule list is.

After Steps
  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"].

  1. 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">]

Copy link

graphite-app bot commented Sep 26, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

Copy link

codspeed-hq bot commented Sep 26, 2024

CodSpeed Performance Report

Merging #6088 will degrade performances by 3.79%

Comparing don/09-26-feat_linter_support_plugins_in_oxlint_config_files (8ea51af) with main (2090fce)

Summary

❌ 1 regressions
✅ 28 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main don/09-26-feat_linter_support_plugins_in_oxlint_config_files Change
linter[checker.ts] 2.4 s 2.5 s -3.79%

@DonIsaac DonIsaac force-pushed the don/09-26-feat_linter_support_plugins_in_oxlint_config_files branch from d08cf2c to 51b398d Compare September 26, 2024 22:19
@DonIsaac
Copy link
Collaborator Author

CodSpeed Performance Report

Merging #6088 will degrade performances by 3.72%

Comparing don/09-26-feat_linter_support_plugins_in_oxlint_config_files (d08cf2c) with don/09-26-fix_linter_rule_and_generic_filters_do_not_re-configure_existing_rules (6edcd5c)

Summary

❌ 1 regressions ✅ 28 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark don/09-26-fix_linter_rule_and_generic_filters_do_not_re-configure_existing_rules don/09-26-feat_linter_support_plugins_in_oxlint_config_files Change
linter[checker.ts] 2.4 s 2.5 s -3.72%

It looks like some rules are not running that weren't before. This either means this PR fixed a bug that caused them not to run, or ...run() is now taking longer, so those spans are showing up?

TBH I'm not quite sure what to make of this.

@DonIsaac DonIsaac force-pushed the don/09-26-fix_linter_rule_and_generic_filters_do_not_re-configure_existing_rules branch 2 times, most recently from b1a12f2 to 29c00c5 Compare September 27, 2024 02:28
@DonIsaac DonIsaac force-pushed the don/09-26-feat_linter_support_plugins_in_oxlint_config_files branch from 51b398d to 27c99ab Compare September 27, 2024 02:28
@DonIsaac DonIsaac changed the base branch from don/09-26-fix_linter_rule_and_generic_filters_do_not_re-configure_existing_rules to graphite-base/6088 September 27, 2024 03:39
@DonIsaac DonIsaac force-pushed the don/09-26-feat_linter_support_plugins_in_oxlint_config_files branch from 27c99ab to 8592ba8 Compare September 27, 2024 03:43
@DonIsaac DonIsaac changed the base branch from graphite-base/6088 to main September 27, 2024 03:44
@DonIsaac DonIsaac force-pushed the don/09-26-feat_linter_support_plugins_in_oxlint_config_files branch from 8592ba8 to d5a088e Compare September 27, 2024 03:44
apps/oxlint/src/command/lint.rs Outdated Show resolved Hide resolved
apps/oxlint/src/command/lint.rs Show resolved Hide resolved
apps/oxlint/src/command/lint.rs Show resolved Hide resolved
crates/oxc_linter/src/config/oxlintrc.rs Outdated Show resolved Hide resolved
crates/oxc_linter/src/options/plugins.rs Outdated Show resolved Hide resolved
@DonIsaac DonIsaac force-pushed the don/09-26-feat_linter_support_plugins_in_oxlint_config_files branch from d5a088e to b197bff Compare September 27, 2024 03:54
@DonIsaac DonIsaac force-pushed the don/09-26-feat_linter_support_plugins_in_oxlint_config_files branch from b197bff to 2be7add Compare September 27, 2024 03:57
Copy link
Member

@Boshen Boshen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest manually test this setup on some of the oxlint-ecosystem-ci projects and see if the rule numbers match.

@DonIsaac DonIsaac force-pushed the don/09-26-feat_linter_support_plugins_in_oxlint_config_files branch from 2be7add to dd0946f Compare September 27, 2024 14:16
@DonIsaac DonIsaac force-pushed the don/09-26-feat_linter_support_plugins_in_oxlint_config_files branch from dd0946f to 8ea51af Compare September 27, 2024 14:56
@DonIsaac DonIsaac changed the title feat(linter): support plugins in oxlint config files feat(linter)!: support plugins in oxlint config files Sep 27, 2024
@DonIsaac
Copy link
Collaborator Author

We'll need to allow for category-based rule configuration in oxlintrc.json files before our next release in order for this PR to be viable. Otherwise there's no way to get that broad-level configuration, followed by rule-by-rule tweaking, that people were getting before using the CLI. Working on a PR now.

DonIsaac added a commit that referenced this pull request Sep 27, 2024
> closes #5454

Adds a `categories` property to config files, where each key is a `RuleCategory` and each value is `"allow"/"off"`, `"warn"`, or `"deny"/"error"`.

Note that this change won't come into effect until after #6088 is merged.
DonIsaac added a commit that referenced this pull request Sep 27, 2024
> closes #5454

Adds a `categories` property to config files, where each key is a `RuleCategory` and each value is `"allow"/"off"`, `"warn"`, or `"deny"/"error"`.

Note that this change won't come into effect until after #6088 is merged.
@DonIsaac
Copy link
Collaborator Author

Waiting on #6120 to land before merging this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area - CLI A-linter Area - Linter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(linter): Support plugins array in config
3 participants