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.

False positive on rule `lines-between-class-memebers` if a comment occurs between class members

See original GitHub issue

Tell us about your environment

  • ESLint Version: 4.12
  • Node Version: 8.9.1
  • npm Version: 5.5.1

What parser (default, Babel-ESLint, etc.) are you using? n/a

Please show your full configuration:

Configuration
{
    "parserOptions": {
        "ecmaVersion": 6,
        "sourceType": "script",
        "ecmaFeatures": {}
    },
    "rules": {
        "lines-between-class-members": 2
    },
    "env": {}
}

(generated by ESLint Demo)

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

I have a class which purpose is to be extended by other classes in order to provide actual implementation of some methods. The class has placeholder methods that only throw, but don’t use context (the subclass implementation will)

Since this is an exception i wrapped the method with /* eslint-disable class-methods-use-this */ just before the doc block and /* eslint-enable class-methods-use-this */ just after the method body like that:

class Foo {
  /* eslint-disable class-methods-use-this */
  /**
   * @returns {Array}
   */
  getFoo() {
    throw new Error('Child class should reimplement this method');
  }
  /* eslint-enable class-methods-use-this */

  /**
   * @returns {undefined}
   */
  doSomething() {}
}

Demo showing false positive (demo1)

Demo reduced to bare minimum showing false positive (demo2). This one proves that any block comment between class members break the rule

What’s interesting: Moving the /* eslint-enable class-methods-use-this */ from line 9 to line 10 (so that the padding line is above the /* eslint-enable */ directive) solves the problem (another demo with no error: demo1-no-error, and demo2-no-error)

What did you expect to happen? I think the rule should not report an error on line 14, especially since there’s a blank line 10 which logically meets rule requirements. Placement of /* eslint-* */ directives should not affect whether the rule reports error or not if there’s one empty line between members.

What actually happened? Please include the actual, raw output from ESLint. Rule reports error in line 14, column 3 (see demo1 and demo2).

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sakabarcommented, Dec 3, 2017

I’m trying on this!

0reactions
aladdin-addcommented, Dec 3, 2017

thanks! I can reproduce it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing New Ways to Communicate Your Group Rules
Now you can apply group rules for muting members, removing group comments or declining pending posts. · Tap on the “...” at the...
Read more >
Oversight Board opens public comments for policy advisory ...
“'False positive risk' refers to the risk of incorrect enforcement against content or entities that do not actually violate” Facebook's Community Standards.
Read more >
Programming - Commenting - Utah School of Computing
Commenting is best done before actually writing the code for your program. Comments are specially marked lines of text in the program that...
Read more >
Best practices for writing code comments - Stack Overflow Blog
Rule 5: Explain unidiomatic code in comments. It's a good idea to comment code that someone else might consider unneeded or redundant, such...
Read more >
Insert or delete a comment - Microsoft Support
Attaching your comments to specific parts of a document makes your feedback more clear. If someone else is commenting on the document, replying...
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