From 8e816ade2ebd8b9e3d6bc464916747899535f7de Mon Sep 17 00:00:00 2001 From: Sander Maijers <3374183+sanmai-NL@users.noreply.github.com> Date: Thu, 7 Dec 2023 17:54:18 +0100 Subject: [PATCH] Allow skipping symlink patterns, to avoid raising a fault (#15533) Co-authored-by: fisker --- changelog_unreleased/cli/15533.md | 5 +++++ src/cli/expand-patterns.js | 12 +++++++++--- tests/integration/__tests__/patterns-dirs.js | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 changelog_unreleased/cli/15533.md diff --git a/changelog_unreleased/cli/15533.md b/changelog_unreleased/cli/15533.md new file mode 100644 index 000000000..4af08f62b --- /dev/null +++ b/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. diff --git a/src/cli/expand-patterns.js b/src/cli/expand-patterns.js index 2b7085ddb..d0b786181 100644 --- a/src/cli/expand-patterns.js +++ b/src/cli/expand-patterns.js @@ -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", diff --git a/tests/integration/__tests__/patterns-dirs.js b/tests/integration/__tests__/patterns-dirs.js index 7963780f9..1ce748d19 100644 --- a/tests/integration/__tests__/patterns-dirs.js +++ b/tests/integration/__tests__/patterns-dirs.js @@ -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(