Skip to content

Commit 8e816ad

Browse files
sanmai-NLfisker
andauthored
Allow skipping symlink patterns, to avoid raising a fault (#15533)
Co-authored-by: fisker <[email protected]>
1 parent 2ca5d75 commit 8e816ad

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

changelog_unreleased/cli/15533.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#### Skip explicitly passed symbolic links with `--no-error-on-unmatched-pattern` (#15533 by @sanmai-NL)
2+
3+
Since Prettier v3, we stopped following symbolic links, however in some use cases, the symbolic link patterns can't be filtered out, and there is no way to prevent Prettier from throwing errors.
4+
5+
In Prettier main, you can use `--no-error-on-unmatched-pattern` to simply skip symbolic links.

src/cli/expand-patterns.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,15 @@ async function* expandPatternsInternal(context) {
6969
const stat = await lstatSafe(absolutePath);
7070
if (stat) {
7171
if (stat.isSymbolicLink()) {
72-
yield {
73-
error: `Explicitly specified pattern "${pattern}" is a symbolic link.`,
74-
};
72+
if (context.argv.errorOnUnmatchedPattern !== false) {
73+
yield {
74+
error: `Explicitly specified pattern "${pattern}" is a symbolic link.`,
75+
};
76+
} else {
77+
context.logger.debug(
78+
`Skipping pattern "${pattern}", as it is a symbolic link.`,
79+
);
80+
}
7581
} else if (stat.isFile()) {
7682
entries.push({
7783
type: "file",

tests/integration/__tests__/patterns-dirs.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,25 @@ function isSymlinkSupported() {
321321
{ stdout: "test-a/symlink-to-directory-b/b.js" },
322322
base,
323323
);
324+
325+
testPatterns(
326+
"",
327+
[
328+
"test-a/symlink-to-file-b",
329+
"--no-error-on-unmatched-pattern",
330+
"--log-level",
331+
"debug",
332+
],
333+
{
334+
status: 0,
335+
stdout: "",
336+
stderr:
337+
'[debug] normalized argv: {"":["test-a/symlink-to-file-b"],"cache":false,"color":true,"editorconfig":true,"errorOnUnmatchedPattern":false,"logLevel":"debug","ignorePath":[".prettierignore"],"configPrecedence":"cli-override","debugRepeat":0,"plugins":[],"listDifferent":true,"_":["test-a/symlink-to-file-b"],"__raw":{"_":["test-a/symlink-to-file-b"],"cache":false,"color":true,"editorconfig":true,"error-on-unmatched-pattern":false,"l":true,"log-level":"debug","ignore-path":".prettierignore","config-precedence":"cli-override","debug-repeat":0,"plugin":[]}}' +
338+
"\n" +
339+
'[debug] Skipping pattern "test-a/symlink-to-file-b", as it is a symbolic link.',
340+
},
341+
base,
342+
);
324343
});
325344

326345
function testPatterns(

0 commit comments

Comments
 (0)