我正在使用http://jscs.info。 如果我的应用程序留下尾随逗号,我需要收到警告,例如,使用:
var x = {
prop1: 10,
prop2: 20,
};
我应该收到警告。 使用以下设置:
disallowTrailingComma true
requireTrailingComma true
我无法得到警告。
我在这里做错了什么?
{
"disallowCommaBeforeLineBreak": null,
"disallowDanglingUnderscores": true,
"disallowEmptyBlocks": true,
"disallowImplicitTypeConversion": [ "string" ],
"disallowKeywordsOnNewLine": [ "else" ],
"disallowKeywords": [ "with" ],
"disallowMixedSpacesAndTabs": true,
"disallowMultipleLineBreaks": true,
"disallowMultipleLineStrings": true,
"disallowMultipleVarDecl": null,
"disallowPaddingNewlinesInBlocks": null,
"disallowQuotedKeysInObjects": true,
"disallowSpaceAfterBinaryOperators": true,
"disallowSpaceAfterKeywords": [ "for", "while", "do", "switch" ],
"disallowSpaceAfterLineComment": false,
"disallowSpaceAfterObjectKeys": null,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforeBinaryOperators": null,
"disallowSpaceBeforeBlockStatements": null,
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpacesInAnonymousFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInConditionalExpression": null,
"disallowSpacesInFunctionDeclaration": null,
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInNamedFunctionExpression": null,
"disallowSpacesInsideArrayBrackets": null,
"disallowSpacesInsideObjectBrackets": null,
"disallowSpacesInsideParentheses": null,
"disallowTrailingComma": true, // -------------------null
"disallowTrailingWhitespace": true,
"disallowYodaConditions": true,
"maximumLineLength": 120,
"requireAlignedObjectValues": "skipWithFunction",
"requireBlocksOnNewline": true,
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
"requireCapitalizedConstructors": true,
"requireCommaBeforeLineBreak": true,
"requireCurlyBraces": [ "if", "else", "for", "while", "do", "try", "catch" ],
"requireDotNotation": true,
"requireKeywordsOnNewLine": null,
"requireLineFeedAtFileEnd": true,
"requireMultipleVarDecl": true,
"requireOperatorBeforeLineBreak": true,
"requirePaddingNewlinesInBlocks": true,
"requireParenthesesAroundIIFE": true,
"requireSpaceAfterBinaryOperators": null,
"requireSpaceAfterKeywords": [ "if", "else", "return", "try", "catch" ],
"requireSpaceAfterLineComment": null,
"requireSpaceAfterObjectKeys": true,
"requireSpaceAfterPrefixUnaryOperators": null,
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceBeforeBlockStatements": true,
"requireSpaceBeforePostfixUnaryOperators": null,
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"requireSpacesInConditionalExpression": true,
"requireSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"requireSpacesInsideArrayBrackets": "all",
"requireSpacesInsideObjectBrackets": "allButNested",
"requireSpacesInsideParentheses": "all",
"requireTrailingComma": true, // -------------------------true
"safeContextKeyword": true,
"validateIndentation": 4,
"validateJSDoc": {
"checkParamNames": true,
"requireParamTypes": true
},
"validateLineBreaks": "LF",
"validateQuoteMarks": true
}
答案 0 :(得分:1)
你的两个选择相互矛盾。同时,您要求使用"requireTrailingComma": true
的尾随逗号,并禁止使用"disallowTrailingComma": true
跟踪逗号。
要获取尾随逗号的警告,请移除"requireTrailingComma": true
选项,同时保留"disallowTrailingComma": true
。
<强>更新强>
我删除了以下在控制台中生成错误的选项,它适用于稍微修改过的示例代码,只显示尾随逗号警告:
var x ={
prop1 : 10,
prop2 : 20,
};
我删除了以下行(与错误一起显示)
"disallowSpaceAfterLineComment": false
因为
AssertionError: disallowSpaceAfterLineComment option requires the value true
和
"safeContextKeyword": true
,因为
AssertionError: safeContextKeyword option requires string or array value
和
"requireTrailingComma": true
因为上述矛盾。