diff --git a/index.js b/index.js index a4059bb..b0cc55a 100644 --- a/index.js +++ b/index.js @@ -27,5 +27,8 @@ module.exports = { asyncArrow: 'always', }], 'quotes': ['error', 'single', 'avoid-escape'], + 'lines-between-class-members': ['error', 'always', { + exceptAfterSingleLine: true, + }], }, }; diff --git a/tests/files/lines-between-class-members-bad.js b/tests/files/lines-between-class-members-bad.js new file mode 100644 index 0000000..f57af36 --- /dev/null +++ b/tests/files/lines-between-class-members-bad.js @@ -0,0 +1,11 @@ +class Example { + constructor() { + console.log(); + } + // there should be a line between class members + method() { + console.log(); + } +} + +console.log((new Example()).theAnswer); diff --git a/tests/files/lines-between-class-members-good.js b/tests/files/lines-between-class-members-good.js new file mode 100644 index 0000000..b0c5aa3 --- /dev/null +++ b/tests/files/lines-between-class-members-good.js @@ -0,0 +1,16 @@ +class Example { + constructor() { + console.log(); + } + + // no line between one-line class members is OK + get theAnswer() { return 42; } + get message() { return 'hi'; } + + // method() is unused but sadly the linter doesn't catch it yet + method() { + console.log(); + } +} + +console.log((new Example()).theAnswer);