From d679f235ed06e559346cc924b2cf3d51c7912905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Spie=C3=9F?= Date: Tue, 6 Jun 2017 17:24:56 +0200 Subject: [PATCH] Also infer parser when using `--list-different` (#1997) * Also infer parser when using `--list-different` * Add integration tests for parser inference --- bin/prettier.js | 7 ++++++- .../with-parser-inference.js.snap | 13 +++++++++++++ .../__tests__/with-parser-inference.js | 18 ++++++++++++++++++ .../cli/with-parser-inference/javascript.js | 2 ++ .../cli/with-parser-inference/stylesheet.css | 4 ++++ 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests_integration/__tests__/__snapshots__/with-parser-inference.js.snap create mode 100644 tests_integration/__tests__/with-parser-inference.js create mode 100644 tests_integration/cli/with-parser-inference/javascript.js create mode 100644 tests_integration/cli/with-parser-inference/stylesheet.css diff --git a/bin/prettier.js b/bin/prettier.js index d84e67da7..ef6dc443a 100755 --- a/bin/prettier.js +++ b/bin/prettier.js @@ -299,7 +299,12 @@ if (stdin) { } if (argv["list-different"]) { - if (!prettier.check(input, options)) { + if ( + !prettier.check( + input, + Object.assign({}, options, { filepath: filename }) + ) + ) { if (!write) { console.log(filename); } diff --git a/tests_integration/__tests__/__snapshots__/with-parser-inference.js.snap b/tests_integration/__tests__/__snapshots__/with-parser-inference.js.snap new file mode 100644 index 000000000..5117e3e09 --- /dev/null +++ b/tests_integration/__tests__/__snapshots__/with-parser-inference.js.snap @@ -0,0 +1,13 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`infers postcss parser 1`] = ` +"/* JavaScript */ +\\"use strict\\"; +/* Stylesheet */ +* { + outline: none; +} +" +`; + +exports[`infers postcss parser with --list-different 1`] = `""`; diff --git a/tests_integration/__tests__/with-parser-inference.js b/tests_integration/__tests__/with-parser-inference.js new file mode 100644 index 000000000..638483a00 --- /dev/null +++ b/tests_integration/__tests__/with-parser-inference.js @@ -0,0 +1,18 @@ +"use strict"; + +const runPrettier = require("../runPrettier"); + +test("infers postcss parser", () => { + const result = runPrettier("cli/with-parser-inference", ["*"]); + + expect(result.stdout).toMatchSnapshot(); +}); + +test("infers postcss parser with --list-different", () => { + const result = runPrettier("cli/with-parser-inference", [ + "--list-different", + "*" + ]); + + expect(result.stdout).toMatchSnapshot(); +}); diff --git a/tests_integration/cli/with-parser-inference/javascript.js b/tests_integration/cli/with-parser-inference/javascript.js new file mode 100644 index 000000000..3691e5880 --- /dev/null +++ b/tests_integration/cli/with-parser-inference/javascript.js @@ -0,0 +1,2 @@ +/* JavaScript */ +"use strict"; diff --git a/tests_integration/cli/with-parser-inference/stylesheet.css b/tests_integration/cli/with-parser-inference/stylesheet.css new file mode 100644 index 000000000..f2fd4cc95 --- /dev/null +++ b/tests_integration/cli/with-parser-inference/stylesheet.css @@ -0,0 +1,4 @@ +/* Stylesheet */ +* { + outline: none; +}