question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`function-paren-newline` "multiline" errors for single arguments on their own line

See original GitHub issue

Tell us about your environment

  • ESLint Version: v4.6.1
  • Node Version: v8.3.0
  • npm Version: v5.3.0

What parser (default, Babel-ESLint, etc.) are you using? babel-eslint

Please show your full configuration:

Configuration
// relevant section:
"function-paren-newline" : ["error", "multiline"],

What did you do? Please include the actual source code causing the issue.

function foo(
  param1
)

// or

foo(
  "some very long argument that I'd love to have on it's own line"
);

What did you expect to happen?

No errors

What actually happened? Please include the actual, raw output from ESLint.

    1:13  error  Unexpected newline after '('                                 function-paren-newline
    3:1   error  Unexpected newline before ')'                                function-paren-newline
    7:4   error  Unexpected newline after '('                                 function-paren-newline
    9:1   error  Unexpected newline before ')'                                function-paren-newline

Some elaboration: with the multiline setting it is only allowed to have newlines in function parenthesis if there are at least 2 arguments. I would expect it to also accept newlines in function parenthesis for single arguments as well (as long as it’s done consistent).

I’m not sure if this is actually a bug or intended behaviour, if it’s the latter then an option to allow newlines for single-argument functions would be very welcome.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
jakezateckycommented, Sep 25, 2017

@not-an-aardvark

I would echo @TiddoLangerak’s desires for a rule that merely enforces “either all parameters are on their own line, or none are”. The multiline option does nearly everything needed for that, with the exception of single arguments. There are times when an individual argument may be a bit verbose and sometimes it is cleaner for that parameter to live on its own line (typically when I write my React test cases).

The consistent option, while permitting a single parameter on a newline, is insufficient, because it allows cases that would be unacceptable:

// Bad
function foo(bar,
  baz) {}

// Also bad
foo(
  bar, baz
);

Should I go ahead and create a new issue requesting an additional option to this rule or can we re-open this one?

1reaction
not-an-aardvarkcommented, Sep 26, 2017

Feel free to create a new issue. That said, keep in mind that you can always implement your preference as a custom rule without it being implemented as part of ESLint itself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

function-paren-newline - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
ESLint simple react App.js Unexpected newline after ...
It seems airbnb uses function-paren-newline: 'multiline' for that rule, ... I think you just need each argument on a separate line.
Read more >
enforce consistent line breaks inside function parentheses ...
"multiline-arguments" works like multiline but allows linebreaks inside function parentheses if there is only one parameter/argument.
Read more >
Configuration · Scalafmt - Scalameta
The special code // is used for single-line comments. Also, since v3.3.1, this includes multi-line comments /* ... */ which do not themselves...
Read more >
Code Style: One argument per line in a multi-line function call
Code like the "not valid" example in the previous comment is considered a multi-line function call because of the new lines after and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found