安装
npm install --save-dev eslint @eslint/create-config
初始化
npx eslint --init
检查文件
// src/index.js function foo(a, b) {return a + b;} function func() {console.log('Hello World');}
$ npx eslint src/index.js src/index.js 2:10 error 'foo' is defined but never used no-unused-vars 3:10 error 'func' is defined but never used no-unused-vars ✖ 2 problems (2 errors, 0 warnings)
可以使用/* eslint-disable */来禁用部分代码的检查
// src/index.js /* eslint-disable */ function foo(a, b) {return a + b;} /* eslint-disable */ function func() {console.log('Hello World');}