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++; } 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!