Skip to content

Commit

Permalink
feat(prettier): add JSON support (#240)
Browse files Browse the repository at this point in the history
Prettier supports JSON officially. See <https://prettier.io/>.
  • Loading branch information
ybiquitous committed Aug 11, 2018
1 parent 461f7d1 commit c5eb5fa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"markdownlint",
"git add"
],
"*.{yml,yaml}": [
"*.{yml,yaml,json}": [
"prettier --write",
"git add"
]
Expand Down
20 changes: 4 additions & 16 deletions test/fixtures/package-empty_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,10 @@
},
"lint-staged": {
"linters": {
"*.{js,jsx,mjs}": [
"eslint --fix --no-ignore",
"git add"
],
"*.md": [
"prettier --write",
"markdownlint",
"git add"
],
"*.{yml,yaml}": [
"prettier --write",
"git add"
]
"*.{js,jsx,mjs}": ["eslint --fix --no-ignore", "git add"],
"*.md": ["prettier --write", "markdownlint", "git add"],
"*.{yml,yaml,json}": ["prettier --write", "git add"]
},
"ignore": [
"CHANGELOG.md"
]
"ignore": ["CHANGELOG.md"]
}
}
20 changes: 4 additions & 16 deletions test/fixtures/package-normal_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,10 @@
"lint-staged": {
"*.css": "xyz",
"linters": {
"*.{js,jsx,mjs}": [
"eslint --fix --no-ignore",
"git add"
],
"*.md": [
"prettier --write",
"markdownlint",
"git add"
],
"*.{yml,yaml}": [
"prettier --write",
"git add"
]
"*.{js,jsx,mjs}": ["eslint --fix --no-ignore", "git add"],
"*.md": ["prettier --write", "markdownlint", "git add"],
"*.{yml,yaml,json}": ["prettier --write", "git add"]
},
"ignore": [
"CHANGELOG.md"
]
"ignore": ["CHANGELOG.md"]
}
}
14 changes: 8 additions & 6 deletions test/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const init = require("../lib/init");
const exec = require("./helpers/exec");

const readFile = file => fs.readFile(file, "utf8");
const readJSON = file => fs.readJSON(file, "utf8");

const sandbox = async (fn, t) => {
const workDir = path.join(os.tmpdir(), `${pkg.name}${Date.now()}`);
Expand All @@ -29,6 +30,7 @@ const sandbox = async (fn, t) => {
fixturePath,
fixture,
readFixture: name => readFile(fixturePath(name)),
readFixtureJSON: name => readJSON(fixturePath(name)),
readOrigFile: name => readFile(path.join(cwd, name)),
readWorkFile: name => readFile(path.join(workDir, name)),
logMessage: () => logMsgs.join(""),
Expand All @@ -47,18 +49,18 @@ test("init", t => {
testInSandbox('update "package.json"', async (t, ctx) => {
const src = await ctx.fixture("package-normal.json");
await init(ctx.initArgs);
const actual = await readFile(src);
const expected = await ctx.readFixture("package-normal_expected.json");
t.is(actual, expected);
const actual = await readJSON(src);
const expected = await ctx.readFixtureJSON("package-normal_expected.json");
t.deepEqual(actual, expected);
t.end();
});

testInSandbox('update "package.json" without fields', async (t, ctx) => {
const src = await ctx.fixture("package-empty.json");
await init(ctx.initArgs);
const actual = await readFile(src);
const expected = await ctx.readFixture("package-empty_expected.json");
t.is(actual, expected);
const actual = await readJSON(src);
const expected = await ctx.readFixtureJSON("package-empty_expected.json");
t.deepEqual(actual, expected);
t.end();
});

Expand Down

0 comments on commit c5eb5fa

Please sign in to comment.