Spring Boot + npm + Geb で入力フォームを作ってテストする ( その69 )( 再び eslint-config-airbnb-base をインストールする )
概要
記事一覧はこちらです。
Spring Boot + npm + Geb で入力フォームを作ってテストする ( その68 )( Spring Boot を 1.5.10 → 1.5.14 へバージョンアップする ) の続きです。
- 今回の手順で確認できるのは以下の内容です。
- Prettier をインストールした時に ESLint の rule を Prettier のもののみに変更したのですが、それだとフォーマットの rule しかチェックされないことに気づいたので、eslint-config-airbnb-base をインストールし直します。
参照したサイト・書籍
目次
手順
動作確認1
Spring Boot + npm + Geb で入力フォームを作ってテストする ( その67 )( Prettier のインストール+Jest Each を試してみる ) で .eslintrc.js を以下の内容に変更しましたが、
module.exports = { "extends": "plugin:prettier/recommended" };
Prettier はフォーマットしか見ないはずなので、これだと eslint-config-airbnb-base を入れていたことで検知できていたフォーマット以外の問題点が検知できなくなっている気がするんですよね。。。 ということで、試してみます。
まずは src/main/assets/js/lib/util/validator.js の checkRequired 関数を以下のように修正します。
checkRequired: function(form, idFormGroup, idList, errmsg) { if (this.ignoreCheckRequired === true) return; var a = "1" console.log("test"); this.forceCheckRequired(form, idFormGroup, idList, errmsg); },
eslint-config-airbnb-base を入れていた時は以下の問題点が指摘されたはずですが、
- 変数 a が定義されているが未使用。
var a = "1"
の最後に;
がない。console.log
が記述されている。
npm run build
コマンドを実行してみると、指摘されたのは ;
がないの1点だけでした。
やっぱり懸念した通りでした。。。 eslint-config-airbnb-base をインストールして設定し直すことにします。
再び eslint-config-airbnb-base をインストールする
npm install --save-dev eslint-config-airbnb-base
コマンドを実行してインストールします。
.eslintrc.js を変更する
.eslintrc.js を変更します。フォーマットは Prettier に任せるのは変わらないので、以前 eslint-config-airbnb-base を導入した時に書いていた rule からフォーマット関連の rule は削除します。
module.exports = { extends: ["airbnb-base/legacy", "plugin:prettier/recommended"], env: { jquery: true }, rules: { // requires to declare all vars on top of their containing scope "vars-on-top": "off", // require function expressions to have a name // http://eslint.org/docs/rules/func-names "func-names": "off", // disallow mixed 'LF' and 'CRLF' as linebreaks // http://eslint.org/docs/rules/linebreak-style "linebreak-style": ["error", "windows"], // specify whether double or single quotes should be used quotes: ["error", "double", { avoidEscape: true }], // disallow use of variables before they are defined "no-use-before-define": [ "error", { functions: false, classes: true, variables: true } ] } };
動作確認2
npm run build
コマンドを実行してみると、今度は3点とも指摘されるようになりました。
src/main/assets/js/lib/util/validator.js を元に戻して、再び npm run build
コマンドを実行してみます。
今度はエラーなしに終了しました。
履歴
2018/07/16
初版発行。