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

Allow skipping symlink patterns, to avoid raising a fault #15533

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 follow symbolic links, however in some use cases, the symbolic link patterns can't be filter out, and there is no way to prevent prettier throw errors.
fisker marked this conversation as resolved.
Show resolved Hide resolved

In Prettier main, you can use `--no-error-on-unmatched-pattern` to simply skip it.
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 points to 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 points to a symbolic link.',
},
base,
);
});

function testPatterns(
Expand Down