您的位置:首页 > 其它

ESlint安装使用

2015-04-18 17:18 295 查看
1、安装node.js环境,可上网百度

2、执行 npm i -g eslint 命令安装eslint

3、安装完成后执行eslint -f junit -o D:\report.xml D:\test\code\dwzy\com.sgcc.pms.dwzy.bzzx\face

eslint的相关命令选项说明

1、-c

This option allows you to specify an alternate configuration file for ESLint (see Configuring ESLint for more). By default, ESLint uses its own configuration file located at conf/eslint.json.

Example:

eslint -c ~/my-eslint.json file.js

This example uses the configuration file at ~/my-eslint.json instead of the default.

译文:

该选项允许你修改eslint的配置选项,默认情况下,eslint使用它自带的配置文件存放在conf/eslint.json中

例如:

eslint -c ~/my-eslint.json file.js

该例子表示使用~/my-eslint.json这个文件替代默认的配置文件

2、--env

This option enables specific environments. Details about the global variables defined by each environment are available on the configuration documentation. This flag only enables environments; it does not disable environments
set in other configuration files. To specify multiple environments, separate them using commas, or use the flag multiple times.

Examples:

eslint --env browser,node file.js

eslint --env browser --env node file.js/

3、--ext

This option allows you to specify which file extensions ESLint will use when searching for JavaScript files. By default, it uses .js as the only file extension.

Examples:

# Use only .js2 extension

eslint --ext .js2

# Use both .js and .js2

eslint --ext .js --ext .js2

# Also use both .js and .js2

eslint --ext .js,.js2

译文:

该选项用于指定eslint在扫描时扫描那些后缀名的文件,默认情况下eslint只扫描.js文件

例如

# 告诉eslint只扫描后缀为.js2的文件

eslint --ext .js2

#告诉eslint只扫描后缀为.js2和.js的文件

eslint --ext .js --ext .js2

# 告诉eslint只扫描后缀为.js2和.js的文件

eslint --ext .js,.js2

4、-f, --format

This option specifies the output format for the console. Possible formats are "stylish" (the default), "compact", "checkstyle", "jslint-xml", "junit" and "tap".

Example:

eslint -f compact file.js

You can also use a custom formatter from the command line by specifying a path to the custom formatter file.

Example:

eslint -f ./customformat.js file.js

When specified, the given format is output to the console. If you'd like to save that output into a file, you can do so on the command line like so:

eslint -f compact file.js > results.txt

This saves the output into the results.txt file.

译文:

该选项用于指定输出报告的格式,eslint提供了"stylish" (默认项), "compact", "checkstyle"(checkstyle格式的xml报告), "jslint-xml"(jslint格式的xml报告), "junit" (junit格式的xml报告)

和"tap"。几种格式的报告格式.

例如:

eslint -f compact file.js

eslint支持使用自定义的报告输出格式。PS:前提是你要自己编写格式模板,可在C:\Users\Administrator\AppData\Roaming\npm\node_modules\eslint\lib\formatters目录参考模板的编写方法,个人觉得默认提供的报告模板就很好了

eslint -f ./customformat.js file.js

默认情况下, 缺陷内容会输出到控制台. 如果你想将缺陷内容输出至指定文件可按如下设置:

eslint -f compact file.js > results.txt

上述配置将会将输出内容保存至results.txt文件,PS:个人觉得-f与-o配合使用更好

5、--global

This option defines global variables so that they will not be flagged as undefined by the no-undef rule. Global variables are read-only by default, but appending :true to a variable's name makes it writable. To define multiple
variables, separate them using commas, or use the flag multiple times.

Examples:

eslint --global require,exports:true file.js

eslint --global require --global exports:true

译文:

该选项用于定义一组全局变量,被定义的全局变量将不会被no-undef规则标识出来(也就是不会被当做缺陷扫出来),全局变量默认情况下是只读的,但是在全局变量后加:true可使其变为可写状态(PS:不理解)。定义多个全局变量可使用逗号隔开也可使用标签多次

例如:

eslint --global require,exports:true file.js

eslint --global require --global exports:true

6、-h, --help

This option outputs the help menu, displaying all of the available options. All other flags are ignored when this is present.

译文:

该选项用于输出帮助菜单,展示所有可用的选项,当该选项位于其他选项之前时,其他选项将被忽略

7、--ignore-path

This option allows you to specify the file to use as your .eslintignore. By default, ESLint looks in the current working directory for .eslintignore. You can override this behavior by providing a path to a different file.

Example:

eslint --ignore-path tmp/.eslintignore file.js

8、--no-color

Disable color in piped output.

Example:

eslint --no-color file.js

译文:禁用输出内容颜色

9、--no-eslintrc

Disables use of configuration from .eslintrc and package.json files.

Example:

eslint --no-eslintrc file.js

10、--no-ignore

Disables excluding of files from .eslintignore and --ignore-path files.

Example:

eslint --no-ignore file.js

11、-o, --output-file

Enable report to be written to a file.

Example:

eslint -o ./test/test.xml

When specified, the given format is output into the provided file name.

译文:

启用报告输出至指定文件,设定之后内容将按-f指定的格式输出至test.xml文件

12、--plugin

This option specifies a plugin to load. You can omit the prefix eslint-plugin- from the plugin name. Before using the plugin you have to install it using npm.

Examples:

eslint --plugin jquery file.js

eslint --plugin eslint-plugin-mocha file.js

13、--quiet

This option allows you to disable reporting on warnings. If you enable this option only errors are reported by ESLint.

Example:

eslint --quiet file.js

译文:该选项允许你禁用警告,如果启用了该项,只有eslint只将错误报告出来,将会隐藏警告

14、--reset

This option turns off all rules enabled in ESLint's default configuration file located at conf/eslint.json. ESLint will still report syntax errors.

Example:

eslint --reset file.js

译文:

该选项将会关闭所有eslint默认配置文件中的规则,但是依然会将有语法错的问题输出

15、--rule

This option specifies rules to be used. They will be merged into any previously defined rules. To start fresh, simply combine with the --reset flag. To define multiple rules, separate them using commas, or use the flag multiple
times. The levn format is used for specifying the rules. If the rule is defined within a plugin you have to prefix the rule ID with the plugin name and a /.

Examples:

eslint --rule 'quotes: [2, double]'

eslint --rule 'guard-for-in: 2' --rule 'brace-style: [2, 1tbs]'

eslint --rule 'jquery/dollar-sign: 2'

译文:

该属性修改本次扫描所有的规则额外的规则,他们将并入前定义的规则当中一起使用,如果只是使用当前指定的规则请结合--reset一起使用,定义多个规则可使用逗号隔开,也可多少次使用标签进行定义。如果规则不是以插件的形式定义的………………

16、--rulesdir(用于指定规则目录)

This option allows you to specify a second directory from which to load rules files. This allows you to dynamically load new rules at run time. This is useful when you have custom rules that aren't suitable for being bundled
with ESLint.

Example:

eslint --rulesdir my-rules/ file.js

The rules in your custom rules directory must follow the same format as bundled rules to work properly. You can also specify multiple locations for custom rules by including multiple --rulesdir flags:

eslint --rulesdir my-rules/ --rulesdir my-other-rules/ file.js

17、--stdin

This option tells ESLint to read and lint source code from STDIN instead files. You can use this to pipe code to ESLint.

Example

cat myfile.js | eslint --stdin

译文:该选项告诉eslint从stdin读取内容,而不是从文件读取。

18、-v, --version(查看版本)

This option outputs the current ESLint version onto the console. All other options are ignored when present.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: