Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: do not ignore symbolic links (fixes #13551, fixes #13615) #14126

Merged
merged 2 commits into from Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/cli-engine/file-enumerator.js
Expand Up @@ -433,9 +433,10 @@ 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;
g-plane marked this conversation as resolved.
Show resolved Hide resolved

// Check if the file is matched.
if (entry.isFile()) {
if (fileInfo.isFile()) {
if (!config) {
config = configArrayFactory.getConfigArrayForFile(
filePath,
Expand Down Expand Up @@ -471,7 +472,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
32 changes: 32 additions & 0 deletions tests/lib/cli-engine/file-enumerator.js
Expand Up @@ -487,6 +487,38 @@ 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")
]);
});
});
});

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