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): inherit rules via the extended config files #9308

Conversation

camchenry
Copy link
Member

@camchenry camchenry commented Feb 23, 2025

This gives the extends keyword some functionality: specifically to allow inheriting rules from other configuration files. Rules that are in the extended configuration will be used as the base, and then files in the config doing the extending will override the extended rules.

So, you can, for example, specify a base configuration that defines rules that you generally want to be enabled. Then, in each nested configuration file, you could disable rules depending on the directory:

.oxlintrc.json       // { "rules: { "no-useless-escape": "error" } }
package1/
  .oxlintrc.json     // { "extends": ["../.oxlintrc.json"], "rules": { "no-useless-escape": "off" } }
package2/
  src                // uses ../.oxlintrc.json with `no-useless-escape` enabled 

As a side effect of this, building a config from a .oxlintrc.json file can result in config errors, even if all of the syntax and rules are configured correctly, because an extended configuration file might be incorrect or unparseable. For now, we simply raise an error if this occurs and stop execution, but in the future we could make this more graceful if we wanted and just ignore that file.

We will also need to revisit performance here, as I think a global cache config might be necessary so that we never load a file more than once and parse it more than once.

Copy link
Member Author

camchenry commented Feb 23, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI C-enhancement Category - New feature or request labels Feb 23, 2025
@camchenry camchenry force-pushed the 02-23-feat_linter_inherit_rules_via_the_extended_config_files branch from 971831f to 789e166 Compare February 24, 2025 03:57
@github-actions github-actions bot added the A-editor Area - Editor and Language Server label Feb 24, 2025
@camchenry camchenry force-pushed the 02-18-feat_linter_add_support_for_extends_property_in_oxlintrc branch from 7f3a3de to c92ba6c Compare February 24, 2025 03:58
@camchenry camchenry force-pushed the 02-23-feat_linter_inherit_rules_via_the_extended_config_files branch from 789e166 to fd06c26 Compare February 24, 2025 03:58
Copy link

codspeed-hq bot commented Feb 24, 2025

CodSpeed Performance Report

Merging #9308 will create unknown performance changes

Comparing 02-23-feat_linter_inherit_rules_via_the_extended_config_files (fc74849) with main (3fce826)

Summary

🆕 16 new benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
🆕 codegen[checker.ts] N/A 23.1 ms N/A
🆕 codegen_sourcemap[checker.ts] N/A 66.2 ms N/A
🆕 linter[RadixUIAdoptionSection.jsx] N/A 2.7 ms N/A
🆕 linter[cal.com.tsx] N/A 1.2 s N/A
🆕 linter[checker.ts] N/A 2.9 s N/A
🆕 estree[checker.ts] N/A 91.8 ms N/A
🆕 parser[RadixUIAdoptionSection.jsx] N/A 88.9 µs N/A
🆕 parser[antd.js] N/A 111.9 ms N/A
🆕 parser[cal.com.tsx] N/A 30.1 ms N/A
🆕 parser[checker.ts] N/A 56.3 ms N/A
🆕 parser[pdf.mjs] N/A 18.1 ms N/A
🆕 semantic[RadixUIAdoptionSection.jsx] N/A 73 µs N/A
🆕 semantic[antd.js] N/A 104.6 ms N/A
🆕 semantic[cal.com.tsx] N/A 26 ms N/A
🆕 semantic[checker.ts] N/A 64.3 ms N/A
🆕 semantic[pdf.mjs] N/A 17.1 ms N/A

@camchenry camchenry force-pushed the 02-23-feat_linter_inherit_rules_via_the_extended_config_files branch 2 times, most recently from 3e96436 to dd36f3c Compare March 1, 2025 13:17
@camchenry camchenry marked this pull request as ready for review March 1, 2025 17:57
@camchenry camchenry force-pushed the 02-18-feat_linter_add_support_for_extends_property_in_oxlintrc branch from c92ba6c to dfdbb48 Compare March 1, 2025 22:35
@camchenry camchenry force-pushed the 02-23-feat_linter_inherit_rules_via_the_extended_config_files branch from dd36f3c to 4cfdc59 Compare March 1, 2025 22:35
@camchenry camchenry force-pushed the 02-18-feat_linter_add_support_for_extends_property_in_oxlintrc branch from dfdbb48 to 7cab29f Compare March 3, 2025 18:12
@camchenry camchenry force-pushed the 02-23-feat_linter_inherit_rules_via_the_extended_config_files branch from 4cfdc59 to 63b413f Compare March 3, 2025 18:12
@camchenry camchenry added the 0-merge Merge with Graphite Merge Queue label Mar 4, 2025
Copy link
Member Author

camchenry commented Mar 4, 2025

Merge activity

  • Mar 3, 9:36 PM EST: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Mar 3, 9:36 PM EST: A user added this pull request to the Graphite merge queue.
  • Mar 3, 9:43 PM EST: A user merged this pull request with the Graphite merge queue.

- part of #9307

This gives the `extends` keyword some functionality: specifically to allow inheriting rules from other configuration files. Rules that are in the extended configuration will be used as the base, and then files in the config doing the extending will override the extended rules.

