Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Indentation in line-wrapped function arguments #12

Closed
ghost opened this issue Jun 6, 2016 · 7 comments
Closed

Indentation in line-wrapped function arguments #12

ghost opened this issue Jun 6, 2016 · 7 comments

Comments

@ghost
Copy link

ghost commented Jun 6, 2016

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
Copy link
Contributor

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

@ghost
Copy link
Author

ghost commented Jun 6, 2016

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
Copy link
Contributor

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
Copy link
Author

ghost commented Jun 8, 2016

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
Copy link

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
Copy link
Member

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

@philipwalton
Copy link
Contributor

Closing now that #50 is merged.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants