javascript - disallowTrailingComma 在 jscs 中不起作用

标签 javascript jshint 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

<小时/>

更新

我删除了以下在控制台中生成错误的选项,它适用于您稍作修改的示例代码,仅显示尾随逗号警告:

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

因为上面描述的矛盾。

关于javascript - disallowTrailingComma 在 jscs 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29120520/

相关文章:

javascript - Gulp:带参数的 Jsc

javascript - 有 JSCS Eclipse 插件吗?

javascript - 使用 RegExp 在特殊字符序列之间提取值

javascript - 浏览器在哪里存储用 let 或 const 定义的全局变量?

javascript - jshint - 不要使用 Array.find 在循环内创建函数

javascript - 在循环中使用 Array.prototype.forEach 可以吗?

javascript - gulp-jshint 包 : How to send parameters (without . jshintrc 文件)?

webstorm - Webstorm 中的 JSCS 进程超时

javascript - 使用 JavaScript 在刷新时将查询字符串附加到 url

javascript - 饼图颜色不变