Repository: prettier/prettier (JavaScript) — Bug Fix

Issue:
Ignored files are written to stdout during --debug-check
Prettier 1.11.0 outputs the source of ignored files to stdout when running with --debug-check.

Reproduce by creating the following three files:

foo.js
`console.log("foo");`

bar.js
`console.log("bar");`

.prettierignore
`bar.js`

Then run prettier:
`prettier.js --debug-check "**/*.js"`

It will output the source of bar.js, instead of ignoring it.

It seems to be caused by:
https://github.com/prettier/prettier/blob/2cb9498ab67615f67ba5b431198d0f434f4ab282/src/cli/util.js#L338-L341
introduced in https://github.com/prettier/prettier/commit/2cb9498ab67615f67ba5b431198d0f434f4ab282


Discussion:
This is the intended behaviour as per #3590. So maybe we should detect if it was passed a glob or a specific filename?

- if passed a glob, ignore the ignored files
- if passed specific filename, write the contents unchanged to output

I don't really know what should be the behavior here, this seems a little confusing to me :P
I agree that it is the intended behavior in regular usage, but **not** when running --debug-check.
#3590 mentions these two cases:

```
With --write, don't read or write to the ignored file
Without --write, read the ignored file and output as-is.
```

I'd argue there are three cases to take into account:
```
With --write, don't read or write to the ignored file
With --debug-check, don't check the ignored file
Without --write and --debug-check, read the ignored file and output as-is.
```

Yeah, I agree

Resolving patch:
diff --git a/src/cli/util.js b/src/cli/util.js
index 4ec80b646992..15f86b3da0e4 100644
--- a/src/cli/util.js
+++ b/src/cli/util.js
@@ -339,7 +339,9 @@ function formatFiles(context) {
     const fileIgnored = ignorer.filter([filename]).length === 0;
     if (
       fileIgnored &&
-      (context.argv["write"] || context.argv["list-different"])
+      (context.argv["debug-check"] ||
+        context.argv["write"] ||
+        context.argv["list-different"])
     ) {
       return;
     }


Test patch:
diff --git a/tests_integration/__tests__/__snapshots__/ignore-path.js.snap b/tests_integration/__tests__/__snapshots__/ignore-path.js.snap
index 11e9966c1696..b748a30d98ae 100644
--- a/tests_integration/__tests__/__snapshots__/ignore-path.js.snap
+++ b/tests_integration/__tests__/__snapshots__/ignore-path.js.snap
@@ -1,5 +1,14 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
+exports[`ignore file when using --debug-check (stderr) 1`] = `""`;
+
+exports[`ignore file when using --debug-check (stdout) 1`] = `
+"other-regular-modules.js
+"
+`;
+
+exports[`ignore file when using --debug-check (write) 1`] = `Array []`;
+
 exports[`ignore path (stderr) 1`] = `""`;
 
 exports[`ignore path (stdout) 1`] = `
diff --git a/tests_integration/__tests__/ignore-path.js b/tests_integration/__tests__/ignore-path.js
index ce5d1aa2c41e..b4afa66e2c3c 100644
--- a/tests_integration/__tests__/ignore-path.js
+++ b/tests_integration/__tests__/ignore-path.js
@@ -19,6 +19,12 @@ describe("support .prettierignore", () => {
   });
 });
 
+describe("ignore file when using --debug-check", () => {
+  runPrettier("cli/ignore-path", ["**/*.js", "--debug-check"]).test({
+    status: 0
+  });
+});
+
 describe("outputs files as-is if no --write", () => {
   runPrettier("cli/ignore-path", ["regular-module.js"]).test({
     status: 0