-
-
Notifications
You must be signed in to change notification settings - Fork 540
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
linter: nested file configuration #7408
Comments
I did a bit of testing and thinking on this today. As it stands, these are my current thoughts on what we need to implement.
|
This is a brief informal description of the nested file configuration specification for oxlint. It is primarily based on ESLint, but with some inspiration taken from the https://docs.astral.sh/ruff/configuration/#config-file-discovery as well. This should be documented officially on the website later DecisionsThese are the main decisions / important points:
ContextIn large monorepositories (repositories containing multiple packages/projects), it is convenient for each project to have its own configuration files, rather than having a single shared file. This makes it easy to clone or work out of just a subdirectory and treat it as its own independent project. This means that each project directory should have its own
However, it is not possible to lint the entire Resolving configuration filesIn ESLint, configuration files are resolved by using the file in the current directory or nearest parent directory as the base configuration file, and then subsequently merging that with each file in each parent directory, up to the root directory. The base configuration file takes precedence over any parent configurations. However, this can create situations where you have more rules enabled than you want, such as rules that shouldn't apply for test files, or rules for packages you aren't using in a subdirectory. ESLint solves this by supporting adding a In oxlint, we will not automatically search upwards in the file hierarchy for configuration files. We will only use the closest configuration file to the file currently being linted. Every configuration file will essentially be treated as if it already contained In priority order, the "nearest" configuration should be defined as:
However, not automatically merging configuration files means that it becomes harder to share configuration across directories. So, we need to define a way to share lint configurations. Extending configuration filesIn ESLint, the Oxlint will also support the
The configuration file paths are resolved relative to the base configuration file. When extending other files, some general rules apply:
Other details and contextHow are CLI arguments resolved?In general, CLI arguments take precedence over the final resolved configuration. For example, if the What is the precedence of configuration resolution?This is a list of the general precedence of configuration, in order from highest precedence to lowest:
How does
|
It would be nice if Oxlint could provide a migration program to convert YAML configuration(or other) files to JSON |
Hi, First off, I want to express how much I appreciate the thought and effort that went into making this decision. It's great to see the structured approach taken here! I do, however, have a few pieces of feedback that I think could help refine the priority order for configuration resolution: 1. Priority Order AdjustmentYou’ve mentioned the priority order as follows:
Based on my experience with mono-repos across many organizations, I’d suggest adjusting this order. Specifically, I recommend prioritizing the current working directory (CWD) configuration after The reason is that in large mono-repos, it's common to run scripts from the root of the repository that are meant to target specific sub-projects. If the root config takes precedence, it can unintentionally override the configuration intended for a specific project. For instance, when using tools like Bit, the CWD is often the root, but the script is executed for a sub-project. In such cases, prioritizing the CWD would lead to the scenario you’ve mentioned: “more rules enabled than desired.” 2. Explicit Configuration (
|
@GiladShoham Thanks for the feedback, I've updated the post with some extra details, but I'll try to add more in the future as well with more clarifications. I'm going to try and get started on implementing this.
This was a mistake on my part, I wrote down the list incorrectly. I agree that the root directory should be a lower priority than a config file in a subdirectory. I've updated the precedence list.
Agreed, I added a clarification on this, as well as a more general list of precedence in configuration. |
Some question because I worked on |
I think so, it should work similarly to the I'm currently working on the first version of the nested config code without any |
- part of #7408 Since the nested configuration work is too big to fit in one PR or even a stack of PRs, I suggest that we make it temporarily an opt-in CLI flag. Once we feel confident in the implementation replacing the existing code, we can remove the flag and make it true by default.
- part of #7408 This is the initial implementation for nested config support, without the `extends` keyword factoring into it yet. So we only load a single config file for any given file still, but it will always be the one closest to the file being linted. Performance is somewhat of a big TODO here, obviously there is some inherent cost to adding support for nested configurations since we need to check if any directory contains an `.oxlintrc.json` file, load it if it exists, and then for every file below that directory check if we should use it. I've left a few TODOs of different ways we might be able to cache more data at the cost of memory but at the potential gain of some CPU time. Optimizing iteration over files/directories is one way in which we might be able to make this faster, so we never need to visit the same directory twice. For now, this will remain an experimental feature that should not affect the current functionality until we enable it for everyone. PRs stacked on top of this will focus on ensuring that other features work well with this, such as `--config`, `-D <rule>`, and then we'll add new features like `extends`. The configuration loading all happens upfront currently, while the config resolution happens at lint-time. There is a new `nested_configs` field on the `Linter` that passes all of the configs that are available, so it can pick which one to use later. Eventually we'll refactor this to not have two duplicate config fields, but I'm leaving it as-is to ensure we're not messing up the existing functionality.
- part of #7408 Ensures that when a config file is explicitly passed via `-c` or `--config`, that file will take precedence over all nested config files, and we will not search for config files within any directories.
@camchenry where do you expect the config file resolution to be done? Will this be done within I think what I'm seeing currently is that this is in the CLI and we will need to re-implement it within each individual IDE plugin. |
@nrayburn-tech yeah it's a good question. I think @Sysix had a good idea here for extracting the config finding out to a separate struct and giving it some methods for locating and resolving which config files to use. Ideally I don't think we want to rewrite this continually on each surface without good reason. |
I would love to have it inside oxc_linter but there will be problems with multi threading. So for now the CLI and the language-server will handle it. |
Done and will become the default without the |
This is the tracking issue for nested file configuration in oxlint.
The text was updated successfully, but these errors were encountered: