diff --git a/commitlint.config.js b/commitlint.config.js index c3556951..e3da0e30 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -2,16 +2,20 @@ module.exports = { extends: ['@commitlint/config-conventional'], rules: { - 'scope-enum': [2, 'always', [ - '', - 'package', - 'readme', - 'eslint', - 'commitlint', - 'coverage', - 'release', - 'init', - 'api', - ]], + 'scope-enum': [ + 2, + 'always', + [ + '', + 'package', + 'readme', + 'eslint', + 'commitlint', + 'coverage', + 'release', + 'init', + 'api', + ], + ], }, } diff --git a/package.json b/package.json index 105ea882..e4cb5f81 100644 --- a/package.json +++ b/package.json @@ -33,13 +33,14 @@ "@commitlint/cli": "^5.2.0", "@commitlint/config-conventional": "^5.1.3", "eslint": "^4.12.1", - "eslint-config-ybiquitous": "^3.0.1", + "eslint-config-ybiquitous": "^4.0.0", "fs-extra": "^4.0.2", "husky": "^0.14.3", "lint-staged": "^6.0.0", "markdownlint-cli": "^0.5.0", "npm-run-all": "^4.1.2", "prepend-file-cli": "^1.0.6", + "prettier": "^1.8.2", "semver": "^5.4.1", "standard-version": "^4.2.0", "yargs": "^10.0.3" diff --git a/src/cli.js b/src/cli.js index 1ce6a7d1..cae6fa15 100644 --- a/src/cli.js +++ b/src/cli.js @@ -1,7 +1,7 @@ const yargs = require('yargs') const init = require('./init') -process.on('unhandledRejection', (reason) => { +process.on('unhandledRejection', reason => { process.stderr.write(reason.stack) process.exit(1) }) @@ -14,6 +14,5 @@ module.exports = function cli() { .demandCommand(1) .strict() .alias('help', 'h') - .alias('version', 'v') - .argv + .alias('version', 'v').argv } diff --git a/src/init.js b/src/init.js index a93eded7..7815fcf1 100644 --- a/src/init.js +++ b/src/init.js @@ -42,13 +42,13 @@ class Init { }) Object.keys(originalPackage.scripts) .filter(key => !(key === 'test' || key.startsWith('test:'))) - .forEach((key) => { + .forEach(key => { scripts[key] = originalPackage.scripts[key] }) // update other keys const keys = ['lint-staged', 'standard-version'] - keys.forEach((key) => { + keys.forEach(key => { if (!(key in packageInfo)) { packageInfo[key] = {} } @@ -66,16 +66,22 @@ class Init { } async writeESLintConfig() { - await this.writeFile('.eslintrc.js', `module.exports = { + await this.writeFile( + '.eslintrc.js', + `module.exports = { root: true, extends: ['ybiquitous'], -}`) +}`, + ) } async writeCommitlintConfig() { - await this.writeFile('commitlint.config.js', `module.exports = { + await this.writeFile( + 'commitlint.config.js', + `module.exports = { extends: ['@commitlint/config-angular'], -}`) +}`, + ) } } diff --git a/test/help.test.js b/test/help.test.js index 93c6bb7a..8dc188a9 100644 --- a/test/help.test.js +++ b/test/help.test.js @@ -17,11 +17,7 @@ Options: `.trim() suite('help', () => { - [ - [], - ['unknown'], - ['unknown', 'xyz'], - ].forEach((args) => { + ;[[], ['unknown'], ['unknown', 'xyz']].forEach(args => { test(`with arguments [${args.join(', ')}]`, async () => { const error = await assertThrows(() => exec(...args)) const { code, stdout, stderr } = error @@ -30,9 +26,8 @@ suite('help', () => { assert(stdout === '') assert(stderr.includes(HELP), stderr) }) - }); - - ['--help', '-h'].forEach((option) => { + }) + ;['--help', '-h'].forEach(option => { test(`with "${option}" option`, async () => { const { stdout, stderr } = await exec(option) assert(stdout.includes(HELP), stdout) diff --git a/test/helpers/index.js b/test/helpers/index.js index e4095249..2be1d2f8 100644 --- a/test/helpers/index.js +++ b/test/helpers/index.js @@ -1,7 +1,4 @@ import assertThrows from './assert-throws' import exec from './exec' -export { - assertThrows, - exec, -} +export { assertThrows, exec } diff --git a/test/init.test.js b/test/init.test.js index 4ab874ea..054e1885 100644 --- a/test/init.test.js +++ b/test/init.test.js @@ -51,10 +51,7 @@ suite('init', () => { }) assert.deepStrictEqual(pkg['lint-staged'], { - '*.{js,jsx}': [ - 'eslint --fix --no-ignore', - 'git add', - ], + '*.{js,jsx}': ['eslint --fix --no-ignore', 'git add'], '*.md': 'markdownlint', '*.css': 'xyz', }) @@ -79,7 +76,10 @@ suite('init', () => { test('copy ".editorconfig"', async () => { await exec('init') - const original = await fs.readFile(path.join(originalDir, '.editorconfig'), 'utf8') + const original = await fs.readFile( + path.join(originalDir, '.editorconfig'), + 'utf8', + ) const copy = await fs.readFile(path.join(workDir, '.editorconfig'), 'utf8') assert(original === copy) }) @@ -88,21 +88,30 @@ suite('init', () => { await exec('init') const wrote = await fs.readFile(path.join(workDir, '.eslintrc.js'), 'utf8') - assert(wrote === `module.exports = { + assert( + wrote === + `module.exports = { root: true, extends: ['ybiquitous'], } -`) +`, + ) }) test('write "commitlint.config.js"', async () => { await exec('init') - const wrote = await fs.readFile(path.join(workDir, 'commitlint.config.js'), 'utf8') - assert(wrote === `module.exports = { + const wrote = await fs.readFile( + path.join(workDir, 'commitlint.config.js'), + 'utf8', + ) + assert( + wrote === + `module.exports = { extends: ['@commitlint/config-angular'], } -`) +`, + ) }) test('throw error', async () => { diff --git a/test/version.test.js b/test/version.test.js index 1f79dc47..f8f018a9 100644 --- a/test/version.test.js +++ b/test/version.test.js @@ -2,9 +2,8 @@ import assert from 'assert' import { exec } from './helpers' suite('version', () => { - const version = process.env.npm_package_version; - - ['--version', '-v'].forEach((option) => { + const version = process.env.npm_package_version + ;['--version', '-v'].forEach(option => { test(`with "${option}" option`, async () => { const { stdout, stderr } = await exec(option) assert(stdout.trim() === version) diff --git a/yarn.lock b/yarn.lock index 520e89e0..83c727f4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1468,15 +1468,23 @@ eslint-config-airbnb@^16.0.0: dependencies: eslint-config-airbnb-base "^12.1.0" -eslint-config-ybiquitous@^3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/eslint-config-ybiquitous/-/eslint-config-ybiquitous-3.0.1.tgz#a326942998bbf1d2fe53d7ddaa6949ff6cbb6970" +eslint-config-prettier@^2.9.0: + version "2.9.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-2.9.0.tgz#5ecd65174d486c22dff389fe036febf502d468a3" + dependencies: + get-stdin "^5.0.1" + +eslint-config-ybiquitous@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/eslint-config-ybiquitous/-/eslint-config-ybiquitous-4.0.0.tgz#d55c93bd91ce87ceaed4b12f1bd30dbe7444f1ab" dependencies: eslint-config-airbnb "^16.0.0" + eslint-config-prettier "^2.9.0" eslint-plugin-compat "^2.0.1" eslint-plugin-eslint-comments "^2.0.1" eslint-plugin-import "^2.7.0" eslint-plugin-jsx-a11y "^6.0.2" + eslint-plugin-prettier "^2.3.1" eslint-plugin-react "^7.4.0" eslint-import-resolver-node@^0.3.1: @@ -1536,6 +1544,13 @@ eslint-plugin-jsx-a11y@^6.0.2: emoji-regex "^6.1.0" jsx-ast-utils "^1.4.0" +eslint-plugin-prettier@^2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-2.3.1.tgz#e7a746c67e716f335274b88295a9ead9f544e44d" + dependencies: + fast-diff "^1.1.1" + jest-docblock "^21.0.0" + eslint-plugin-react@^7.4.0: version "7.5.1" resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.5.1.tgz#52e56e8d80c810de158859ef07b880d2f56ee30b" @@ -1712,6 +1727,10 @@ fast-deep-equal@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz#96256a3bc975595eb36d82e9929d060d893439ff" +fast-diff@^1.1.1: + version "1.1.2" + resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.1.2.tgz#4b62c42b8e03de3f848460b639079920695d0154" + fast-json-stable-stringify@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2" @@ -1922,7 +1941,7 @@ get-pkg-repo@^1.0.0: parse-github-repo-url "^1.3.0" through2 "^2.0.0" -get-stdin@5.0.1: +get-stdin@5.0.1, get-stdin@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-5.0.1.tgz#122e161591e21ff4c52530305693f20e6393a398" @@ -2449,6 +2468,10 @@ istanbul-reports@^1.1.3: dependencies: handlebars "^4.0.3" +jest-docblock@^21.0.0: + version "21.2.0" + resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-21.2.0.tgz#51529c3b30d5fd159da60c27ceedc195faf8d414" + jest-get-type@^21.2.0: version "21.2.0" resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-21.2.0.tgz#f6376ab9db4b60d81e39f30749c6c466f40d4a23" @@ -3323,6 +3346,10 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" +prettier@^1.8.2: + version "1.8.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.8.2.tgz#bff83e7fd573933c607875e5ba3abbdffb96aeb8" + pretty-format@^21.2.1: version "21.2.1" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-21.2.1.tgz#ae5407f3cf21066cd011aa1ba5fce7b6a2eddb36"