| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
10年前发布

JavaScript代码风格检查器:node-jscs

node-jscs 是一个 JavaScript 的代码风格检查工具。可在 Node.js 和浏览器中使用,在浏览器中使用的方法如下:

<script type="text/javascript" src="jscs-browser.js"></script>  <script type="text/javascript">  var checker = new JscsStringChecker();  checker.registerDefaultRules();  checker.configure({disallowMultipleVarDecl: true});  var errors = checker.checkString('var x, y = 1;');  errors.getErrorList().forEach(function(error) {      console.log(errors.explainError(error));  });  </script>

安装

jscs可以使用npm安装

npm install jscs

To run jscs, you can use the following command from the project root:

./node_modules/.bin/jscs path[ path[...]]

配置

jscs is configured using .jscs.json file, located in the project root.

requireCurlyBraces

Requires curly braces after statements.

Type: Array

Values: Arrow of quoted keywords

Example

"requireCurlyBraces": [      "if",      "else",      "for",      "while",      "do",      "try",      "catch",      "case",      "default"  ]
Valid
if (x) {     x++; } 
Invalid
if (x) x++; 

requireSpaceAfterKeywords

Requires space after keyword.

Type: Array

Values: Array of quoted keywords

Example

"requireSpaceAfterKeywords": [      "if",      "else",      "for",      "while",      "do",      "switch",      "return",      "try",      "catch"  ]
Valid
return true; 
Invalid
if(x) {     x++; } 

项目主页:http://www.open-open.com/lib/view/home/1389579390055

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1389579390055.html
node-jscs 代码分析/审查/优化