From c5eb5fa0d88bf957733a7aee286a69255e72f4a0 Mon Sep 17 00:00:00 2001 From: Masafumi Koba Date: Sun, 12 Aug 2018 01:53:34 +0900 Subject: [PATCH] feat(prettier): add JSON support (#240) Prettier supports JSON officially. See . --- package.json | 2 +- test/fixtures/package-empty_expected.json | 20 ++++---------------- test/fixtures/package-normal_expected.json | 20 ++++---------------- test/init.test.js | 14 ++++++++------ 4 files changed, 17 insertions(+), 39 deletions(-) diff --git a/package.json b/package.json index 2570b18c..c446e235 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "markdownlint", "git add" ], - "*.{yml,yaml}": [ + "*.{yml,yaml,json}": [ "prettier --write", "git add" ] diff --git a/test/fixtures/package-empty_expected.json b/test/fixtures/package-empty_expected.json index 10cde1a0..9b492dfe 100644 --- a/test/fixtures/package-empty_expected.json +++ b/test/fixtures/package-empty_expected.json @@ -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"] } } diff --git a/test/fixtures/package-normal_expected.json b/test/fixtures/package-normal_expected.json index 88339af6..db70ed5f 100644 --- a/test/fixtures/package-normal_expected.json +++ b/test/fixtures/package-normal_expected.json @@ -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"] } } diff --git a/test/init.test.js b/test/init.test.js index 9a7f63df..9725689b 100644 --- a/test/init.test.js +++ b/test/init.test.js @@ -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()}`); @@ -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(""), @@ -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(); });