dsheiko / jscodesniffer

⛔️ [DEPRECATED] Tool to ensure that your JavaScript code does not violate the specified coding standard (Idiomatic Style Manifesto or JQuery Core Style Guidelines)
http://dsheiko.github.io/jscodesniffer/
42 stars 8 forks source link

ArgumentsSpacing Exception isn't working #18

Closed fabicious closed 9 years ago

fabicious commented 10 years ago

Hi there,

I'm trying to use my own coding-standard but the exceptions of ArgumentsSpacing and ParametersSpacing aren't working. Here ´'s the rule:

"ArgumentsSpacing": {
        "allowArgPrecedingWhitespaces": 1,
        "allowArgTrailingWhitespaces": 0,
        "exceptions": {
            "singleArg": {
                "for": [ "FunctionExpression", "ArrayExpression", "ObjectExpression" ],
                "allowArgPrecedingWhitespaces": 0,
                "allowArgTrailingWhitespaces": 0
            },
            "firstArg": {
                "for": [ "FunctionExpression", "ArrayExpression", "ObjectExpression" ],
                "allowArgPrecedingWhitespaces": 0
            },
            "lastArg": {
                "for": [ "FunctionExpression", "ArrayExpression", "ObjectExpression" ],
                "allowArgTrailingWhitespaces": 0
            }
        }
    }

And this line creates following error:

$(selector).css("width", final + "px");
ArgumentsSpacing: There must be one whitespace(s) preceding argument; no found

What I want is: 1 whitespace between every argument. But not before the first argument and not after the last argument. That implies no whitespaces before and after a single argument too.

Thanks for help!

evsheffield commented 9 years ago

:+1: I created a failing test case for this in my fork which demonstrates the issue: https://github.com/iVantage/jscodesniffer/commit/df7af3c1899ed104d32b7c5d4a312b9825fadd0a. Are there any updates on this? If not I'll try to take a look at it when I get the chance.

tersmitten commented 9 years ago

+1 for the "1 whitespace between every argument. But not before the first argument and not after the last argument"

dsheiko commented 9 years ago

Check in the rule set you provide - you specify explicitly what nodes you mean for the exceptions:

"for": [ "FunctionExpression", "ArrayExpression", "ObjectExpression" ]

Arguments of your example o not match any of these:

$(selector).css("width", final + "px");

selector is Identifier "width" - Literal final + "px" - BinaryExpression

By http://esprima.org/demo/parse.html

I've just deployed jscodesniffer 2.1.14 where you can simply omit "for"

 "ArgumentsSpacing": {
        "allowArgPrecedingWhitespaces": 1,
        "allowArgTrailingWhitespaces": 0,
        "exceptions": {
            "singleArg": {
                "allowArgPrecedingWhitespaces": 0,
                "allowArgTrailingWhitespaces": 0
            },
            "firstArg": {
                "allowArgPrecedingWhitespaces": 0
            },
            "lastArg": {
                "allowArgTrailingWhitespaces": 0
            }
        }
      }

See my test https://github.com/dsheiko/jscodesniffer/blob/master/test/try.js

 mocha test/try.js