Respect prettierignore when executed in subdirectories (#7588)

* Respect prettierignore when executed in subdirectories

* Add ignore-in-subdirectories tests

* Add changelog entry
This commit is contained in:
Corinne Hoener authored and GitHub committed 2020-02-18 00:40:26 +02:00
1 parent f40c5e3336
commit 50e0ea91ee
9 files changed
+136 -2

No files matched your search

+11 -2
View File
@@ -362,7 +362,11 @@ function formatStdin(context) {
: process.cwd();
const ignorer = createIgnorerFromContextOrDie(context);
const relativeFilepath = path.relative(process.cwd(), filepath);
// If there's an ignore-path set, the filename must be relative to the
// ignore path, not the current working directory.
const relativeFilepath = context.argv["ignore-path"]
? path.relative(path.dirname(context.argv["ignore-path"]), filepath)
: path.relative(process.cwd(), filepath);
thirdParty
.getStream(process.stdin)
@@ -439,7 +443,12 @@ function formatFiles(context) {
}
eachFilename(context, context.filePatterns, filename => {
const fileIgnored = ignorer.filter([filename]).length === 0;
// If there's an ignore-path set, the filename must be relative to the
// ignore path, not the current working directory.
const ignoreFilename = context.argv["ignore-path"]
? path.relative(path.dirname(context.argv["ignore-path"]), filename)
: filename;
const fileIgnored = ignorer.filter([ignoreFilename]).length === 0;
if (
fileIgnored &&
(context.argv["debug-check"] ||