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

Co-authored-by: fisker <lionkay@gmail.com>
This commit is contained in:
Sander Maijersandfisker authored and GitHub committed 2023-12-08 01:54:18 +09:00
1 parent 2ca5d757b7
commit 8e816ade2e
3 files changed
+33 -3

No files matched your search

+5
View File
@@ -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.
+9 -3
View File
@@ -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",
@@ -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(