diff --git a/package.json b/package.json index 424b5b77733..9e26685f596 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "homepage": "https://eslint.org", "bugs": "https://github.com/eslint/eslint/issues/", "dependencies": { - "@eslint/eslintrc": "^1.2.0", + "@eslint/eslintrc": "^1.2.1", "@humanwhocodes/config-array": "^0.9.2", "ajv": "^6.10.0", "chalk": "^4.0.0", diff --git a/tests/fixtures/ignored-paths/.eslintignoreWithEscapedBrackets b/tests/fixtures/ignored-paths/.eslintignoreWithEscapedBrackets new file mode 100644 index 00000000000..4cc03e6a21d --- /dev/null +++ b/tests/fixtures/ignored-paths/.eslintignoreWithEscapedBrackets @@ -0,0 +1,3 @@ +brackets/\[index.js +brackets/index\].js +brackets/\[index\].js diff --git a/tests/fixtures/ignored-paths/brackets/[index.js b/tests/fixtures/ignored-paths/brackets/[index.js new file mode 100644 index 00000000000..9b2b3016bd0 --- /dev/null +++ b/tests/fixtures/ignored-paths/brackets/[index.js @@ -0,0 +1 @@ +/* content is not necessary */ diff --git a/tests/fixtures/ignored-paths/brackets/[index].js b/tests/fixtures/ignored-paths/brackets/[index].js new file mode 100644 index 00000000000..9b2b3016bd0 --- /dev/null +++ b/tests/fixtures/ignored-paths/brackets/[index].js @@ -0,0 +1 @@ +/* content is not necessary */ diff --git a/tests/fixtures/ignored-paths/brackets/index.js b/tests/fixtures/ignored-paths/brackets/index.js new file mode 100644 index 00000000000..9b2b3016bd0 --- /dev/null +++ b/tests/fixtures/ignored-paths/brackets/index.js @@ -0,0 +1 @@ +/* content is not necessary */ diff --git a/tests/fixtures/ignored-paths/brackets/index].js b/tests/fixtures/ignored-paths/brackets/index].js new file mode 100644 index 00000000000..9b2b3016bd0 --- /dev/null +++ b/tests/fixtures/ignored-paths/brackets/index].js @@ -0,0 +1 @@ +/* content is not necessary */ diff --git a/tests/lib/eslint/eslint.js b/tests/lib/eslint/eslint.js index 29c5fa164f5..2cec67fde6b 100644 --- a/tests/lib/eslint/eslint.js +++ b/tests/lib/eslint/eslint.js @@ -1446,6 +1446,21 @@ describe("ESLint", () => { }, /All files matched by '\.\/tests\/fixtures\/cli-engine\/' are ignored\./u); }); + // https://github.com/eslint/eslint/issues/15642 + it("should ignore files that are ignored by patterns with escaped brackets", async () => { + eslint = new ESLint({ + ignorePath: getFixturePath("ignored-paths", ".eslintignoreWithEscapedBrackets"), + useEslintrc: false, + cwd: getFixturePath("ignored-paths") + }); + + // Only `brackets/index.js` should be linted. Other files in `brackets/` should be ignored. + const results = await eslint.lintFiles(["brackets/*.js"]); + + assert.strictEqual(results.length, 1); + assert.strictEqual(results[0].filePath, getFixturePath("ignored-paths", "brackets", "index.js")); + }); + it("should throw an error when all given files are ignored via ignore-pattern", async () => { eslint = new ESLint({ overrideConfig: { @@ -4677,6 +4692,28 @@ describe("ESLint", () => { assert(!await engine.isPathIgnored(getFixturePath("ignored-paths", "negation", "unignore.js"))); }); + + // https://github.com/eslint/eslint/issues/15642 + it("should correctly handle patterns with escaped brackets", async () => { + const cwd = getFixturePath("ignored-paths"); + const ignorePath = getFixturePath("ignored-paths", ".eslintignoreWithEscapedBrackets"); + const engine = new ESLint({ ignorePath, cwd }); + + const subdir = "brackets"; + + assert( + !await engine.isPathIgnored(getFixturePath("ignored-paths", subdir, "index.js")), + `'${subdir}/index.js' should not be ignored` + ); + + for (const filename of ["[index.js", "index].js", "[index].js"]) { + assert( + await engine.isPathIgnored(getFixturePath("ignored-paths", subdir, filename)), + `'${subdir}/${filename}' should be ignored` + ); + } + + }); }); describe("with --ignore-path option and --ignore-pattern option", () => {