google / eslint-config-google

ESLint shareable config for the Google JavaScript style guide
Apache License 2.0
1.75k stars 139 forks source link

Indentation in line-wrapped function arguments #12

Closed ghost closed 6 years ago

ghost commented 8 years ago

According to the Google JavaScript Style:

When possible, all function arguments should be listed on the same line. If doing so would exceed the 80-column limit, the arguments must be line-wrapped in a readable way. To save space, you may wrap as close to 80 as possible, or put each argument on its own line to enhance readability. The indentation may be either four spaces, or aligned to the parenthesis.

This ESLint configuration (version 0.5.0) does not enforce that indentation. No warning is throw when I use less or more indentation in line-wrapped function arguments. By comparison the Closure Linter does this. It also throws indentation warnings on line-wrapped variable initializations and method chaining, which this ESLint configuration also does not enforce.

sindresorhus commented 8 years ago

Is there an ESLint rule for that? Otherwise you'll need to request it on the ESLint issue tracker.

ghost commented 8 years ago

Apparently there is not, as I was unable to find one in the ESLint documentation (v2.11.1).

Unfortunately, according to the ESlint contributing guide page, to request a new rule and for it to be accepted, you also need to be the one to create and maintain it. Currently I would be unable to do that.

Wouldn't that be the case to create a custom rule for this configuration?

sindresorhus commented 8 years ago

to request a new rule and for it to be accepted, you also need to be the one to create and maintain it.

That's not entirely correct. Open an issue and if there's merit to the idea, someone will come along and implement it.

ghost commented 8 years ago

I just found that a parameter indentation rule is currently being evaluated by ESLint members. So it's just a question of time now.

rachel-fenichel commented 6 years ago

The indent rule has been updated to be more configurable.

I found this repo while tweaking eslint configs for Google style. If you're still updating it, here's what I'm using for indentation so far:

        "indent": [
            "error", 2,  # Google use 2-space indents
            # Google uses +4 space indents for line continuations.
            {
                "SwitchCase": 1,
                "MemberExpression": 2,
                "FunctionDeclaration": {
                    "body": 1,
                    "parameters": 2
                },
                "FunctionExpression": {
                    "body": 1,
                    "parameters": 2
                },
                "CallExpression": {
                    "arguments": 2
                },
                # Ignore default rules for ternary expressions.
                "ignoredNodes": ["ConditionalExpression"]
            }
        ],

I haven't sorted out what version of the Object Expression rule applies.

mathiasbynens commented 6 years ago

Thanks for providing that snippet, @rachel-fenichel! I've added an object expression rule and submitted a PR: #50.

philipwalton commented 6 years ago

Closing now that #50 is merged.