Allow skipping symlink patterns, to avoid raising a fault (#15533)
Co-authored-by: fisker <lionkay@gmail.com>
This commit is contained in:
1 parent
2ca5d757b7
commit
8e816ade2e
3 files changed
+33
-3
No files matched your search
@@ -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.
|
||||||
@@ -69,9 +69,15 @@ async function* expandPatternsInternal(context) {
|
|||||||
const stat = await lstatSafe(absolutePath);
|
const stat = await lstatSafe(absolutePath);
|
||||||
if (stat) {
|
if (stat) {
|
||||||
if (stat.isSymbolicLink()) {
|
if (stat.isSymbolicLink()) {
|
||||||
yield {
|
if (context.argv.errorOnUnmatchedPattern !== false) {
|
||||||
error: `Explicitly specified pattern "${pattern}" is a symbolic link.`,
|
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()) {
|
} else if (stat.isFile()) {
|
||||||
entries.push({
|
entries.push({
|
||||||
type: "file",
|
type: "file",
|
||||||
|
|||||||
@@ -321,6 +321,25 @@ function isSymlinkSupported() {
|
|||||||
{ stdout: "test-a/symlink-to-directory-b/b.js" },
|
{ stdout: "test-a/symlink-to-directory-b/b.js" },
|
||||||
base,
|
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(
|
function testPatterns(
|
||||||
|
|||||||
Reference in new issue
Block a user