From 21f913cb6e95ace274e189e5a4ac80cbe37a8be0 Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Sun, 18 Jun 2017 14:35:42 +1000 Subject: [PATCH] CLI: ignore node_modules with ./**-style glob, fixes #2110 (#2185) --- bin/prettier.js | 2 +- .../__tests__/__snapshots__/with-node-modules.js.snap | 6 ++++++ tests_integration/__tests__/with-node-modules.js | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bin/prettier.js b/bin/prettier.js index ddf42c17f..0648180be 100755 --- a/bin/prettier.js +++ b/bin/prettier.js @@ -70,7 +70,7 @@ const write = argv["write"]; const stdin = argv["stdin"] || (!filepatterns.length && !process.stdin.isTTY); const ignoreNodeModules = argv["with-node-modules"] === false; const globOptions = { - ignore: ignoreNodeModules && "**/node_modules/**", + ignore: ignoreNodeModules && ["**/node_modules/**", "./node_modules/**"], dot: true }; diff --git a/tests_integration/__tests__/__snapshots__/with-node-modules.js.snap b/tests_integration/__tests__/__snapshots__/with-node-modules.js.snap index 5fb7217a7..9bb5c7f59 100644 --- a/tests_integration/__tests__/__snapshots__/with-node-modules.js.snap +++ b/tests_integration/__tests__/__snapshots__/with-node-modules.js.snap @@ -25,3 +25,9 @@ exports[`ignores node_modules by default for file list 1`] = ` regular-module.js " `; + +exports[`ignores node_modules by with ./**/*.js 1`] = ` +"./not_node_modules/file.js +./regular-module.js +" +`; diff --git a/tests_integration/__tests__/with-node-modules.js b/tests_integration/__tests__/with-node-modules.js index 32bc3c567..492e28c98 100644 --- a/tests_integration/__tests__/with-node-modules.js +++ b/tests_integration/__tests__/with-node-modules.js @@ -9,6 +9,13 @@ test("ignores node_modules by default", () => { expect(result.status).toEqual(1); }); +test("ignores node_modules by with ./**/*.js", () => { + const result = runPrettier("cli/with-node-modules", ["./**/*.js", "-l"]); + + expect(result.stdout).toMatchSnapshot(); + expect(result.status).toEqual(1); +}); + test("doesn't ignore node_modules with --with-node-modules flag", () => { const result = runPrettier("cli/with-node-modules", [ "**/*.js",