function-call-argument-newline complains in some cases when it logically shouldn't.
See original GitHub issueTell us about your environment
- ESLint Version: 6.2.0
- Node Version: 11.14.0
- npm Version: 6.7.0
What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:
This config is the minimum together with the example code below to reproduce the issue.
Configuration
{
"extends": "eslint:recommended",
"env": {
"browser": true
},
"rules": {
"function-call-argument-newline": [
"error",
"consistent"
]
}
}
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
This is a minimal reproducer that I’ve created based on my own experimentation, not the original code that caused the issue:
document.body.addEventListener('scroll', function() {
// do something
})
document.body.addEventListener('scroll', function() {
// do something
}, {
passive: true,
})
document.body.addEventListener('scroll', function() {
// do something
}, {passive: true})
npx eslint test.js
What did you expect to happen?
In consistent mode, none of the three calls to document.body.addEventListener()
above should trigger an error (the use of newlines between arguments is consistent in all three cases).
What actually happened? Please include the actual, raw output from ESLint.
/mnt/sync/eslint-test/test.js
7:3 error There should be no line break here function-call-argument-newline
13:3 error There should be no line break here function-call-argument-newline
✖ 2 problems (2 errors, 0 warnings)
2 errors and 0 warnings potentially fixable with the `--fix` option.
Are you willing to submit a pull request to fix this bug?
I don’t have enough background with Node.js to be comfortable submitting a PR, but I will be more than happy to help test any that does get submitted.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:14 (10 by maintainers)
By #10323 it seems that
function-call-argument-newline
should have a behavior similar to the behavior ofarray-element-newline
, which indeed compares the last token of an element with the first token of the following element.These examples are equivalent to the two examples from the initial post, and there are no errors:
Online Demo
Also,
function-call-argument-newline
with thenever
option in its current version indirectly disallows newlines inside the arguments (unless it’s the last argument). which I believe shouldn’t be the responsibility of this rule. The same applies to theconsistent
option when the first two arguments start on the same line (like in the original example), because it appliesnever
to all following arguments.I strongly believe this is a bug that should be fixed, though it will generate some new warnings, like in these cases:
function-call-argument-newline
at the moment doesn’t generate warnings in the above cases, but it’s probably also a bug sincearray-element-newline
does (Online Demo 1, Online Demo 2).@kaicataldo can we already accept this as a bug fix that will generate more warnings by default, or maybe wait for one more vote ?
This isn’t related directly to the
consistent
option, e.g. this is also an error:and is reporting a line break between
,
andbar
(Demo)The issue is with comparing first tokens instead of last vs first (there is also a similar but not same issue with multiline tokens because it compares start with start).
I believe this could be seen as a bug, because:
If fixed to compare last to first (and end to start) all examples from this issue should be solved, but the following would be a new error: