Skip to content

Commit

Permalink
Fix: glob processing (fixes #11940) (#11986)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jul 21, 2019
1 parent bfcf8b2 commit d08683e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
18 changes: 5 additions & 13 deletions lib/cli-engine/file-enumerator.js
Expand Up @@ -292,26 +292,18 @@ class FileEnumerator {
_iterateFiles(pattern) {
const { cwd, globInputPaths } = internalSlotsMap.get(this);
const absolutePath = path.resolve(cwd, pattern);

if (globInputPaths && isGlobPattern(pattern)) {
return this._iterateFilesWithGlob(
absolutePath,
dotfilesPattern.test(pattern)
);
}

const isDot = dotfilesPattern.test(pattern);
const stat = statSafeSync(absolutePath);

if (stat && stat.isDirectory()) {
return this._iterateFilesWithDirectory(
absolutePath,
dotfilesPattern.test(pattern)
);
return this._iterateFilesWithDirectory(absolutePath, isDot);
}

if (stat && stat.isFile()) {
return this._iterateFilesWithFile(absolutePath);
}
if (globInputPaths && isGlobPattern(pattern)) {
return this._iterateFilesWithGlob(absolutePath, isDot);
}

return [];
}
Expand Down
41 changes: 41 additions & 0 deletions tests/lib/cli-engine/cli-engine.js
Expand Up @@ -3454,6 +3454,47 @@ describe("CLIEngine", () => {
assert.strictEqual(report.results[0].messages[0].message, "ok");
});
});

describe("glob pattern '[ab].js'", () => {
const root = getFixturePath("cli-engine/unmatched-glob");

it("should match '[ab].js' if existed.", () => {
CLIEngine = defineCLIEngineWithInMemoryFileSystem({
cwd: () => root,
files: {
"a.js": "",
"b.js": "",
"ab.js": "",
"[ab].js": "",
".eslintrc.yml": "root: true"
}
}).CLIEngine;
engine = new CLIEngine();

const { results } = engine.executeOnFiles(["[ab].js"]);
const filenames = results.map(r => path.basename(r.filePath));

assert.deepStrictEqual(filenames, ["[ab].js"]);
});

it("should match 'a.js' and 'b.js' if '[ab].js' didn't existed.", () => {
CLIEngine = defineCLIEngineWithInMemoryFileSystem({
cwd: () => root,
files: {
"a.js": "",
"b.js": "",
"ab.js": "",
".eslintrc.yml": "root: true"
}
}).CLIEngine;
engine = new CLIEngine();

const { results } = engine.executeOnFiles(["[ab].js"]);
const filenames = results.map(r => path.basename(r.filePath));

assert.deepStrictEqual(filenames, ["a.js", "b.js"]);
});
});
});

describe("getConfigForFile", () => {
Expand Down

0 comments on commit d08683e

Please sign in to comment.