要在Node.js 上运行 ESLint,必须先安装 npm。
安装好npm后,可以运行下列命令:
npm i -g eslint
这表示从npm仓库安装了ESLint CLI。然后继续使用下列命令运行ESLint:
eslint [options] [file|dir|glob]*
示例:
eslint file1.js file2.js
或者:
eslint lib/**
如果想要使用 node 的 glob
语法,需要给参数加上引号,在 windows 系统运行时也可以使用双引号,像下面这样:
eslint "lib/**"
命令选项
使用 ESLint 命令时,我们可以通过eslint -h
命令来查看所有的命令行选项:
eslint [options] file.js [file.js] [dir]
Basic configuration:
--no-eslintrc Disable use of configuration from .eslintrc.*
-c, --config path::String Use this configuration, overriding .eslintrc.* config
options if present
--env [String] Specify environments
--ext [String] Specify JavaScript file extensions - default: .js
--global [String] Define global variables
--parser String Specify the parser to be used
--parser-options Object Specify parser options
--resolve-plugins-relative-to path::String A folder where plugins should be resolved
from, CWD by default
Specifying rules and plugins:
--rulesdir [path::String] Use additiona