Skip to content

Commit 8e7511f

Browse files
authored
feat(eslint): enforce blank line before return and after directives (#54)
1 parent eca3022 commit 8e7511f

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

eslint/configs/_base.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const commentsRules = require('../rules/comments');
22
const importRules = require('../rules/import');
33
const standardRules = require('../rules/standard');
4+
const stylisticRules = require('../rules/stylistic');
45
const unicornRules = require('../rules/unicorn');
56

67
// See: https://github.com/eslint/eslint/issues/3458
@@ -19,11 +20,12 @@ module.exports = {
1920
'plugin:unicorn/recommended',
2021
'plugin:prettier/recommended',
2122
],
22-
plugins: ['simple-import-sort'],
23+
plugins: ['@stylistic', 'simple-import-sort'],
2324
// Report unused `eslint-disable` comments.
2425
reportUnusedDisableDirectives: true,
2526
rules: {
2627
...standardRules,
28+
...stylisticRules,
2729
...commentsRules,
2830
...importRules,
2931
...unicornRules,

eslint/rules/stylistic.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
/**
3+
* This rule requires or disallows blank lines between the given 2 kinds of
4+
* statements. Properly blank lines help developers to understand the code.
5+
*
6+
* 🔧 Fixable - https://eslint.style/rules/js/padding-line-between-statements
7+
*/
8+
'@stylistic/padding-line-between-statements': [
9+
'warn',
10+
// Blank line before `return`
11+
{ blankLine: 'always', next: 'return', prev: '*' },
12+
// Blank line after all directives (e.g. `use strict`)
13+
{ blankLine: 'always', next: '*', prev: 'directive' },
14+
{ blankLine: 'any', next: 'directive', prev: 'directive' },
15+
],
16+
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@babel/core": "^7.23.3",
3333
"@babel/eslint-parser": "^7.23.3",
3434
"@rushstack/eslint-patch": "^1.6.0",
35+
"@stylistic/eslint-plugin": "^1.4.1",
3536
"@typescript-eslint/eslint-plugin": "^6.12.0",
3637
"eslint-config-prettier": "^9.0.0",
3738
"eslint-import-resolver-typescript": "^3.6.1",

pnpm-lock.yaml

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)