ESLint を試してみる
今度は、JavaScript の文法チェックを試してみたいと思います。
インストール
Raspberry Pi OS の node では、バージョン 7以降の eslint は動かないようなので、バージョンを指定してインストールします。
$ sudo mkdir /opt/eslint $ cd /opt/eslint $ sudo npm install --save-dev eslint@6.8.0 $ sudo cp package-lock.json package.json $ sudo npx eslint --init ? How would you like to use ESLint? To check syntax and find problems ? What type of modules does your project use? None of these ? Which framework does your project use? None of these ? Does your project use TypeScript? No ? Where does your code run? Browser ? What format do you want your config file to be in? JSON Local ESLint installation not found. The config that you've selected requires the following dependencies: eslint@latest ? Would you like to install them now with npm? No Successfully created .eslintrc.json file in /opt/eslint ESLint was installed locally. We recommend using this local copy instead of your globally-installed copy.
init する際、package.json ファイルがないと init できないようなので、package-lock.json をコピーします。また、init の途中で最新版の eslint をインストールするか聞いてきますが、インストールしません。
JavaScript をチェックしてみると、インストールしたディレクトリにあるファイルしかチェックできませんでした。インストールしたディレクトリ以外のファイルをチェックするには、–config オプションで設定ファイルを指定する必要があります。
SHELL スクリプト
一応、何処で実行しても大丈夫なように SHELL スクリプトを作ります。
$ sudo vi /usr/local/bin/eslint
#!/bin/bash INSTALL_DIR=/opt/eslint if [ -f "${PWD}/$1" ]; then file="${PWD}/$1" else file="$1" fi cd ${INSTALL_DIR} npx eslint --config "${INSTALL_DIR}/.eslintrc.json" "${file}"
$ sudo chmod +x eslint
バージョンが古いし、あまり使わないと思います。まあ、新しい JavaSCript を書くことが有ったら、チェックして見るくらいでいいかな。
ディスカッション
コメント一覧
まだ、コメントがありません