So, you can, for example, specify a base configuration that defines rules that you generally want to be enabled. Then, in each nested configuration file, you could disable rules depending on the directory:

```text
.oxlintrc.json       // { "rules: { "no-useless-escape": "error" } }
package1/
  .oxlintrc.json     // { "extends": ["../.oxlintrc.json"], "rules": { "no-useless-escape": "off" } }
package2/
  src                // uses ../.oxlintrc.json with `no-useless-escape` enabled
```

As a side effect of this, building a config from a `.oxlintrc.json` file can result in config errors, even if all of the syntax and rules are configured correctly, because an extended configuration file might be incorrect or unparseable. For now, we simply raise an error if this occurs and stop execution, but in the future we could make this more graceful if we wanted and just ignore that file.

We will also need to revisit performance here, as I think a global cache config might be necessary so that we never load a file more than once and parse it more than once.
@graphite-app graphite-app bot force-pushed the 02-18-feat_linter_add_support_for_extends_property_in_oxlintrc branch from 7cab29f to 3fce826 Compare March 4, 2025 02:37
@graphite-app graphite-app bot force-pushed the 02-23-feat_linter_inherit_rules_via_the_extended_config_files branch from 63b413f to fc74849 Compare March 4, 2025 02:37
Base automatically changed from 02-18-feat_linter_add_support_for_extends_property_in_oxlintrc to main March 4, 2025 02:41
@graphite-app graphite-app bot merged commit fc74849 into main Mar 4, 2025
24 of 30 checks passed
@graphite-app graphite-app bot deleted the 02-23-feat_linter_inherit_rules_via_the_extended_config_files branch March 4, 2025 02:43
Boshen added a commit that referenced this pull request Mar 11, 2025
## [0.15.14] - 2025-03-11

### Features

- 0815fe8 linter: Add `promise/no-return-wrap` (#9537) (therewillbecode)
- ae7bb75 linter: Add react/jsx-filename-extension rule (#9474) (Cédric
DIRAND)
- 50327f3 linter: Add import/exports-last (#9578) (yefan)
- 75e4b8d linter: Add import/no-anonymous-default-export rule (#9481)
(yefan)
- 2f08b16 linter: Add `promise/prefer-catch` (#9488) (therewillbecode)
- 41f32ea linter: Allow adding more overrides via `extends` configs
(#9475) (camchenry)
- fb7cf10 linter: Allowing `plugins` to be extended with `extends`
(#9473) (camchenry)
- fc74849 linter: Inherit `rules` via the extended config files (#9308)
(camchenry)
- 3fce826 linter: Add support for `extends` property in oxlintrc (#9217)
(camchenry)

### Bug Fixes

- 2d42569 linter: Rule `eslint/no-unsafe-optional-chaining` (#9632)
(therewillbecode)
- a9d7df9 linter: False positive in `unicorn/escape-case` (#9638)
(shulaoda)
- 3831819 linter: Fix example lint declaration and macro syntax (#9626)
(Uli)
- 4ca62ab linter: Output right file line and column for `.vue`, `.astro`
and `.svelte` files (#9484) (Sysix)
- 3105159 linter: Do not output number of rules with nested configs
(#9476) (camchenry)
- 5ecda01 linter: Support nested extending (#9472) (camchenry)

### Documentation

- b7c61e9 linter: Improve docs for `eslint-guard-for-in` (#9658)
(therewillbecode)
- 1cc43f7 linter: Improve the documentation of `eslint-no-console`
(#9612) (therewillbecode)
- 608bb77 linter: Improve the docs and add test case for
`typescript-no-extra-non-null-assertion` (#9609) (therewillbecode)
- 43add5d linter: Better docs for
`typescript-no-non-null-asserted-nullish-coalescing` rule (#9610)
(therewillbecode)
- bd90ce6 linter: Improve the docs and add test cases for
`eslint-no-shadow-restricted-names` (#9597) (therewillbecode)
- a0c9f7c linter: Improve the documentation of `eslint-no-func-assign`
(#9596) (therewillbecode)
- ec922e9 linter: Improve the documentation of
`typescript-consistent-type-definitions` (#9575) (therewillbecode)
- 165c89d linter: Improve the documentation of `typescript-no-namespace`
(#9545) (therewillbecode)

### Refactor

- c174600 linter: Improve `eslint/no-duplicate-imports` (#9627)
(therewillbecode)
- 31ba425 linter: Improve `eslint/no-self-assign` (#9635)
(therewillbecode)
- 03a40df linter: Access scoping from `ctx` directly (#9624) (Boshen)
- be5e5dc linter: Improve `unicorn/escape-case` (#9568) (shulaoda)
- b7f82fc linter: Improve `unicorn/error-message` (#9560) (shulaoda)
- 069ef2d linter: Improve `promise/no-nesting` (#9544) (therewillbecode)
- 62bffed rust: Allow a few annoying clippy rules (#9588) (Boshen)

### Testing

- 934a387 linter: Remove test dependency on oxlint (#9513) (camchenry)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0-merge Merge with Graphite Merge Queue A-cli Area - CLI A-editor Area - Editor and Language Server A-linter Area - Linter C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants