-
-
Notifications
You must be signed in to change notification settings - Fork 79
feat: Support basePath
property in config objects
#131
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
base: main
Are you sure you want to change the base?
Conversation
basePath
` property in config objectsbasePath
property in config objects
|
||
## Open Questions | ||
|
||
Should this RFC include the `--basePath` feature (https://github.com/eslint/eslint/issues/19118)? I didn't see a relation between config-level base paths and ability to override config array's base path, so I didn't include it in this RFC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I thought it might be good to include this feature in this RFC is because of how --base-path
might interact with a config basePath
property. Would it just replace the config file base path completely such that any relative basePath
property would now be relative to the value passed as --base-path
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel strongly about including the --base-path
feature in this RFC but it seems useful to clarify how it will (or won't) interact with the basePath
property.
I'm thinking about the situation where a parent config and an extended config have different base paths. Per the current Maybe relative base paths in extended configs should be joined to the base path of the parent config? |
I'm not sure I understand what you're describing. Can you provide an example? |
Here's an example where the export default defineConfig({
basePath: "packages/foo",
files: ["**/*.js"],
rules: {
rule1: "error"
},
extends: [{
ignores: ["ignored.js"],
rules: {
rule2: "error"
}
}]
}); Using the fork in mdjermanovic/rewrite#1, this will result in the following array: [
{
ignores: ["ignored.js"],
rules: { rule2: "error" },
files: ["**/*.js"],
name: "UserConfig[0] > ExtendedConfig[0]"
},
{
basePath: "packages/foo",
files: ["**/*.js"],
rules: { rule1: "error" }
}
] Basically the merged config object (the first array element) now contains the |
Ah okay, so "parent config" is what I refer to as the "base config". 👍 I agree, it seems like when we extend a config, the result should contain the |
When the base config has So, in the example from #131 (comment), I think the result should be: [
{
basePath: "packages/foo",
ignores: ["ignored.js"],
rules: { rule2: "error" },
files: ["**/*.js"],
name: "UserConfig[0] > ExtendedConfig[0]"
},
{
basePath: "packages/foo",
files: ["**/*.js"],
rules: { rule1: "error" }
}
] On the other hand, I'm not sure what to do when the extended config has |
That would be the first time I'm not sure I agree that people won't use So, I think it's useful to allow a config file to overwrite |
@mdjermanovic @fasttime where do we want to go from here? |
I'm not sure if overwriting For example, if this is a shared config: export default [
// apply this config everywhere
{
files: ["**/*.js"],
rules: {
"no-undef": 2,
},
},
// apply this config only in `foo` directory
{
basePath: "foo",
files: ["**/*.js"],
rules: {
"no-unused-vars": 2,
},
},
]; The intent is to define a general config for all files, and specific additions for a subdirectory. Now, if this shared config is used with the intent to apply it to a particular directory only: export default defineConfig([
{
basePath: "bar",
extends: [sharedConfig],
},
]); Overwriting [
{
basePath: "bar",
files: ["**/*.js"],
rules: {
"no-undef": 2,
},
},
{
basePath: "bar",
files: ["**/*.js"],
rules: {
"no-unused-vars": 2,
},
},
]; This means that both config objects apply to all files, which wasn't the original intent of the shared config. |
I guess I don't see that as a common case. In my mind, it's more common for either the shared config or the user config to have Given that the user should have ultimate control over where a config is applied, I still think overwriting |
Because this issue of
I'm okay with this, as it allows us the opportunity to think through this use case further and make changes down the line if necessary. I think it's important to get this change out relatively soon so we can start v10 planning. @fasttime what do you think? |
|
||
Currently, config array has a single property `basePath` (string) at the top level. When used from `eslint`, this property is set to the location of the config file, or the current working directory (when `--no-config-lookup` or `--config` options are used). `files` and `ignores` patterns in all config objects are treated as relative to the config array's `basePath`. | ||
|
||
This RFC proposes allowing config objects to specify their own `basePath` property. When present, config object's `basePath` overrides config array's `basePath`, meaning that `files` and `ignores` patterns in that config object should be treated as relative to the config object's `basePath` instead of the config array's `basePath`. Also, when `basePath` is present in a config object that has neither `files` nor `ignores`, then the config object applies to files in `basePath` and its subdirectories only. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've realized the behavior of basePath
in configuration objects that have neither files
nor ignores
was not considered, so I updated this RFC in 09409ed, and the proof of concept accordingly in mdjermanovic/rewrite@d2ea0d7.
Summary
This RFC proposes supporting
basePath
property in config objects.When present, config object's
basePath
overrides config array'sbasePath
, meaning thatfiles
andignores
patterns in that config object will be treated as relative to the config object'sbasePath
instead of the config array'sbasePath
.Related Issues
eslint/eslint#18948