oxc icon indicating copy to clipboard operation
oxc copied to clipboard

linter: Overrides property is not working with "Vitest" plugin

Open i62navpm opened this issue 9 months ago • 1 comments

What version of Oxlint are you using?

0.15.13

What command did you run?

yarn oxlint -c .oxlintrc.json index.test.ts

What does your .oxlintrc.json config file look like?

{
  "categories": {
    "style": "error"
  },
  "overrides": [
    {
      "files": ["./index.test.ts"],
      "plugins": ["vitest"]
    }
  ]
}

What happened?

The linter only works when the plugins property is set in the root of the config file, when the plugins property is set in the overrides property, the linter does not work.

This is the config file that works:

{
  "plugins": ["vitest"]
 "categories": {
   "style": "error"
 },
 "overrides": [
 ]
}

But this one doesn't work:

{
  "categories": {
    "style": "error"
  },
  "overrides": [
    {
      "files": ["./index.test.ts"],
      "plugins": ["vitest"]
    }
  ]
}

https://github.com/user-attachments/assets/cf8386db-2bf2-47ab-a693-0044890843dd

i62navpm avatar Mar 10 '25 10:03 i62navpm

I had look into this a little bit. I think there is a specification issue here that we need to think about. The problem essentially boils down to the order in which rules are enabled causes the difference in behavior.

When enabling plugins at the top-level, it allows those rules to be accessible as part of the base rule set, which then factors into which rules are enabled by categories. But if the plugins are enabled as part of an override, it can't factor into the base rule set, since that happens too late and we don't recalculate the base rules at that point.

If we want categories to apply to overrides as well, then we probably need to store what categories are enabled in the ConfigStore, not just compute the base rule set once at the beginning.

camchenry avatar Mar 21 '25 03:03 camchenry

@camchenry any thoughts on the best approach here? perhaps the config gets resolved like:

{
  "categories": {
    "style": "error"
  },
  "overrides": [
    {
      "files": ["./index.test.ts"],
      "plugins": ["vitest"]
    }
  ]
}

to

{
  "categories": {
    "style": "error"
  },
  "overrides": [
    {
      "files": ["./index.test.ts"],
      "plugins": ["vitest"],
  "categories": {
    "style": "error"
  },
    }
  ]
}

and then the rules are resolved?

this should ensure that vitest style rules are enabled for that set of override

camc314 avatar May 01 '25 14:05 camc314

@camc314 I think that seems right to me. It makes sense that categories at the top-level should be configured for overrides as well, but we don't currently store it this way.

camchenry avatar May 01 '25 21:05 camchenry

thanks for the extra color. I think i'm going to put this one on hold, and focus on https://github.com/oxc-project/oxc/issues/9809 first? need to investigate a bit more, but if that one is resolved, the overrides here don't really apply anymore

camc314 avatar May 02 '25 10:05 camc314

@i62navpm apologies for the delay in fixing this, do you mind trying 0.18.0 and seeing if it's fixed?

camc314 avatar Jun 06 '25 17:06 camc314