Skip to content

Commit

Permalink
Also infer parser when using --list-different (prettier#1997)
Browse files Browse the repository at this point in the history
* Also infer parser when using `--list-different`

* Add integration tests for parser inference
  • Loading branch information
philipp-spiess authored and vjeux committed Jun 6, 2017
1 parent df7311a commit d679f23
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bin/prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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`] = `""`;
18 changes: 18 additions & 0 deletions tests_integration/__tests__/with-parser-inference.js
Original file line number Diff line number Diff line change
@@ -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();
});
2 changes: 2 additions & 0 deletions tests_integration/cli/with-parser-inference/javascript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* JavaScript */
"use strict";
4 changes: 4 additions & 0 deletions tests_integration/cli/with-parser-inference/stylesheet.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Stylesheet */
* {
outline: none;
}

0 comments on commit d679f23

Please sign in to comment.