diff --git a/src/cli/util.js b/src/cli/util.js index 497f35b932bf..b5ffadfdca35 100644 --- a/src/cli/util.js +++ b/src/cli/util.js @@ -399,10 +399,12 @@ function createIgnorerFromContextOrDie(context) { } function eachFilename(context, patterns, callback) { + // The '!./' globs are due to https://github.com/prettier/prettier/issues/2110 const ignoreNodeModules = context.argv["with-node-modules"] !== true; if (ignoreNodeModules) { patterns = patterns.concat(["!**/node_modules/**", "!./node_modules/**"]); } + patterns = patterns.concat(["!**/.{git,svn,hg}/**", "!./.{git,svn,hg}/**"]); try { const filePaths = globby diff --git a/tests_integration/__tests__/__snapshots__/ignore-vcs-files.js.snap b/tests_integration/__tests__/__snapshots__/ignore-vcs-files.js.snap new file mode 100644 index 000000000000..c265128e8874 --- /dev/null +++ b/tests_integration/__tests__/__snapshots__/ignore-vcs-files.js.snap @@ -0,0 +1,10 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ignores files in version control systems (stderr) 1`] = `""`; + +exports[`ignores files in version control systems (stdout) 1`] = ` +"file.js +" +`; + +exports[`ignores files in version control systems (write) 1`] = `Array []`; diff --git a/tests_integration/__tests__/__snapshots__/multiple-patterns.js.snap b/tests_integration/__tests__/__snapshots__/multiple-patterns.js.snap index b790ddec7a1b..9f984bcc18a9 100644 --- a/tests_integration/__tests__/__snapshots__/multiple-patterns.js.snap +++ b/tests_integration/__tests__/__snapshots__/multiple-patterns.js.snap @@ -72,7 +72,7 @@ directory/nested-directory/nested-directory-file.js exports[`multiple patterns with non exists pattern (write) 1`] = `Array []`; exports[`multiple patterns, throw error and exit with non zero code on non existing files (stderr) 1`] = ` -"[error] No matching files. Patterns tried: non-existent.js other-non-existent.js !**/node_modules/** !./node_modules/** +"[error] No matching files. Patterns tried: non-existent.js other-non-existent.js !**/node_modules/** !./node_modules/** !**/.{git,svn,hg}/** !./.{git,svn,hg}/** " `; diff --git a/tests_integration/__tests__/ignore-vcs-files.js b/tests_integration/__tests__/ignore-vcs-files.js new file mode 100644 index 000000000000..0bb13ce3f4f2 --- /dev/null +++ b/tests_integration/__tests__/ignore-vcs-files.js @@ -0,0 +1,16 @@ +"use strict"; + +const runPrettier = require("../runPrettier"); + +expect.addSnapshotSerializer(require("../path-serializer")); + +describe("ignores files in version control systems", () => { + runPrettier("cli/ignore-vcs-files", [ + ".svn/file.js", + ".hg/file.js", + "file.js", + "-l" + ]).test({ + status: 1 + }); +}); diff --git a/tests_integration/cli/ignore-vcs-files/.hg/file.js b/tests_integration/cli/ignore-vcs-files/.hg/file.js new file mode 100644 index 000000000000..ad9a93a7c160 --- /dev/null +++ b/tests_integration/cli/ignore-vcs-files/.hg/file.js @@ -0,0 +1 @@ +'use strict'; diff --git a/tests_integration/cli/ignore-vcs-files/.svn/file.js b/tests_integration/cli/ignore-vcs-files/.svn/file.js new file mode 100644 index 000000000000..3d0ca1bd1785 --- /dev/null +++ b/tests_integration/cli/ignore-vcs-files/.svn/file.js @@ -0,0 +1,2 @@ +/* eslint-disable */ +'use strict'; diff --git a/tests_integration/cli/ignore-vcs-files/file.js b/tests_integration/cli/ignore-vcs-files/file.js new file mode 100644 index 000000000000..ad9a93a7c160 --- /dev/null +++ b/tests_integration/cli/ignore-vcs-files/file.js @@ -0,0 +1 @@ +'use strict';