Skip to content

Commit

Permalink
Update: do not ignore symbolic links (fixes #13551, fixes #13615) (#1…
Browse files Browse the repository at this point in the history
…4126)

* Fix: do not ignore symbolic links (fixes #13551, fixes #13615)

* Fix: ignore broken symbolic links
  • Loading branch information
g-plane committed Feb 26, 2021
1 parent 87c43a5 commit 5e51fd2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/cli-engine/file-enumerator.js
Expand Up @@ -433,9 +433,14 @@ class FileEnumerator {
// Enumerate the files of this directory.
for (const entry of readdirSafeSync(directoryPath)) {
const filePath = path.join(directoryPath, entry.name);
const fileInfo = entry.isSymbolicLink() ? statSafeSync(filePath) : entry;

if (!fileInfo) {
continue;
}

// Check if the file is matched.
if (entry.isFile()) {
if (fileInfo.isFile()) {
if (!config) {
config = configArrayFactory.getConfigArrayForFile(
filePath,
Expand Down Expand Up @@ -471,7 +476,7 @@ class FileEnumerator {
}

// Dive into the sub directory.
} else if (options.recursive && entry.isDirectory()) {
} else if (options.recursive && fileInfo.isDirectory()) {
if (!config) {
config = configArrayFactory.getConfigArrayForFile(
filePath,
Expand Down
44 changes: 44 additions & 0 deletions tests/lib/cli-engine/file-enumerator.js
Expand Up @@ -487,6 +487,50 @@ describe("FileEnumerator", () => {
});
});
});

describe("if contains symbolic links", async () => {
const root = path.join(os.tmpdir(), "eslint/file-enumerator");
const files = {
"dir1/1.js": "",
"dir1/2.js": "",
"top-level.js": "",
".eslintrc.json": JSON.stringify({ rules: {} })
};
const dir2 = path.join(root, "dir2");
const { prepare, cleanup } = createCustomTeardown({ cwd: root, files });

beforeEach(async () => {
await prepare();
fs.mkdirSync(dir2);
fs.symlinkSync(path.join(root, "top-level.js"), path.join(dir2, "top.js"), "file");
fs.symlinkSync(path.join(root, "dir1"), path.join(dir2, "nested"), "dir");
});

afterEach(cleanup);

it("should resolve", () => {
const enumerator = new FileEnumerator({ cwd: root });
const list = Array.from(enumerator.iterateFiles(["dir2/**/*.js"])).map(({ filePath }) => filePath);

assert.deepStrictEqual(list, [
path.join(dir2, "nested", "1.js"),
path.join(dir2, "nested", "2.js"),
path.join(dir2, "top.js")
]);
});

it("should ignore broken links", () => {
fs.unlinkSync(path.join(root, "top-level.js"));

const enumerator = new FileEnumerator({ cwd: root });
const list = Array.from(enumerator.iterateFiles(["dir2/**/*.js"])).map(({ filePath }) => filePath);

assert.deepStrictEqual(list, [
path.join(dir2, "nested", "1.js"),
path.join(dir2, "nested", "2.js")
]);
});
});
});

// https://github.com/eslint/eslint/issues/13789
Expand Down

0 comments on commit 5e51fd2

Please sign in to comment.