簡體   English   中英

disallowTrailingComma在JSC中不起作用

[英]disallowTrailingComma does not work in jscs

我正在使用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
}

您的兩個選擇相互矛盾。 同時,您需要使用"requireTrailingComma": true結尾的逗號,並使用"disallowTrailingComma": true禁止結尾逗號。

要獲取尾隨逗號的警告,請刪除"requireTrailingComma": true選項,同時保留"disallowTrailingComma": true


UPDATE

我刪除了以下選項,這些選項在控制台中產生了錯誤,並且對您稍作修改的示例代碼有效,僅顯示了逗號結尾警告:

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

由於上述矛盾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM