Skip to content

Commit

Permalink
Allow skipping symlink patterns, to avoid raising a fault (prettier#1…
Browse files Browse the repository at this point in the history
…5533)

Co-authored-by: fisker <lionkay@gmail.com>
  • Loading branch information
2 people authored and medikoo committed Feb 16, 2024
1 parent c707e25 commit eba4ec2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changelog_unreleased/cli/15533.md
@@ -0,0 +1,5 @@
#### Skip explicitly passed symbolic links with `--no-error-on-unmatched-pattern` (#15533 by @sanmai-NL)

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.

In Prettier main, you can use `--no-error-on-unmatched-pattern` to simply skip symbolic links.
12 changes: 9 additions & 3 deletions src/cli/expand-patterns.js
Expand Up @@ -69,9 +69,15 @@ async function* expandPatternsInternal(context) {
const stat = await lstatSafe(absolutePath);
if (stat) {
if (stat.isSymbolicLink()) {
yield {
error: `Explicitly specified pattern "${pattern}" is a symbolic link.`,
};
if (context.argv.errorOnUnmatchedPattern !== false) {
yield {
error: `Explicitly specified pattern "${pattern}" is a symbolic link.`,
};
} else {
context.logger.debug(
`Skipping pattern "${pattern}", as it is a symbolic link.`,
);
}
} else if (stat.isFile()) {
entries.push({
type: "file",
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/__tests__/patterns-dirs.js
Expand Up @@ -321,6 +321,25 @@ function isSymlinkSupported() {
{ stdout: "test-a/symlink-to-directory-b/b.js" },
base,
);

testPatterns(
"",
[
"test-a/symlink-to-file-b",
"--no-error-on-unmatched-pattern",
"--log-level",
"debug",
],
{
status: 0,
stdout: "",
stderr:
'[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":[]}}' +
"\n" +
'[debug] Skipping pattern "test-a/symlink-to-file-b", as it is a symbolic link.',
},
base,
);
});

function testPatterns(
Expand Down

0 comments on commit eba4ec2

Please sign in to comment.