[H5]使用JSHint 配置完善代码规范

2017-01-22  本文已影响2247人  肖浩呗

什么是JSHint
发现错误和潜在问题的社区驱动的工具

常见js编辑器的JSHint插件


安装JSHint命令行工具

使用JSHint命令行工具

{
  "esversion": 3
}
let text = 'HelloWorld';
console.log (text);
 jshint -c ./.jshintrc ./HelloWorld.js 
./HelloWorld.js: line 5, col 1, 'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
1 error

JSHintjshint -help命令解析

Usage:
  jshint [OPTIONS] [ARGS]

Options: 
  /**
   * 自定义配置文件路径 `.jshintrc`
   * example
   * jshint -c ./.jshintrc
   */
  -c, --config STRING    Custom configuration file

      /**
       * 修改报错输出使用的插件
       * example
       * jshint --reporter checkstyle 
       */
      --reporter STRING  Custom reporter (<PATH>|jslint|checkstyle|unix) 

      /**
       * 分析前的依赖全局变量
       * example
       * jshint -c ./.jshintrc  --prereq "var lala;"
       */
      --prereq STRING    Comma-separate list of prerequisite (paths). E.g. 
                         files which includedefinitions of global variabls 
                         used throughout your project 
      /**
       * 指定不需要分析的js文件和`.jshintignore`用法相同
       * example
       * jshint -c ./.jshintrc  --exclude ./HelloWorld.js  ./
       */
      --exclude STRING   Exclude files matching the given filename pattern 
                         (same as .jshintignore) 

      /**
       * 指定不需要分析的js文件和`.jshintignore`用法相同
       * example
       * jshint -c ./.jshintrc  --exclude-path ./.jshintignore ./
       */
      --exclude-path STRINGPass in a custom jshintignore file path
      --filename STRING  Pass in a filename when using STDIN to emulate config 
                         lookup for that file name 
      --verbose          Show message codes

      /**
       * 文件分析没有错误时输出结果
       * example
       * jshint --show-non-errors
       */
      --show-non-errors  Show additional data generated by jshint
  -e, --extra-ext STRING Comma-separated list of file extensions to use 
                         (default is .js) 
      --extract [STRING] Extract inline scripts contained in HTML 
                         (auto|always|never, default to never)  (Default is never)
      --jslint-reporter  Use a jslint compatible reporter (DEPRECATED, use 
                         --reporter=jslint instead) 
      --checkstyle-reporter Use a CheckStyle compatible XML reporter 
                            (DEPRECATED, use --reporter=checkstyle 
                            instead) 
  -v, --version          Display the current version
  -h, --help             Display help and usage details

JSHint常见的设置选项

参考文章

JSHint Documentation
JSHint Configuration Options
JSHint Grunt Pluign
Improving Code Quality with JSHint
JSHint 配置简析

上一篇 下一篇

猜你喜欢

热点阅读