LoginSignup
2
3

More than 5 years have passed since last update.

EsLintをNodeJSに導入してコミット時に構文チェックをする

Last updated at Posted at 2017-05-01

1.NPMインストール

1.1 huskey

コミット時に何かをトリガーする

 npm uninstall ghooks --save-dev && npm install husky --save-dev

1.2 eslint

構文チェック

 npm install -g eslint --save-dev
 eslint init
    >? How would you like to configure ESLint? Inspect your JavaScript file(s)
    >? Which file(s), path(s), or glob(s) should be examined? ./src/assets/js/
    >? What format do you want your config file to be in? JavaScript
    >? Are you using ECMAScript 6 features? No
    >? Where will your code run? Browser
    >? Do you use CommonJS? Yes
    >? Do you use JSX? No

2.package.jsonでスクリプトの呼び出し設定

  "scripts": {
    "precommit": "npm run test.sh -q || eslint ./src/assets/js/"
  }

3.確認

eslint ./src/assets/js/
npm run precommit
npm run eslint

4. gitコミット時にエラーを確認

git commit
>......
>✖ 1733 problems (1733 errors, 0 warnings)
>
>
> husky - pre-commit hook failed (add --no-verify to bypass)
> husky - to debug, use 'npm run precommit'

5.rails + yarn + VueJS版

yarn add eslint
yarn add eslint-config-vue
yarn add ghooks
yarn add husky
 "scripts": {
    "precommit": "npm run test.sh -q || eslint ./src/assets/js/"
  }
yarn run precommit

package.jsonに記載したprecommitが動いている事を確認

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3