Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(prettier): add JSON support #240

Merged
merged 2 commits into from
Aug 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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