False positive on rule `lines-between-class-memebers` if a comment occurs between class members
See original GitHub issueTell 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:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
I’m trying on this!
thanks! I can reproduce it.