Skip to content

Commit cf38d0d

Browse files
authoredFeb 14, 2020
Breaking: change default ignore pattern (refs eslint/rfcs#51) (#12888)
1 parent bfe1dc4 commit cf38d0d

File tree

4 files changed

+34
-47
lines changed

4 files changed

+34
-47
lines changed
 

‎docs/user-guide/configuring.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -1061,20 +1061,18 @@ Of particular note is that like `.gitignore` files, all paths used as patterns f
10611061

10621062
Please see `.gitignore`'s specification for further examples of valid syntax.
10631063

1064-
In addition to any patterns in a `.eslintignore` file, ESLint always ignores files in `/node_modules/*` and `/bower_components/*`.
1064+
In addition to any patterns in a `.eslintignore` file, ESLint always ignores files in `/**/node_modules/*`.
10651065

1066-
For example, placing the following `.eslintignore` file in the current working directory will ignore all of `node_modules`, `bower_components` in the project root and anything in the `build/` directory except `build/index.js`:
1066+
For example, placing the following `.eslintignore` file in the current working directory will ignore all of `node_modules/*` and anything in the `build/` directory except `build/index.js`:
10671067

10681068
```text
1069-
# /node_modules/* and /bower_components/* in the project root are ignored by default
1069+
# node_modules/* are ignored by default
10701070
10711071
# Ignore built files except build/index.js
10721072
build/*
10731073
!build/index.js
10741074
```
10751075

1076-
**Important**: Note that `node_modules` directories in, for example, a `packages` directory in a mono repo are *not* ignored by default and need to be added to `.eslintignore` explicitly.
1077-
10781076
### Using an Alternate File
10791077

10801078
If you'd prefer to use a different file than the `.eslintignore` in the current working directory, you can specify it on the command line using the `--ignore-path` option. For example, you can use `.jshintignore` file because it has the same format:

‎lib/cli-engine/cli-engine.js

-3
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,11 @@ function createIgnoreResult(filePath, baseDir) {
278278
let message;
279279
const isHidden = /^\./u.test(path.basename(filePath));
280280
const isInNodeModules = baseDir && path.relative(baseDir, filePath).startsWith("node_modules");
281-
const isInBowerComponents = baseDir && path.relative(baseDir, filePath).startsWith("bower_components");
282281

283282
if (isHidden) {
284283
message = "File ignored by default. Use a negated ignore pattern (like \"--ignore-pattern '!<relative/path/to/filename>'\") to override.";
285284
} else if (isInNodeModules) {
286285
message = "File ignored by default. Use \"--ignore-pattern '!node_modules/*'\" to override.";
287-
} else if (isInBowerComponents) {
288-
message = "File ignored by default. Use \"--ignore-pattern '!bower_components/*'\" to override.";
289286
} else {
290287
message = "File ignored because of a matching ignore pattern. Use \"--no-ignore\" to override.";
291288
}

‎lib/cli-engine/config-array/ignore-pattern.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ function dirSuffix(filePath) {
103103
return isDir ? "/" : "";
104104
}
105105

106-
const DefaultPatterns = Object.freeze(["/node_modules/*", "/bower_components/*"]);
107-
const DotPatterns = Object.freeze([".*", "!../"]);
106+
const DefaultPatterns = Object.freeze(["/**/node_modules/*"]);
107+
const DotPatterns = Object.freeze([".*", "!.eslintrc.*", "!../"]);
108108

109109
//------------------------------------------------------------------------------
110110
// Public

‎tests/lib/cli-engine/cli-engine.js

+29-37
Original file line numberDiff line numberDiff line change
@@ -3796,24 +3796,16 @@ describe("CLIEngine", () => {
37963796
const cwd = getFixturePath("ignored-paths");
37973797
const engine = new CLIEngine({ cwd });
37983798

3799-
assert(engine.isPathIgnored(getFixturePath("ignored-paths", "bower_components/package/file.js")));
38003799
assert(engine.isPathIgnored(getFixturePath("ignored-paths", "node_modules/package/file.js")));
3800+
assert(engine.isPathIgnored(getFixturePath("ignored-paths", "subdir/node_modules/package/file.js")));
38013801
});
38023802

38033803
it("should still apply defaultPatterns if ignore option is is false", () => {
38043804
const cwd = getFixturePath("ignored-paths");
38053805
const engine = new CLIEngine({ ignore: false, cwd });
38063806

3807-
assert(engine.isPathIgnored(getFixturePath("ignored-paths", "bower_components/package/file.js")));
38083807
assert(engine.isPathIgnored(getFixturePath("ignored-paths", "node_modules/package/file.js")));
3809-
});
3810-
3811-
it("should not ignore files in defaultPatterns within a subdirectory", () => {
3812-
const cwd = getFixturePath("ignored-paths");
3813-
const engine = new CLIEngine({ cwd });
3814-
3815-
assert(!engine.isPathIgnored(getFixturePath("ignored-paths", "subdir/bower_components/package/file.js")));
3816-
assert(!engine.isPathIgnored(getFixturePath("ignored-paths", "subdir/node_modules/package/file.js")));
3808+
assert(engine.isPathIgnored(getFixturePath("ignored-paths", "subdir/node_modules/package/file.js")));
38173809
});
38183810

38193811
it("should allow subfolders of defaultPatterns to be unignored by ignorePattern", () => {
@@ -3869,20 +3861,20 @@ describe("CLIEngine", () => {
38693861
assert(!engine.isPathIgnored(`${getFixturePath("ignored-paths", "foo")}/../unignored.js`));
38703862
});
38713863

3872-
it("should ignore /node_modules/ at top level relative to .eslintignore when loaded", () => {
3864+
it("should ignore /node_modules/ relative to .eslintignore when loaded", () => {
38733865
const cwd = getFixturePath("ignored-paths");
38743866
const engine = new CLIEngine({ ignorePath: getFixturePath("ignored-paths", ".eslintignore"), cwd });
38753867

38763868
assert(engine.isPathIgnored(getFixturePath("ignored-paths", "node_modules", "existing.js")));
3877-
assert(!engine.isPathIgnored(getFixturePath("ignored-paths", "foo", "node_modules", "existing.js")));
3869+
assert(engine.isPathIgnored(getFixturePath("ignored-paths", "foo", "node_modules", "existing.js")));
38783870
});
38793871

3880-
it("should ignore /node_modules/ at top level relative to cwd without an .eslintignore", () => {
3872+
it("should ignore /node_modules/ relative to cwd without an .eslintignore", () => {
38813873
const cwd = getFixturePath("ignored-paths", "no-ignore-file");
38823874
const engine = new CLIEngine({ cwd });
38833875

38843876
assert(engine.isPathIgnored(getFixturePath("ignored-paths", "no-ignore-file", "node_modules", "existing.js")));
3885-
assert(!engine.isPathIgnored(getFixturePath("ignored-paths", "no-ignore-file", "foo", "node_modules", "existing.js")));
3877+
assert(engine.isPathIgnored(getFixturePath("ignored-paths", "no-ignore-file", "foo", "node_modules", "existing.js")));
38863878
});
38873879
});
38883880

@@ -5052,12 +5044,12 @@ describe("CLIEngine", () => {
50525044
InMemoryCLIEngine = defineCLIEngineWithInMemoryFileSystem({
50535045
cwd: () => root,
50545046
files: {
5055-
".eslintrc.js": `module.exports = ${JSON.stringify({
5047+
".eslintrc.json": JSON.stringify({
50565048
ignorePatterns: "foo.js"
5057-
})}`,
5058-
"subdir/.eslintrc.js": `module.exports = ${JSON.stringify({
5049+
}),
5050+
"subdir/.eslintrc.json": JSON.stringify({
50595051
ignorePatterns: "bar.js"
5060-
})}`,
5052+
}),
50615053
"foo.js": "",
50625054
"bar.js": "",
50635055
"subdir/foo.js": "",
@@ -5107,12 +5099,12 @@ describe("CLIEngine", () => {
51075099
InMemoryCLIEngine = defineCLIEngineWithInMemoryFileSystem({
51085100
cwd: () => root,
51095101
files: {
5110-
".eslintrc.js": `module.exports = ${JSON.stringify({
5102+
".eslintrc.json": JSON.stringify({
51115103
ignorePatterns: "foo.js"
5112-
})}`,
5113-
"subdir/.eslintrc.js": `module.exports = ${JSON.stringify({
5104+
}),
5105+
"subdir/.eslintrc.json": JSON.stringify({
51145106
ignorePatterns: "!foo.js"
5115-
})}`,
5107+
}),
51165108
"foo.js": "",
51175109
"subdir/foo.js": ""
51185110
}
@@ -5193,13 +5185,13 @@ describe("CLIEngine", () => {
51935185
InMemoryCLIEngine = defineCLIEngineWithInMemoryFileSystem({
51945186
cwd: () => root,
51955187
files: {
5196-
".eslintrc.js": `module.exports = ${JSON.stringify({
5188+
".eslintrc.json": JSON.stringify({
51975189
ignorePatterns: "foo.js"
5198-
})}`,
5199-
"subdir/.eslintrc.js": `module.exports = ${JSON.stringify({
5190+
}),
5191+
"subdir/.eslintrc.json": JSON.stringify({
52005192
root: true,
52015193
ignorePatterns: "bar.js"
5202-
})}`,
5194+
}),
52035195
"foo.js": "",
52045196
"bar.js": "",
52055197
"subdir/foo.js": "",
@@ -5251,11 +5243,11 @@ describe("CLIEngine", () => {
52515243
InMemoryCLIEngine = defineCLIEngineWithInMemoryFileSystem({
52525244
cwd: () => root,
52535245
files: {
5254-
".eslintrc.js": `module.exports = ${JSON.stringify({})}`,
5255-
"subdir/.eslintrc.js": `module.exports = ${JSON.stringify({
5246+
".eslintrc.json": JSON.stringify({}),
5247+
"subdir/.eslintrc.json": JSON.stringify({
52565248
root: true,
52575249
ignorePatterns: "bar.js"
5258-
})}`,
5250+
}),
52595251
".eslintignore": "foo.js",
52605252
"foo.js": "",
52615253
"bar.js": "",
@@ -5305,9 +5297,9 @@ describe("CLIEngine", () => {
53055297
"node_modules/eslint-config-one/index.js": `module.exports = ${JSON.stringify({
53065298
ignorePatterns: "foo.js"
53075299
})}`,
5308-
".eslintrc.js": `module.exports = ${JSON.stringify({
5300+
".eslintrc.json": JSON.stringify({
53095301
extends: "one"
5310-
})}`,
5302+
}),
53115303
"foo.js": "",
53125304
"bar.js": ""
53135305
}
@@ -5347,9 +5339,9 @@ describe("CLIEngine", () => {
53475339
"node_modules/eslint-config-one/index.js": `module.exports = ${JSON.stringify({
53485340
ignorePatterns: "/foo.js"
53495341
})}`,
5350-
".eslintrc.js": `module.exports = ${JSON.stringify({
5342+
".eslintrc.json": JSON.stringify({
53515343
extends: "one"
5352-
})}`,
5344+
}),
53535345
"foo.js": "",
53545346
"subdir/foo.js": ""
53555347
}
@@ -5389,10 +5381,10 @@ describe("CLIEngine", () => {
53895381
"node_modules/eslint-config-one/index.js": `module.exports = ${JSON.stringify({
53905382
ignorePatterns: "*.js"
53915383
})}`,
5392-
".eslintrc.js": `module.exports = ${JSON.stringify({
5384+
".eslintrc.json": JSON.stringify({
53935385
extends: "one",
53945386
ignorePatterns: "!bar.js"
5395-
})}`,
5387+
}),
53965388
"foo.js": "",
53975389
"bar.js": ""
53985390
}
@@ -5429,9 +5421,9 @@ describe("CLIEngine", () => {
54295421
InMemoryCLIEngine = defineCLIEngineWithInMemoryFileSystem({
54305422
cwd: () => root,
54315423
files: {
5432-
".eslintrc.js": `module.exports = ${JSON.stringify({
5424+
".eslintrc.json": JSON.stringify({
54335425
ignorePatterns: "*.js"
5434-
})}`,
5426+
}),
54355427
"foo.js": ""
54365428
}
54375429
}).CLIEngine;

0 commit comments

Comments
 (0)
Please sign in to comment.