Skip to content

Commit

Permalink
feat(prettier): add Markdown support (#197)
Browse files Browse the repository at this point in the history
* Now `ybiq init` generates `.prettierignore` file
* Now `lint-staged` updates Markdown files via Prettier
  • Loading branch information
ybiquitous committed Jun 16, 2018
1 parent 49c8650 commit 38d0d9c
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
'api',
'markdownlint',
'travis',
'prettier',
],
],
},
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG.md
1 change: 1 addition & 0 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ module.exports = async function init() {
const cmd = new Init(process.cwd())
await cmd.updatePackageFile()
await cmd.writePackageFile('.editorconfig')
await cmd.writePackageFile('.prettierignore')
await cmd.writeTemplateFile('.eslintrc.js')
await cmd.writeTemplateFile('.commitlintrc.js')
}
Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"bin",
"lib",
"templates",
".editorconfig"
".editorconfig",
".prettierignore"
],
"engines": {
"node": ">=8"
Expand Down Expand Up @@ -54,6 +55,7 @@
"lint:js": "eslint --ignore-path .gitignore --ext .js,.jsx,.mjs .",
"lint:js:fix": "npm run lint:js -- --fix",
"lint:md": "markdownlint --ignore node_modules --ignore CHANGELOG.md \"**/*.md\"",
"lint:md:fix": "prettier --write \"**/*.md\"",
"lint": "npm-run-all --print-name --print-label --parallel lint:*",
"commitmsg": "commitlint -E GIT_PARAMS",
"precommit": "lint-staged",
Expand All @@ -66,7 +68,11 @@
"eslint --fix --no-ignore",
"git add"
],
"*.md": "markdownlint"
"*.md": [
"prettier --write",
"markdownlint",
"git add"
]
},
"ignore": [
"CHANGELOG.md"
Expand Down
7 changes: 6 additions & 1 deletion test/fixtures/package-empty_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"lint:js": "eslint --ignore-path .gitignore --ext .js,.jsx,.mjs .",
"lint:js:fix": "npm run lint:js -- --fix",
"lint:md": "markdownlint --ignore node_modules --ignore CHANGELOG.md \"**/*.md\"",
"lint:md:fix": "prettier --write \"**/*.md\"",
"lint": "npm-run-all --print-name --print-label --parallel lint:*",
"commitmsg": "commitlint -E GIT_PARAMS",
"precommit": "lint-staged",
Expand All @@ -18,7 +19,11 @@
"eslint --fix --no-ignore",
"git add"
],
"*.md": "markdownlint"
"*.md": [
"prettier --write",
"markdownlint",
"git add"
]
},
"ignore": [
"CHANGELOG.md"
Expand Down
7 changes: 6 additions & 1 deletion test/fixtures/package-normal_expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"test:coverage": "echo \"unsupported.\" && exit 1",
"lint:js:fix": "npm run lint:js -- --fix",
"lint:md": "markdownlint --ignore node_modules --ignore CHANGELOG.md \"**/*.md\"",
"lint:md:fix": "prettier --write \"**/*.md\"",
"lint": "npm-run-all --print-name --print-label --parallel lint:*",
"commitmsg": "commitlint -E GIT_PARAMS",
"precommit": "lint-staged",
Expand All @@ -19,7 +20,11 @@
"eslint --fix --no-ignore",
"git add"
],
"*.md": "markdownlint"
"*.md": [
"prettier --write",
"markdownlint",
"git add"
]
},
"ignore": [
"CHANGELOG.md"
Expand Down
11 changes: 11 additions & 0 deletions test/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ suite('init', () => {
assert(original === copy)
})

test('write ".prettierignore"', async () => {
await fixture('package-normal.json')
const { stdout, stderr } = await exec('init')
assert(stdout.includes('package.json was updated.'))
assert(stderr === '')

const original = await readFile(path.join(originalDir, '.prettierignore'))
const copy = await readFile(path.join(workDir, '.prettierignore'))
assert(original === copy)
})

test('write ".eslintrc.js"', async () => {
await fixture('package-normal.json')
const { stdout, stderr } = await exec('init')
Expand Down

0 comments on commit 38d0d9c

Please sign in to comment.