Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function argument alignment causes false positive about indentation #208

Closed
idan opened this issue Jul 27, 2015 · 7 comments

Comments

@idan
Copy link

commented Jul 27, 2015

So, I have an unfortunate function with a slew of default parameters like so:

export function create (id, xfilter, rawType,
                        width=defaultWidth, height=defaultHeight,
                        footerHeight=defaultFooterHeight,
                        padding=defaultPadding) {
  // ... function body, indented two spaces
}

However this gets me complaints about the function body not being indented 26 spaces. 😦

I tried putting the opening brace on the following line in column zero, and it netted me a separate warning about the brace not being on the same line as the controlling statement.

One way I've found to keep standard happy is by doing this:

export function create (
id, xfilter, rawType,
width=defaultWidth, height=defaultHeight, footerHeight=defaultFooterHeight,
padding=defaultPadding) {
  // ... function body, indented two spaces
}

.. which doesn't read well for me.

Another is this, which is more legible to my eye:

export function create (id, xfilter, rawType,
                        width=defaultWidth, height=defaultHeight,
                        footerHeight=defaultFooterHeight,
                        padding=defaultPadding
) {
  // ... function body, indented two spaces
}

I feel like I'm missing something. What's the proper way to author standardjs-compliant functions with multiline arguments?

@julien-f

This comment has been minimized.

Copy link

commented Jul 27, 2015

What about this?

export function create (
  id, xfilter, rawType,
  width=defaultWidth, height=defaultHeight,
  footerHeight=defaultFooterHeight,
  padding=defaultPadding
) {
  // ... function body, indented two spaces
}

Anyway, IMHO with so many arguments you should use named parameters with an object and destructuring.

@feross

This comment has been minimized.

Copy link
Member

commented Jul 27, 2015

@idan What version of standard? Run standard --version.

@idan

This comment has been minimized.

Copy link
Author

commented Jul 27, 2015

@julien-f that does look nice. In this case I wanted the laziness of default params and with destructuring, I think I'd have to add some extra logic to set the defaults? I need to read up on how that would work.

@feross 4.5.4

@julien-f

This comment has been minimized.

Copy link

commented Jul 27, 2015

@idan Nope, not so much:

export function create ({
  id, xfilter, rawType,
  width=defaultWidth, height=defaultHeight,
  footerHeight=defaultFooterHeight,
  padding=defaultPadding
} = {}) {
  // ... function body, indented two spaces
}
@idan

This comment has been minimized.

Copy link
Author

commented Jul 27, 2015

@julien-f nifty! Thanks for the educational moment. 😄

@feross

This comment has been minimized.

Copy link
Member

commented Jul 27, 2015

@julien-f that's sexy!

This looks like an indentation bug in eslint. Bug filed here: eslint/eslint#3173

@feross feross changed the title Indentation of function arguments? Function argument alignment causes false positive about indentation Aug 4, 2015

@feross

This comment has been minimized.

Copy link
Member

commented Aug 21, 2015

Fixed in eslint master, so this will be fixed in a future standard release when we upgrade the eslint dependency.

@feross feross closed this Aug 21, 2015

@lock lock bot locked as resolved and limited conversation to collaborators May 11, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
3 participants
You can’t perform that action at this time.