From 353b2ca064c943b1b0b20c3e8a6d12b7d2b12607 Mon Sep 17 00:00:00 2001 From: James Reggio Date: Tue, 18 Jun 2019 13:20:47 -0700 Subject: [PATCH] Config should not be evaluated for ignored files (#6233) Prior to this change, the CLI would resolve the config for a file before checking it against the ignored list. If the config was invalid, the CLI would report a failure. This change relocates the config-resolution phase until after the file is confirmed to not be ignored. --- src/cli/util.js | 15 ++++++--------- .../ignore-absolute-path/ignored/.prettierrc.js | 1 + .../level1/level2/.prettierrc.js | 1 + 3 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 tests_integration/cli/ignore-absolute-path/ignored/.prettierrc.js create mode 100644 tests_integration/cli/ignore-relative-path/level1/level2/.prettierrc.js diff --git a/src/cli/util.js b/src/cli/util.js index 7fb64538..592575c0 100644 --- a/src/cli/util.js +++ b/src/cli/util.js @@ -420,14 +420,7 @@ function eachFilename(context, patterns, callback) { process.exitCode = 2; return; } - filePaths.forEach(filePath => - callback( - filePath, - Object.assign(getOptionsForFile(context, filePath), { - filepath: filePath - }) - ) - ); + filePaths.forEach(filePath => callback(filePath)); } catch (error) { context.logger.error( `Unable to expand glob patterns: ${patterns.join(" ")}\n${error.message}` @@ -448,7 +441,7 @@ function formatFiles(context) { context.logger.log("Checking formatting..."); } - eachFilename(context, context.filePatterns, (filename, options) => { + eachFilename(context, context.filePatterns, filename => { const fileIgnored = ignorer.filter([filename]).length === 0; if ( fileIgnored && @@ -460,6 +453,10 @@ function formatFiles(context) { return; } + const options = Object.assign(getOptionsForFile(context, filename), { + filepath: filename + }); + if (isTTY()) { // Don't use `console.log` here since we need to replace this line. context.logger.log(filename, { newline: false }); diff --git a/tests_integration/cli/ignore-absolute-path/ignored/.prettierrc.js b/tests_integration/cli/ignore-absolute-path/ignored/.prettierrc.js new file mode 100644 index 00000000..efe59c0c --- /dev/null +++ b/tests_integration/cli/ignore-absolute-path/ignored/.prettierrc.js @@ -0,0 +1 @@ +throw Error('This config should not be evaluated since the directory is ignored'); diff --git a/tests_integration/cli/ignore-relative-path/level1/level2/.prettierrc.js b/tests_integration/cli/ignore-relative-path/level1/level2/.prettierrc.js new file mode 100644 index 00000000..efe59c0c --- /dev/null +++ b/tests_integration/cli/ignore-relative-path/level1/level2/.prettierrc.js @@ -0,0 +1 @@ +throw Error('This config should not be evaluated since the directory is ignored');