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-call-argument-newline complains in some cases when it logically shouldn't.

See original GitHub issue

Tell 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:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Sep 29, 2019

By #10323 it seems that function-call-argument-newline should have a behavior similar to the behavior of array-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:

/* eslint array-element-newline:["error", "consistent"] */

['scroll', function() {
    // do something
}, {
    passive: true,
}];

['scroll', function() {
    // do something
}, {passive: true}];

Online Demo

Also, function-call-argument-newline with the never 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 the consistent option when the first two arguments start on the same line (like in the original example), because it applies never 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:

/*eslint function-call-argument-newline:["error", "always"] */
foo({
  bar: 1
}, baz);

/*eslint function-call-argument-newline:["error", "consistent"] */
foo(bar,
    function (){
      // do something
    }, {
        a: 1  
    }
);

function-call-argument-newline at the moment doesn’t generate warnings in the above cases, but it’s probably also a bug since array-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 ?

1reaction
mdjermanoviccommented, Aug 27, 2019

This isn’t related directly to the consistent option, e.g. this is also an error:

/*eslint function-call-argument-newline:["error", "never"] */

foo({
}, bar);

and is reporting a line break between , and bar (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:

This rule enforces line breaks between arguments of a function call. “always” (default) requires line breaks between arguments “never” disallows line breaks between arguments “consistent” requires consistent usage of line breaks between arguments

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:

/*eslint function-call-argument-newline:["error", "always"] */

foo({
}, bar);
Read more comments on GitHub >

github_iconTop Results From Across the Web

LSAT 75, Logical Reasoning II, Q3, LSATHacks
To strengthen the argument, you just need to state that principle explicitly: “Complaints shouldn't be denied on a technicality if the error was...
Read more >
eslint | Yarn - Package Manager
ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. In many ways, it is similar to JSLint and...
Read more >
griebnitz/node_modules/eslint/CHANGELOG.md - GitLab
Repository ; 39dfe08 Update: false positives in function-call-argument-newline (fixes #12123) (#12280) (Scott O'Hara) ; 4d84210 Update: improve ...
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