From 8e7511f0b911141fe5381fe5278c6a7cbecefa38 Mon Sep 17 00:00:00 2001 From: Alexey Ryabov Date: Thu, 7 Dec 2023 12:12:49 +0300 Subject: [PATCH] feat(eslint): enforce blank line before `return` and after directives (#54) --- eslint/configs/_base.js | 4 ++- eslint/rules/stylistic.js | 16 +++++++++++ package.json | 1 + pnpm-lock.yaml | 58 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 eslint/rules/stylistic.js diff --git a/eslint/configs/_base.js b/eslint/configs/_base.js index a9ee6f8..f8aa14d 100644 --- a/eslint/configs/_base.js +++ b/eslint/configs/_base.js @@ -1,6 +1,7 @@ const commentsRules = require('../rules/comments'); const importRules = require('../rules/import'); const standardRules = require('../rules/standard'); +const stylisticRules = require('../rules/stylistic'); const unicornRules = require('../rules/unicorn'); // See: https://github.com/eslint/eslint/issues/3458 @@ -19,11 +20,12 @@ module.exports = { 'plugin:unicorn/recommended', 'plugin:prettier/recommended', ], - plugins: ['simple-import-sort'], + plugins: ['@stylistic', 'simple-import-sort'], // Report unused `eslint-disable` comments. reportUnusedDisableDirectives: true, rules: { ...standardRules, + ...stylisticRules, ...commentsRules, ...importRules, ...unicornRules, diff --git a/eslint/rules/stylistic.js b/eslint/rules/stylistic.js new file mode 100644 index 0000000..6080c17 --- /dev/null +++ b/eslint/rules/stylistic.js @@ -0,0 +1,16 @@ +module.exports = { + /** + * This rule requires or disallows blank lines between the given 2 kinds of + * statements. Properly blank lines help developers to understand the code. + * + * 🔧 Fixable - https://eslint.style/rules/js/padding-line-between-statements + */ + '@stylistic/padding-line-between-statements': [ + 'warn', + // Blank line before `return` + { blankLine: 'always', next: 'return', prev: '*' }, + // Blank line after all directives (e.g. `use strict`) + { blankLine: 'always', next: '*', prev: 'directive' }, + { blankLine: 'any', next: 'directive', prev: 'directive' }, + ], +}; diff --git a/package.json b/package.json index 93b9bde..1100971 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@babel/core": "^7.23.3", "@babel/eslint-parser": "^7.23.3", "@rushstack/eslint-patch": "^1.6.0", + "@stylistic/eslint-plugin": "^1.4.1", "@typescript-eslint/eslint-plugin": "^6.12.0", "eslint-config-prettier": "^9.0.0", "eslint-import-resolver-typescript": "^3.6.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8711dd1..85d5d3d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13,6 +13,9 @@ dependencies: '@rushstack/eslint-patch': specifier: ^1.6.0 version: 1.6.0 + '@stylistic/eslint-plugin': + specifier: ^1.4.1 + version: 1.4.1(eslint@8.54.0)(typescript@5.3.2) '@typescript-eslint/eslint-plugin': specifier: ^6.12.0 version: 6.12.0(@typescript-eslint/parser@6.12.0)(eslint@8.54.0)(typescript@5.3.2) @@ -881,6 +884,61 @@ packages: lodash: 4.17.21 dev: false + /@stylistic/eslint-plugin-js@1.4.1(eslint@8.54.0): + resolution: {integrity: sha512-WXHPEVw5PB7OML7cLwHJDEcCyLiP7vzKeBbSwmpHLK0oh0JYkoJfTg2hEdFuQT5rQxFy3KzCy9R1mZ0wgLjKrA==} + engines: {node: ^16.0.0 || >=18.0.0} + peerDependencies: + eslint: '>=8.40.0' + dependencies: + acorn: 8.11.2 + escape-string-regexp: 4.0.0 + eslint: 8.54.0 + eslint-visitor-keys: 3.4.3 + espree: 9.6.1 + graphemer: 1.4.0 + dev: false + + /@stylistic/eslint-plugin-jsx@1.4.1(eslint@8.54.0): + resolution: {integrity: sha512-INBYpZmXrkeqnjCrUuTKMa7BeXiCR5VNvq71033hbPqXnG9oQDxX5mqE9Duj9qlISEOsxzhSr+UXGmq3mVYG9Q==} + engines: {node: ^16.0.0 || >=18.0.0} + peerDependencies: + eslint: '>=8.40.0' + dependencies: + '@stylistic/eslint-plugin-js': 1.4.1(eslint@8.54.0) + eslint: 8.54.0 + estraverse: 5.3.0 + dev: false + + /@stylistic/eslint-plugin-ts@1.4.1(eslint@8.54.0)(typescript@5.3.2): + resolution: {integrity: sha512-zuqnxhWoqPhZcxOb7AiYZz1RF/fUCsbJ7xq60IdRWnEY6MPybqYVJAb+SYilJ3PYxqmz8zdZeYkSeVy6f1fNnA==} + engines: {node: ^16.0.0 || >=18.0.0} + peerDependencies: + eslint: '>=8.40.0' + dependencies: + '@stylistic/eslint-plugin-js': 1.4.1(eslint@8.54.0) + '@typescript-eslint/utils': 6.12.0(eslint@8.54.0)(typescript@5.3.2) + eslint: 8.54.0 + graphemer: 1.4.0 + transitivePeerDependencies: + - supports-color + - typescript + dev: false + + /@stylistic/eslint-plugin@1.4.1(eslint@8.54.0)(typescript@5.3.2): + resolution: {integrity: sha512-CDwQCxglLTkUjpIJT4ltlpC8sKkPvTA7DjFcWiuZtBr0Vc6owGuYgJso4X1TDiD2JkjD3idbXCoGK0AfzNrgww==} + engines: {node: ^16.0.0 || >=18.0.0} + peerDependencies: + eslint: '>=8.40.0' + dependencies: + '@stylistic/eslint-plugin-js': 1.4.1(eslint@8.54.0) + '@stylistic/eslint-plugin-jsx': 1.4.1(eslint@8.54.0) + '@stylistic/eslint-plugin-ts': 1.4.1(eslint@8.54.0)(typescript@5.3.2) + eslint: 8.54.0 + transitivePeerDependencies: + - supports-color + - typescript + dev: false + /@types/eslint@8.44.7: resolution: {integrity: sha512-f5ORu2hcBbKei97U73mf+l9t4zTGl74IqZ0GQk4oVea/VS8tQZYkUveSYojk+frraAVYId0V2WC9O4PTNru2FQ==} dependencies: