diff --git a/packages/config-array/src/config-array.js b/packages/config-array/src/config-array.js index 3aadb0f..1c75b32 100644 --- a/packages/config-array/src/config-array.js +++ b/packages/config-array/src/config-array.js @@ -490,6 +490,67 @@ function assertExtraConfigTypes(extraConfigTypes) { } } +/** + * Calculates whether a file has a config or why it doesn't. + * @param {ConfigArray} configArray A normalized config array. + * @param {string} filePath The path of the file to check. + * @returns {"ignored"|"external"|"unconfigured"|"matched"} One of the constants returned by + * {@linkcode ConfigArray.getConfigStatus}. + */ +function calculateConfigStatus(configArray, filePath) { + // check if the file is outside the base path + const relativeFilePath = path.relative(configArray.basePath, filePath); + if (relativeFilePath.startsWith("..")) return "external"; + + // next check to see if the file should be ignored + if ( + configArray.isDirectoryIgnored(path.dirname(filePath)) || + shouldIgnorePath(configArray.ignores, filePath, relativeFilePath) + ) { + return "ignored"; + } + + // filePath isn't automatically ignored, so try to find a matching config + const universalPattern = /\/\*{1,2}$/; + + for (const config of configArray) { + if (!config.files) continue; + + /* + * If a config has a files pattern ending in /** or /*, and the + * filePath only matches those patterns, then the config is only + * applied if there is another config where the filePath matches + * a file with a specific extensions such as *.js. + */ + + const universalFiles = config.files.filter(pattern => + universalPattern.test(pattern), + ); + + let filteredConfig; + + // universal patterns were found so we need to filter the files + if (universalFiles.length) { + const nonUniversalFiles = config.files.filter( + pattern => !universalPattern.test(pattern), + ); + + filteredConfig = { + files: nonUniversalFiles, + ignores: config.ignores, + }; + } else { + filteredConfig = config; + } + + if (pathMatches(filePath, configArray.basePath, filteredConfig)) { + return "matched"; + } + } + + return "unconfigured"; +} + //------------------------------------------------------------------------------ // Public Interface //------------------------------------------------------------------------------ @@ -582,6 +643,7 @@ export class ConfigArray extends Array { directoryMatches: new Map(), files: undefined, ignores: undefined, + configStatus: new Map(), }); // load the configs into this array @@ -985,6 +1047,31 @@ export class ConfigArray extends Array { return finalConfig; } + /** + * Determines whether a file has a config or why it doesn't. + * @param {string} filePath The path of the file to check. + * @returns {"ignored"|"external"|"unconfigured"|"matched"} One of the following values: + * * `"ignored"`: the file is ignored + * * `"external"`: the file is outside the base path + * * `"unconfigured"`: the file is not matched by any config + * * `"matched"`: the file has a matching config + */ + getConfigStatus(filePath) { + assertNormalized(this); + + // first check the cache for a filename match to avoid duplicate work + const cache = dataCache.get(this).configStatus; + let configStatus = cache.get(filePath); + + if (!configStatus) { + // no cached value found, so calculate + configStatus = calculateConfigStatus(this, filePath); + cache.set(configStatus); + } + + return configStatus; + } + /** * Determines if the given filepath is ignored based on the configs. * @param {string} filePath The complete path of a file to check. @@ -1001,7 +1088,7 @@ export class ConfigArray extends Array { * @returns {boolean} True if the path is ignored, false if not. */ isFileIgnored(filePath) { - return this.getConfig(filePath) === undefined; + return this.getConfigStatus(filePath) === "ignored"; } /** diff --git a/packages/config-array/tests/config-array.test.js b/packages/config-array/tests/config-array.test.js index f796f56..63268bb 100644 --- a/packages/config-array/tests/config-array.test.js +++ b/packages/config-array/tests/config-array.test.js @@ -961,6 +961,793 @@ describe("ConfigArray", () => { }); }); + describe("getConfigStatus()", () => { + it("should throw an error when not normalized", () => { + const filename = path.resolve(basePath, "foo.js"); + assert.throws(() => { + unnormalizedConfigs.getConfigStatus(filename); + }, /normalized/); + }); + + it('should return "matched" when passed JS filename', () => { + const filename = path.resolve(basePath, "foo.js"); + + assert.strictEqual( + configs.getConfigStatus(filename), + "matched", + ); + }); + + it('should return "external" when passed JS filename in parent directory', () => { + const filename = path.resolve(basePath, "../foo.js"); + + assert.strictEqual( + configs.getConfigStatus(filename), + "external", + ); + }); + + it('should return "matched" when passed HTML filename', () => { + const filename = path.resolve(basePath, "foo.html"); + + assert.strictEqual( + configs.getConfigStatus(filename), + "matched", + ); + }); + + it('should return "ignored" when passed ignored .gitignore filename', () => { + const filename = path.resolve(basePath, ".gitignore"); + + assert.strictEqual( + configs.getConfigStatus(filename), + "ignored", + ); + }); + + it('should return "matched" when passed CSS filename', () => { + const filename = path.resolve(basePath, "foo.css"); + + assert.strictEqual( + configs.getConfigStatus(filename), + "matched", + ); + }); + + it('should return "matched" when passed docx filename', () => { + const filename = path.resolve(basePath, "sss.docx"); + + assert.strictEqual( + configs.getConfigStatus(filename), + "matched", + ); + }); + + it('should return "ignored" when passed ignored node_modules filename', () => { + const filename = path.resolve(basePath, "node_modules/foo.js"); + + assert.strictEqual( + configs.getConfigStatus(filename), + "ignored", + ); + }); + + it('should return "unconfigured" when passed matching both files and ignores in a config', () => { + configs = new ConfigArray( + [ + { + files: ["**/*.xsl"], + ignores: ["fixtures/test.xsl"], + defs: { + xsl: true, + }, + }, + ], + { basePath }, + ); + + configs.normalizeSync(); + const filename = path.resolve(basePath, "fixtures/test.xsl"); + + assert.strictEqual( + configs.getConfigStatus(filename), + "unconfigured", + ); + }); + + it('should return "matched" when negated pattern comes after matching pattern', () => { + configs = new ConfigArray( + [ + { + files: ["**/foo.*"], + ignores: ["**/*.txt", "!foo.txt"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "bar.txt")), + "unconfigured", + ); + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "foo.txt")), + "matched", + ); + }); + + it('should return "ignored" when negated pattern comes before matching pattern', () => { + configs = new ConfigArray( + [ + { + ignores: ["!foo.txt", "**/*.txt"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "bar.txt")), + "ignored", + ); + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "foo.txt")), + "ignored", + ); + }); + + it('should return "matched" when matching files and ignores has a negated pattern after matching pattern', () => { + configs = new ConfigArray( + [ + { + files: ["**/*.js"], + ignores: ["**/*.test.js", "!foo.test.js"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "bar.test.js")), + "unconfigured", + ); + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "foo.test.js")), + "matched", + ); + }); + + it('should return "ignored" when file is inside of ignored directory', () => { + configs = new ConfigArray( + [ + { + ignores: ["ignoreme"], + }, + { + files: ["**/*.js"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus( + path.join(basePath, "ignoreme/foo.js"), + ), + "ignored", + ); + }); + + it('should return "matched" when file is inside of unignored directory', () => { + configs = new ConfigArray( + [ + { + files: ["**/*.js"], + }, + { + ignores: ["foo/*", "!foo/bar"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus( + path.join(basePath, "foo/bar/a.js"), + ), + "matched", + ); + }); + + it('should return "ignored" when file is ignored, unignored, and then reignored', () => { + configs = new ConfigArray( + [ + { + files: ["**/*.js"], + }, + { + ignores: ["a.js", "!a*.js", "a.js"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "a.js")), + "ignored", + ); + }); + + it('should return "ignored" when the parent directory of a file is ignored', () => { + configs = new ConfigArray( + [ + { + files: ["**/*.js"], + }, + { + ignores: ["foo"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus( + path.join(basePath, "foo/bar/a.js"), + ), + "ignored", + ); + }); + + it('should "ignored" true when an ignored directory is later negated with **', () => { + configs = new ConfigArray( + [ + { + files: ["**/*.js"], + }, + { + ignores: ["**/node_modules/**"], + }, + { + ignores: ["!node_modules/package/**"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus( + path.join(basePath, "node_modules/package/a.js"), + ), + "ignored", + ); + }); + + it('should return "ignored" when an ignored directory is later negated with *', () => { + configs = new ConfigArray( + [ + { + files: ["**/*.js"], + }, + { + ignores: ["**/node_modules/**"], + }, + { + ignores: ["!node_modules/package/*"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus( + path.join(basePath, "node_modules/package/a.js"), + ), + "ignored", + ); + }); + + it('should return "unconfigured" when there are only patterns ending with /*', () => { + configs = new ConfigArray( + [ + { + files: ["foo/*"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "foo/a.js")), + "unconfigured", + ); + }); + + it('should return "unconfigured" when there are only patterns ending with /**', () => { + configs = new ConfigArray( + [ + { + files: ["foo/**"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "foo/a.js")), + "unconfigured", + ); + }); + + it('should return "matched" when files pattern matches and there is a pattern ending with /**', () => { + configs = new ConfigArray( + [ + { + files: ["foo/*.js", "foo/**"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "foo/a.js")), + "matched", + ); + }); + + it('should return "matched" when file has the same name as a directory that is ignored by a pattern that ends with `/`', () => { + configs = new ConfigArray( + [ + { + files: ["**/foo"], + }, + { + ignores: ["foo/"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "foo")), + "matched", + ); + }); + + it('should return "matched" when file is in the parent directory of directories that are ignored by a pattern that ends with `/`', () => { + configs = new ConfigArray( + [ + { + files: ["**/*.js"], + }, + { + ignores: ["foo/*/"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "foo/a.js")), + "matched", + ); + }); + + it('should return "ignored" when file is in a directory that is ignored by a pattern that ends with `/`', () => { + configs = new ConfigArray( + [ + { + files: ["**/*.js"], + }, + { + ignores: ["foo/"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "foo/a.js")), + "ignored", + ); + }); + + it('should return "ignored" when file is in a directory that is ignored by a pattern that does not end with `/`', () => { + configs = new ConfigArray( + [ + { + files: ["**/*.js"], + }, + { + ignores: ["foo"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "foo/a.js")), + "ignored", + ); + }); + + it('should return "matched" when file is in a directory that is ignored and then unignored by pattern that ends with `/`', () => { + configs = new ConfigArray( + [ + { + files: ["**/*.js"], + }, + { + ignores: ["foo/", "!foo/"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "foo/a.js")), + "matched", + ); + }); + + it('should return "ignored" when file is in a directory that is ignored along with its files by a pattern that ends with `/**` and then unignored by pattern that ends with `/`', () => { + configs = new ConfigArray( + [ + { + files: ["**/*.js"], + }, + { + ignores: [ + "foo/**", + + // only the directory is unignored, files are not + "!foo/", + ], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "foo/a.js")), + "ignored", + ); + }); + + it('should return "ignored" when file is in a directory that is ignored along with its files by a pattern that ends with `/**` and then unignored by pattern that does not end with `/`', () => { + configs = new ConfigArray( + [ + { + files: ["**/*.js"], + }, + { + ignores: [ + "foo/**", + + // only the directory is unignored, files are not + "!foo", + ], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "foo/a.js")), + "ignored", + ); + }); + + it('should return "matched" when file is in a directory that is ignored along its files by pattern that ends with `/**` and then unignored along its files by pattern that ends with `/**`', () => { + configs = new ConfigArray( + [ + { + files: ["**/*.js"], + }, + { + ignores: [ + "foo/**", + + // both the directory and the files are unignored + "!foo/**", + ], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "foo/a.js")), + "matched", + ); + }); + + it('should return "ignored" when file is ignored by a pattern and there are unignore patterns that target files of a directory with the same name', () => { + configs = new ConfigArray( + [ + { + files: ["**/foo"], + }, + { + ignores: ["foo", "!foo/*", "!foo/**"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "foo")), + "ignored", + ); + }); + + it('should return "ignored" when file is in a directory that is ignored even if an unignore pattern that ends with `/*` matches the file', () => { + configs = new ConfigArray( + [ + { + files: ["**/*.js"], + }, + { + ignores: ["foo", "!foo/*"], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus(path.join(basePath, "foo/a.js")), + "ignored", + ); + }); + + // https://github.com/eslint/eslint/issues/17964#issuecomment-1879840650 + it('should return "ignored" for all files ignored in a directory tree except for explicitly unignored ones', () => { + configs = new ConfigArray( + [ + { + files: ["**/*.js"], + }, + { + ignores: [ + // ignore all files and directories + "tests/format/**/*", + + // unignore all directories + "!tests/format/**/*/", + + // unignore specific files + "!tests/format/**/jsfmt.spec.js", + ], + }, + ], + { + basePath, + }, + ); + + configs.normalizeSync(); + + assert.strictEqual( + configs.getConfigStatus( + path.join(basePath, "tests/format/foo.js"), + ), + "ignored", + ); + assert.strictEqual( + configs.getConfigStatus( + path.join(basePath, "tests/format/jsfmt.spec.js"), + ), + "matched", + ); + assert.strictEqual( + configs.getConfigStatus( + path.join(basePath, "tests/format/subdir/foo.js"), + ), + "ignored", + ); + assert.strictEqual( + configs.getConfigStatus( + path.join( + basePath, + "tests/format/subdir/jsfmt.spec.js", + ), + ), + "matched", + ); + }); + + // https://github.com/eslint/eslint/pull/16579/files + describe("gitignore-style unignores", () => { + it('should return "unconfigured" when a subdirectory is ignored and then we try to unignore a directory', () => { + configs = new ConfigArray( + [ + { + ignores: [ + "/**/node_modules/*", + "!/node_modules/foo", + ], + }, + ], + { basePath }, + ); + + configs.normalizeSync(); + const filename = path.resolve( + basePath, + "node_modules/foo/bar.js", + ); + + assert.strictEqual( + configs.getConfigStatus(filename), + "unconfigured", + ); + }); + + it('should return "unconfigured" when a subdirectory is ignored and then we try to unignore a file', () => { + configs = new ConfigArray( + [ + { + ignores: [ + "/**/node_modules/*", + "!/node_modules/foo/**", + ], + }, + ], + { basePath }, + ); + + configs.normalizeSync(); + const filename = path.resolve( + basePath, + "node_modules/foo/bar.js", + ); + + assert.strictEqual( + configs.getConfigStatus(filename), + "unconfigured", + ); + }); + + it("should return true when all descendant directories are ignored and then we try to unignore a file", () => { + configs = new ConfigArray( + [ + { + ignores: [ + "/**/node_modules/**", + "!/node_modules/foo/**", + ], + }, + ], + { basePath }, + ); + + configs.normalizeSync(); + const filename = path.resolve( + basePath, + "node_modules/foo/bar.js", + ); + + assert.strictEqual( + configs.getConfigStatus(filename), + "unconfigured", + ); + }); + + it('should return "ignored" when all descendant directories are ignored without leading slash and then we try to unignore a file', () => { + configs = new ConfigArray( + [ + { + ignores: [ + "**/node_modules/**", + "!/node_modules/foo/**", + ], + }, + ], + { basePath }, + ); + + configs.normalizeSync(); + const filename = path.resolve( + basePath, + "node_modules/foo/bar.js", + ); + + assert.strictEqual( + configs.getConfigStatus(filename), + "ignored", + ); + }); + }); + }); + describe("isIgnored()", () => { it("should throw an error when not normalized", () => { const filename = path.resolve(basePath, "foo.js"); @@ -973,9 +1760,9 @@ describe("ConfigArray", () => { assert.strictEqual(configs.isIgnored(filename), false); }); - it("should return true when passed JS filename in parent directory", () => { + it("should return false when passed JS filename in parent directory", () => { const filename = path.resolve(basePath, "../foo.js"); - assert.strictEqual(configs.isIgnored(filename), true); + assert.strictEqual(configs.isIgnored(filename), false); }); it("should return false when passed HTML filename", () => { @@ -994,7 +1781,7 @@ describe("ConfigArray", () => { assert.strictEqual(configs.isIgnored(filename), false); }); - it("should return true when passed docx filename", () => { + it("should return false when passed docx filename", () => { const filename = path.resolve(basePath, "sss.docx"); assert.strictEqual(configs.isIgnored(filename), false); @@ -1005,50 +1792,6 @@ describe("ConfigArray", () => { assert.strictEqual(configs.isIgnored(filename), true); }); - it("should return true when passed matching both files and ignores in a config", () => { - configs = new ConfigArray( - [ - { - files: ["**/*.xsl"], - ignores: ["fixtures/test.xsl"], - defs: { - xsl: true, - }, - }, - ], - { basePath }, - ); - - configs.normalizeSync(); - const filename = path.resolve(basePath, "fixtures/test.xsl"); - - assert.strictEqual(configs.isIgnored(filename), true); - }); - - it("should return false when negated pattern comes after matching pattern", () => { - configs = new ConfigArray( - [ - { - files: ["**/foo.*"], - ignores: ["**/*.txt", "!foo.txt"], - }, - ], - { - basePath, - }, - ); - - configs.normalizeSync(); - - assert.strictEqual( - configs.isIgnored(path.join(basePath, "bar.txt")), - true, - ); - assert.strictEqual( - configs.isIgnored(path.join(basePath, "foo.txt")), - false, - ); - }); it("should return true when negated pattern comes before matching pattern", () => { configs = new ConfigArray( @@ -1073,31 +1816,6 @@ describe("ConfigArray", () => { true, ); }); - - it("should return false when matching files and ignores has a negated pattern comes after matching pattern", () => { - configs = new ConfigArray( - [ - { - files: ["**/*.js"], - ignores: ["**/*.test.js", "!foo.test.js"], - }, - ], - { - basePath, - }, - ); - - configs.normalizeSync(); - - assert.strictEqual( - configs.isIgnored(path.join(basePath, "bar.test.js")), - true, - ); - assert.strictEqual( - configs.isIgnored(path.join(basePath, "foo.test.js")), - false, - ); - }); }); describe("isFileIgnored()", () => { @@ -1114,10 +1832,10 @@ describe("ConfigArray", () => { assert.strictEqual(configs.isFileIgnored(filename), false); }); - it("should return true when passed JS filename in parent directory", () => { + it("should return false when passed JS filename in parent directory", () => { const filename = path.resolve(basePath, "../foo.js"); - assert.strictEqual(configs.isFileIgnored(filename), true); + assert.strictEqual(configs.isFileIgnored(filename), false); }); it("should return false when passed HTML filename", () => { @@ -1138,7 +1856,7 @@ describe("ConfigArray", () => { assert.strictEqual(configs.isFileIgnored(filename), false); }); - it("should return true when passed docx filename", () => { + it("should return false when passed docx filename", () => { const filename = path.resolve(basePath, "sss.docx"); assert.strictEqual(configs.isFileIgnored(filename), false); @@ -1150,51 +1868,6 @@ describe("ConfigArray", () => { assert.strictEqual(configs.isFileIgnored(filename), true); }); - it("should return true when passed matching both files and ignores in a config", () => { - configs = new ConfigArray( - [ - { - files: ["**/*.xsl"], - ignores: ["fixtures/test.xsl"], - defs: { - xsl: true, - }, - }, - ], - { basePath }, - ); - - configs.normalizeSync(); - const filename = path.resolve(basePath, "fixtures/test.xsl"); - - assert.strictEqual(configs.isFileIgnored(filename), true); - }); - - it("should return false when negated pattern comes after matching pattern", () => { - configs = new ConfigArray( - [ - { - files: ["**/foo.*"], - ignores: ["**/*.txt", "!foo.txt"], - }, - ], - { - basePath, - }, - ); - - configs.normalizeSync(); - - assert.strictEqual( - configs.isFileIgnored(path.join(basePath, "bar.txt")), - true, - ); - assert.strictEqual( - configs.isFileIgnored(path.join(basePath, "foo.txt")), - false, - ); - }); - it("should return true when negated pattern comes before matching pattern", () => { configs = new ConfigArray( [ @@ -1219,32 +1892,7 @@ describe("ConfigArray", () => { ); }); - it("should return false when matching files and ignores has a negated pattern comes after matching pattern", () => { - configs = new ConfigArray( - [ - { - files: ["**/*.js"], - ignores: ["**/*.test.js", "!foo.test.js"], - }, - ], - { - basePath, - }, - ); - - configs.normalizeSync(); - - assert.strictEqual( - configs.isFileIgnored(path.join(basePath, "bar.test.js")), - true, - ); - assert.strictEqual( - configs.isFileIgnored(path.join(basePath, "foo.test.js")), - false, - ); - }); - - it("should return false when file is inside of ignored directory", () => { + it("should return true when file is inside of ignored directory", () => { configs = new ConfigArray( [ { @@ -1269,7 +1917,7 @@ describe("ConfigArray", () => { ); }); - it("should return false when file is inside of ignored directory", () => { + it("should return false when file is inside of unignored directory", () => { configs = new ConfigArray( [ { @@ -1394,66 +2042,6 @@ describe("ConfigArray", () => { ); }); - it("should return true when there are only patterns ending with /*", () => { - configs = new ConfigArray( - [ - { - files: ["foo/*"], - }, - ], - { - basePath, - }, - ); - - configs.normalizeSync(); - - assert.strictEqual( - configs.isFileIgnored(path.join(basePath, "foo/a.js")), - true, - ); - }); - - it("should return true when there are only patterns ending with /**", () => { - configs = new ConfigArray( - [ - { - files: ["foo/**"], - }, - ], - { - basePath, - }, - ); - - configs.normalizeSync(); - - assert.strictEqual( - configs.isFileIgnored(path.join(basePath, "foo/a.js")), - true, - ); - }); - - it("should return false when files pattern matches and there is a pattern ending with /**", () => { - configs = new ConfigArray( - [ - { - files: ["foo/*.js", "foo/**"], - }, - ], - { - basePath, - }, - ); - - configs.normalizeSync(); - - assert.strictEqual( - configs.isFileIgnored(path.join(basePath, "foo/a.js")), - false, - ); - }); - it("should return false when file has the same name as a directory that is ignored by a pattern that ends with `/`", () => { configs = new ConfigArray( [ @@ -1546,7 +2134,7 @@ describe("ConfigArray", () => { ); }); - it("should return false when file is in a directory that is ignored and then unignored by pattern that end with `/`", () => { + it("should return false when file is in a directory that is ignored and then unignored by pattern that ends with `/`", () => { configs = new ConfigArray( [ { @@ -1757,7 +2345,7 @@ describe("ConfigArray", () => { // https://github.com/eslint/eslint/pull/16579/files describe("gitignore-style unignores", () => { - it("should return true when a subdirectory is ignored and then we try to unignore a directory", () => { + it("should return false when a subdirectory is ignored and then we try to unignore a directory", () => { configs = new ConfigArray( [ { @@ -1776,7 +2364,7 @@ describe("ConfigArray", () => { "node_modules/foo/bar.js", ); - assert.strictEqual(configs.isFileIgnored(filename), true); + assert.strictEqual(configs.isFileIgnored(filename), false); }); it("should return true when a subdirectory is ignored and then we try to unignore a file", () => { @@ -1798,7 +2386,7 @@ describe("ConfigArray", () => { "node_modules/foo/bar.js", ); - assert.strictEqual(configs.isFileIgnored(filename), true); + assert.strictEqual(configs.isFileIgnored(filename), false); }); it("should return true when all descendant directories are ignored and then we try to unignore a file", () => { @@ -1820,7 +2408,7 @@ describe("ConfigArray", () => { "node_modules/foo/bar.js", ); - assert.strictEqual(configs.isFileIgnored(filename), true); + assert.strictEqual(configs.isFileIgnored(filename), false); }); it("should return true when all descendant directories are ignored without leading slash and then we try to unignore a file", () => {