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: Support basePath property in config objects #131

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mdjermanovic
Copy link
Member

Summary

This RFC proposes supporting basePath property in config objects.

When present, config object's basePath overrides config array's basePath, meaning that files and ignores patterns in that config object will be treated as relative to the config object's basePath instead of the config array's basePath.

Related Issues

eslint/eslint#18948

@mdjermanovic mdjermanovic changed the title feat: Support basePath` property in config objects feat: Support basePath property in config objects Mar 31, 2025
@nzakas nzakas added the Initial Commenting This RFC is in the initial feedback stage label Mar 31, 2025
- `filesAndIgnoresSchema` will be updated to validate that the new `basePath` property, if present, has a string value.
- `normalizeConfigPatterns()` will be updated to normalize the `basePath` property value to an equivalent namespace-prefixed path, for consistency with the config array's `basePath` property value.
- `META_FIELDS` will be updated to include `"basePath"`, in order to treat config objects with `basePath` + `ignores` as global ignores.
- `get ignores()` will be updated to return an array of config objects instead of an array of ignore patterns.
Copy link
Member

Choose a reason for hiding this comment

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

Presumably this is because we need to combine the basePath with the ignore patterns to get the correct files/directories to ignore? If so, can you add that detail here?


## 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.
Copy link
Member

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?

@fasttime
Copy link
Member

fasttime commented Apr 2, 2025

I'm thinking about the situation where a parent config and an extended config have different base paths. Per the current defineConfig logic, the files and ignores properties would be merged, but the merged config will inherit the extended config's base path, which seems unexpected.

Maybe relative base paths in extended configs should be joined to the base path of the parent config?

@nzakas
Copy link
Member

nzakas commented Apr 2, 2025

I'm thinking about the situation where a parent config and an extended config have different base paths.

I'm not sure I understand what you're describing. Can you provide an example?

@fasttime
Copy link
Member

fasttime commented Apr 3, 2025

Here's an example where the basePath property is manually defined on the parent object:

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 files of the parent config without the basePath that should be used to resolve those patterns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Initial Commenting This RFC is in the initial feedback stage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants