gpt4 book ai didi

javascript - disallowTrailingComma 在 jscs 中不起作用

转载 作者:行者123 更新时间:2023-12-03 10:33:08 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com