Skip to content

Commit

Permalink
feat: change default ignore pattern to **/node_modules/ in flat config
Browse files Browse the repository at this point in the history
Fixes #17113
  • Loading branch information
mdjermanovic committed May 17, 2023
1 parent 94da96c commit 15fc02d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
16 changes: 15 additions & 1 deletion docs/src/use/configure/configuration-files-new.md
Expand Up @@ -143,7 +143,21 @@ export default [
];
```

This configuration specifies that all of the files in the `.config` directory should be ignored. This pattern is added after the default patterns, which are `["**/node_modules/**", ".git/**"]`.
This configuration specifies that all of the files in the `.config` directory should be ignored. This pattern is added after the default patterns, which are `["**/node_modules/", ".git/"]`.

You can also unignore files and directories that are ignored by the default patterns. For example, this config unignores `node_modules/mylibrary`:

```js
export default [
{
ignores: [
"!node_modules/", // unignore `node_modules/` directory
"node_modules/*", // ignore its content
"!node_modules/mylibrary/" // unignore `node_modules/mylibrary` directory
]
}
];
```

#### Cascading configuration objects

Expand Down
2 changes: 1 addition & 1 deletion lib/config/default-config.js
Expand Up @@ -48,7 +48,7 @@ exports.defaultConfig = [
// default ignores are listed here
{
ignores: [
"**/node_modules/*",
"**/node_modules/",
".git/"
]
},
Expand Down
18 changes: 9 additions & 9 deletions tests/lib/eslint/flat-eslint.js
Expand Up @@ -3578,26 +3578,26 @@ describe("FlatESLint", () => {
assert(await engine.isPathIgnored(getFixturePath("ignored-paths", "subdir/node_modules/package/file.js")));
});

it("should allow subfolders of defaultPatterns to be unignored by ignorePattern", async () => {
it("should allow subfolders of defaultPatterns to be unignored by ignorePattern constructor option", async () => {
const cwd = getFixturePath("ignored-paths");
const engine = new FlatESLint({
cwd,
overrideConfigFile: true,
ignorePatterns: ["!node_modules/package/**"]
ignorePatterns: ["!node_modules/", "node_modules/*", "!node_modules/package/"]
});

const result = await engine.isPathIgnored(getFixturePath("ignored-paths", "node_modules", "package", "file.js"));

assert(!result, "File should not be ignored");
});

it("should allow subfolders of defaultPatterns to be unignored by ignorePath", async () => {
it("should allow subfolders of defaultPatterns to be unignored by ignores in overrideConfig", async () => {
const cwd = getFixturePath("ignored-paths");
const engine = new FlatESLint({
cwd,
overrideConfigFile: true,
overrideConfig: {
ignores: ["!node_modules/package/**"]
ignores: ["!node_modules/", "node_modules/*", "!node_modules/package/"]
}
});

Expand Down Expand Up @@ -4608,13 +4608,13 @@ describe("FlatESLint", () => {
});


describe("ignores can unignore '/node_modules/foo'.", () => {
describe("ignores can unignore '/node_modules/foo' with patterns ['!node_modules/', 'node_modules/*', '!node_modules/foo/'].", () => {

const { prepare, cleanup, getPath } = createCustomTeardown({
cwd: `${root}-unignores`,
files: {
"eslint.config.js": `module.exports = {
ignores: ["!**/node_modules/foo"]
ignores: ["!node_modules/", "node_modules/*", "!node_modules/foo/"]
};`,
"node_modules/foo/index.js": "",
"node_modules/foo/.dot.js": "",
Expand Down Expand Up @@ -4659,13 +4659,13 @@ describe("FlatESLint", () => {
});
});

describe("ignores can unignore '/node_modules/foo/**'.", () => {
describe("ignores can unignore '/node_modules/foo' with patterns ['!node_modules/', 'node_modules/*', '!node_modules/foo/**'].", () => {

const { prepare, cleanup, getPath } = createCustomTeardown({
cwd: `${root}-unignores`,
files: {
"eslint.config.js": `module.exports = {
ignores: ["!**/node_modules/foo/**"]
ignores: ["!node_modules/", "node_modules/*", "!node_modules/foo/**"]
};`,
"node_modules/foo/index.js": "",
"node_modules/foo/.dot.js": "",
Expand Down Expand Up @@ -5194,7 +5194,7 @@ describe("FlatESLint", () => {
cwd: `${root}a3`,
files: {
"node_modules/myconf/eslint.config.js": `module.exports = [{
ignores: ["!node_modules/myconf", "foo/*.js"],
ignores: ["!node_modules", "node_modules/*", "!node_modules/myconf", "foo/*.js"],
}, {
rules: {
eqeqeq: "error"
Expand Down

0 comments on commit 15fc02d

Please sign in to comment.