From 32e5828af41ec6c625111dc847981612bde966ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Nikoli=C4=87?= Date: Sun, 14 Apr 2024 10:22:58 +0200 Subject: [PATCH] Group stylistic rules --- browser.js | 7 - index.js | 521 ++++++++++++++++++++++++-------------------------- tests.js | 9 - typescript.js | 2 - vue.js | 23 +-- 5 files changed, 251 insertions(+), 311 deletions(-) diff --git a/browser.js b/browser.js index 0b0784b..dd931b4 100644 --- a/browser.js +++ b/browser.js @@ -5,17 +5,10 @@ module.exports = { node: false, browser: true }, - plugins: ['eslint-plugin-unicorn'], - rules: { - // Possible errors 'no-console': 2, - - // Best practices 'no-implicit-globals': 2, - - // Unicorn 'unicorn/no-document-cookie': 2, 'unicorn/require-post-message-target-origin': 2, 'unicorn/prefer-dom-node-append': 0, diff --git a/index.js b/index.js index 1654e6e..34b9b28 100644 --- a/index.js +++ b/index.js @@ -5,11 +5,9 @@ module.exports = { node: true, es2022: true }, - parserOptions: { ecmaVersion: 2022 }, - plugins: [ 'eslint-plugin-promise', 'eslint-plugin-n', @@ -19,7 +17,6 @@ module.exports = { ], rules: { - // Node 'n/no-sync': 1, 'n/no-restricted-require': 0, 'n/no-restricted-import': 0, @@ -39,10 +36,8 @@ module.exports = { 'n/no-callback-literal': 2, 'n/no-exports-assign': 2, 'n/exports-style': [1, 'module.exports'], - // Ref. https://github.com/mysticatea/eslint-plugin-node/issues/301 'n/process-exit-as-throw': 0, - 'n/prefer-global/url': [1, 'always'], 'n/prefer-global/url-search-params': [1, 'always'], 'n/no-deprecated-api': 0, @@ -67,8 +62,6 @@ module.exports = { 'n/prefer-promises/fs': 1, 'n/hashbang': 1, 'n/prefer-node-protocol': 1, - - // Unicorn 'unicorn/better-regex': 1, 'unicorn/import-style': 1, 'unicorn/no-null': 0, @@ -192,8 +185,6 @@ module.exports = { 'unicorn/no-unnecessary-polyfills': 0, 'unicorn/prefer-blob-reading-methods': 1, 'unicorn/prefer-set-size': 1, - - // JSDoc 'jsdoc/check-line-alignment': 1, 'jsdoc/require-property': 0, 'jsdoc/check-property-names': 0, @@ -247,15 +238,12 @@ module.exports = { 'jsdoc/informative-docs': 0, 'jsdoc/no-blank-block-descriptions': 0, 'jsdoc/no-blank-blocks': 0, - - // Possible errors 'no-unreachable-loop': 2, 'no-useless-backreference': 1, 'no-loss-of-precision': 1, 'no-promise-executor-return': 2, 'getter-return': [2, { allowImplicit: true }], 'no-compare-neg-zero': 2, - 'comma-dangle': [1, 'never'], 'no-cond-assign': [2, 'except-parens'], 'no-console': 0, 'no-constant-condition': 2, @@ -268,8 +256,6 @@ module.exports = { 'no-empty': 1, 'no-ex-assign': 2, 'no-extra-boolean-cast': 2, - 'no-extra-parens': 0, - 'no-extra-semi': 1, 'no-func-assign': 2, 'no-inner-declarations': [2, 'both'], 'no-invalid-regexp': 2, @@ -295,8 +281,6 @@ module.exports = { 'no-unsafe-optional-chaining': 1, 'no-constant-binary-expression': 2, 'no-new-native-nonconstructor': 1, - - // Best practices 'default-case-last': 2, 'prefer-regex-literals': 1, 'accessor-pairs': [ @@ -310,7 +294,6 @@ module.exports = { 'consistent-return': 1, curly: [2, 'all'], 'default-case': 1, - 'dot-location': [1, 'property'], 'dot-notation': 1, eqeqeq: 2, 'guard-for-in': 2, @@ -325,7 +308,6 @@ module.exports = { 'no-extend-native': 1, 'no-extra-bind': 1, 'no-fallthrough': 2, - 'no-floating-decimal': 2, 'no-global-assign': 2, 'no-implicit-coercion': 2, 'no-implied-eval': 2, @@ -335,16 +317,6 @@ module.exports = { 'no-lone-blocks': 2, 'no-loop-func': 2, 'no-magic-numbers': 0, - 'no-multi-spaces': [ - 1, - { - exceptions: { - Property: true, - VariableDeclarator: true, - ImportDeclaration: true - } - } - ], 'no-multi-str': 2, 'no-native-reassign': 2, 'no-new-func': 1, @@ -375,7 +347,6 @@ module.exports = { 'no-with': 2, radix: [2, 'always'], 'vars-on-top': 2, - 'wrap-iife': [2, 'inside'], yoda: 1, 'array-callback-return': 1, 'no-empty-function': 0, @@ -395,11 +366,7 @@ module.exports = { 'no-nonoctal-decimal-escape': 0, 'logical-assignment-operators': 0, 'no-empty-static-block': 1, - - // Strict mode strict: [2, 'global'], - - // Variables 'init-declarations': 0, 'no-catch-shadow': 2, 'no-delete-var': 2, @@ -419,100 +386,10 @@ module.exports = { 'no-unused-vars': 1, 'no-use-before-define': [2, 'nofunc'], 'no-restricted-globals': 0, - - // Node.js and CommonJS 'no-buffer-constructor': 2, - - // Stylistic issues 'id-denylist': 0, 'prefer-exponentiation-operator': 0, - 'switch-colon-spacing': [1, { before: false, after: true }], - 'semi-style': [2, 'last'], - 'padding-line-between-statements': [ - 2, - - // Blank line always after directives - { - blankLine: 'always', - prev: 'directive', - next: '*' - }, - { - blankLine: 'any', - prev: 'directive', - next: 'directive' - }, - - // Blank line always before "module.exports" and "export" statement - { - blankLine: 'always', - prev: '*', - next: 'cjs-export' - }, - { - blankLine: 'never', - prev: 'cjs-export', - next: 'cjs-export' - }, - { - blankLine: 'always', - prev: '*', - next: 'export' - }, - - // Blank line always after last "require" and "import" statement - { - blankLine: 'always', - prev: 'cjs-import', - next: '*' - }, - { - blankLine: 'any', - prev: 'cjs-import', - next: 'cjs-import' - }, - { - blankLine: 'any', - prev: 'cjs-import', - next: 'import' - }, - { - blankLine: 'always', - prev: 'import', - next: '*' - }, - { - blankLine: 'any', - prev: 'import', - next: 'import' - }, - { - blankLine: 'any', - prev: 'import', - next: 'cjs-import' - } - ], 'multiline-comment-style': [1, 'starred-block'], - 'lines-between-class-members': [1, 'always'], - 'implicit-arrow-linebreak': [1, 'beside'], - 'function-paren-newline': [1, 'multiline'], - 'array-bracket-spacing': [ - 1, - 'always', - { - singleValue: false, - objectsInArrays: false, - arraysInArrays: false - } - ], - 'block-spacing': [1, 'always'], - 'brace-style': [ - 2, - '1tbs', - { - allowSingleLine: true - } - ], camelcase: [ 2, { @@ -527,18 +404,7 @@ module.exports = { ignoreConsecutiveComments: true } ], - 'comma-spacing': [ - 2, - { - before: false, - after: true - } - ], - 'comma-style': [2, 'last'], - 'computed-property-spacing': [2, 'never'], 'consistent-this': [2, 'self'], - 'eol-last': [2, 'unix'], - 'func-call-spacing': [2, 'never'], 'func-name-matching': 0, 'func-names': 0, 'func-style': [ @@ -550,24 +416,7 @@ module.exports = { ], 'id-length': 0, 'id-match': 0, - indent: [ - 2, - 'tab', - { - SwitchCase: 1 - } - ], - 'key-spacing': [ - 2, - { - beforeColon: false, - afterColon: true - } - ], - 'linebreak-style': [2, 'unix'], - 'lines-around-comment': 0, 'max-depth': [1, 3], - 'max-len': 0, 'max-lines': [ 1, { @@ -579,42 +428,22 @@ module.exports = { 'max-nested-callbacks': [1, 3], 'max-params': [1, 4], 'max-statements': 0, - 'multiline-ternary': 0, - 'max-statements-per-line': [ - 1, - { - max: 4 - } - ], 'new-cap': 2, - 'new-parens': 2, 'no-array-constructor': 1, 'no-bitwise': 1, 'no-continue': 1, 'no-inline-comments': 0, 'no-lonely-if': 1, - 'no-mixed-operators': 2, - 'no-mixed-spaces-and-tabs': [2, 'smart-tabs'], 'no-multi-assign': 0, - 'no-multiple-empty-lines': [ - 2, - { - max: 5, - maxEOF: 1 - } - ], 'no-negated-condition': 0, 'no-nested-ternary': 2, 'no-new-object': 1, 'no-plusplus': 0, 'no-restricted-syntax': 0, - 'no-tabs': 0, 'no-spaced-func': 2, 'no-ternary': 0, - 'no-trailing-spaces': 2, 'no-underscore-dangle': 0, 'no-unneeded-ternary': 1, - 'object-curly-spacing': [1, 'always'], 'one-var': [ 1, { @@ -623,90 +452,13 @@ module.exports = { } ], 'operator-assignment': 0, - 'operator-linebreak': [2, 'after'], - 'padded-blocks': 0, - 'quote-props': [ - 1, - 'consistent-as-needed', - { - keywords: true - } - ], - quotes: [ - 2, - 'single', - { - allowTemplateLiterals: true - } - ], 'require-jsdoc': 0, - 'semi-spacing': [ - 1, - { - before: false, - after: true - } - ], - semi: [2, 'always'], 'sort-keys': 0, 'sort-vars': 0, - 'keyword-spacing': [ - 2, - { - before: true, - after: true - } - ], 'line-comment-position': 0, - 'space-before-blocks': [2, 'always'], - 'space-before-function-paren': [2, 'always'], - 'space-in-parens': 0, - 'space-infix-ops': 1, - 'space-unary-ops': [ - 1, - { - words: true, - nonwords: false - } - ], - 'spaced-comment': [ - 1, - 'always', - { - line: { - exceptions: ['-'], - markers: ['/'] - }, - block: { - exceptions: ['-'] - } - } - ], - 'wrap-regex': 0, 'id-blacklist': 0, - 'newline-per-chained-call': [ - 1, - { - ignoreChainWithDepth: 4 - } - ], - 'no-whitespace-before-property': 1, - 'nonblock-statement-body-position': 0, - 'one-var-declaration-per-line': 0, - 'object-property-newline': [1, { allowAllPropertiesOnSameLine: true }], - 'object-curly-newline': [ - 1, - { - consistent: true - } - ], 'unicode-bom': [2, 'never'], - 'array-bracket-newline': [1, 'consistent'], - 'array-element-newline': [1, 'consistent'], 'max-lines-per-function': 0, - 'function-call-argument-newline': 0, - - // ES2015 (we want to use subset from ES2015) 'promise/catch-or-return': 1, 'promise/always-return': 2, 'promise/param-names': 2, @@ -722,23 +474,12 @@ module.exports = { 'promise/no-return-in-finally': 1, 'promise/valid-params': 2, 'promise/no-multiple-resolved': 2, - 'arrow-body-style': 0, - 'arrow-parens': [2, 'always'], - 'arrow-spacing': [ - 2, - { - before: true, - after: true - } - ], - 'no-confusing-arrow': [1, { allowParens: true }], 'no-const-assign': 2, 'no-var': 0, 'prefer-arrow-callback': 0, 'prefer-const': 0, 'prefer-template': 1, - 'template-curly-spacing': [2, 'never'], 'no-template-curly-in-string': 1, 'prefer-promise-reject-errors': [ 1, @@ -746,17 +487,9 @@ module.exports = { allowEmptyReject: true } ], - 'template-tag-spacing': [2, 'never'], 'no-useless-computed-key': 1, 'object-shorthand': [1, 'consistent-as-needed'], 'constructor-super': 1, - 'generator-star-spacing': [ - 2, - { - before: true, - after: false - } - ], 'no-class-assign': 1, 'no-dupe-class-members': 2, 'no-this-before-super': 2, @@ -769,10 +502,8 @@ module.exports = { 'prefer-rest-params': 1, 'sort-imports': 0, 'symbol-description': 1, - 'yield-star-spacing': [1, 'after'], 'no-duplicate-imports': 1, 'no-useless-rename': 1, - 'rest-spread-spacing': [2, 'never'], 'class-methods-use-this': 0, 'prefer-numeric-literals': 0, 'no-return-await': 2, @@ -789,8 +520,6 @@ module.exports = { 'unicorn/prefer-at': 1, 'unicorn/prefer-object-from-entries': 1, 'unicorn/prefer-top-level-await': 0, - - // "import" and "require" 'import/no-absolute-path': 2, 'import/no-dynamic-require': 2, 'import/no-webpack-loader-syntax': 2, @@ -837,6 +566,254 @@ module.exports = { 'n/file-extension-in-import': 0, 'import/extensions': [2, 'always', { ignorePackages: true }], 'import/consistent-type-specifier-style': 0, - 'import/no-empty-named-blocks': 1 + 'import/no-empty-named-blocks': 1, + + // Stylistic rules - deprecated + 'array-bracket-newline': [1, 'consistent'], + 'array-bracket-spacing': [ + 1, + 'always', + { + singleValue: false, + objectsInArrays: false, + arraysInArrays: false + } + ], + 'array-element-newline': [1, 'consistent'], + 'arrow-parens': [2, 'always'], + 'arrow-spacing': [ + 2, + { + before: true, + after: true + } + ], + 'block-spacing': [1, 'always'], + 'brace-style': [ + 2, + '1tbs', + { + allowSingleLine: true + } + ], + 'comma-dangle': [1, 'never'], + 'comma-spacing': [ + 2, + { + before: false, + after: true + } + ], + 'comma-style': [2, 'last'], + 'computed-property-spacing': [2, 'never'], + 'dot-location': [1, 'property'], + 'eol-last': [2, 'unix'], + 'func-call-spacing': [2, 'never'], + 'function-call-argument-newline': 0, + 'function-paren-newline': [1, 'multiline'], + 'generator-star-spacing': [ + 2, + { + before: true, + after: false + } + ], + 'implicit-arrow-linebreak': [1, 'beside'], + indent: [ + 2, + 'tab', + { + SwitchCase: 1 + } + ], + 'jsx-quotes': 0, + 'key-spacing': [ + 2, + { + beforeColon: false, + afterColon: true + } + ], + 'keyword-spacing': [ + 2, + { + before: true, + after: true + } + ], + 'linebreak-style': [2, 'unix'], + 'lines-between-class-members': [1, 'always'], + 'lines-around-comment': 0, + 'max-len': 0, + 'max-statements-per-line': [ + 1, + { + max: 4 + } + ], + 'multiline-ternary': 0, + 'new-parens': 2, + 'newline-per-chained-call': [ + 1, + { + ignoreChainWithDepth: 4 + } + ], + 'no-confusing-arrow': [1, { allowParens: true }], + 'no-extra-parens': 0, + 'no-extra-semi': 1, + 'no-floating-decimal': 2, + 'no-mixed-operators': 2, + 'no-mixed-spaces-and-tabs': [2, 'smart-tabs'], + 'no-multi-spaces': [ + 1, + { + exceptions: { + Property: true, + VariableDeclarator: true, + ImportDeclaration: true + } + } + ], + 'no-multiple-empty-lines': [ + 2, + { + max: 5, + maxEOF: 1 + } + ], + 'no-tabs': 0, + 'no-trailing-spaces': 2, + 'no-whitespace-before-property': 1, + 'nonblock-statement-body-position': 0, + 'object-curly-newline': [ + 1, + { + consistent: true + } + ], + 'object-curly-spacing': [1, 'always'], + 'object-property-newline': [1, { allowAllPropertiesOnSameLine: true }], + 'one-var-declaration-per-line': 0, + 'operator-linebreak': [2, 'after'], + 'padded-blocks': 0, + 'padding-line-between-statements': [ + 2, + + // Blank line always after directives + { + blankLine: 'always', + prev: 'directive', + next: '*' + }, + { + blankLine: 'any', + prev: 'directive', + next: 'directive' + }, + + // Blank line always before "module.exports" and "export" statement + { + blankLine: 'always', + prev: '*', + next: 'cjs-export' + }, + { + blankLine: 'never', + prev: 'cjs-export', + next: 'cjs-export' + }, + { + blankLine: 'always', + prev: '*', + next: 'export' + }, + + // Blank line always after last "require" and "import" statement + { + blankLine: 'always', + prev: 'cjs-import', + next: '*' + }, + { + blankLine: 'any', + prev: 'cjs-import', + next: 'cjs-import' + }, + { + blankLine: 'any', + prev: 'cjs-import', + next: 'import' + }, + { + blankLine: 'always', + prev: 'import', + next: '*' + }, + { + blankLine: 'any', + prev: 'import', + next: 'import' + }, + { + blankLine: 'any', + prev: 'import', + next: 'cjs-import' + } + ], + 'quote-props': [ + 1, + 'consistent-as-needed', + { + keywords: true + } + ], + quotes: [ + 2, + 'single', + { + allowTemplateLiterals: true + } + ], + 'rest-spread-spacing': [2, 'never'], + semi: [2, 'always'], + 'semi-spacing': [ + 1, + { + before: false, + after: true + } + ], + 'semi-style': [2, 'last'], + 'space-before-blocks': [2, 'always'], + 'space-before-function-paren': [2, 'always'], + 'space-in-parens': 0, + 'space-infix-ops': 1, + 'space-unary-ops': [ + 1, + { + words: true, + nonwords: false + } + ], + 'spaced-comment': [ + 1, + 'always', + { + line: { + exceptions: ['-'], + markers: ['/'] + }, + block: { + exceptions: ['-'] + } + } + ], + 'switch-colon-spacing': [1, { before: false, after: true }], + 'template-curly-spacing': [2, 'never'], + 'template-tag-spacing': [2, 'never'], + 'wrap-iife': [2, 'inside'], + 'wrap-regex': 0, + 'yield-star-spacing': [1, 'after'] } }; diff --git a/tests.js b/tests.js index 289a742..4ffe757 100644 --- a/tests.js +++ b/tests.js @@ -4,12 +4,9 @@ module.exports = { env: { mocha: true }, - plugins: ['eslint-plugin-mocha', 'eslint-plugin-promise'], - rules: { 'promise/always-return': 0, - 'mocha/no-exclusive-tests': 1, 'mocha/no-skipped-tests': 1, 'mocha/no-pending-tests': 1, @@ -34,14 +31,8 @@ module.exports = { 'mocha/prefer-arrow-callback': 0, 'mocha/no-empty-description': 2, 'mocha/consistent-spacing-between-blocks': 1, - - // Possible errors 'no-console': 0, - - // Best practices 'no-invalid-this': 0, - - // Stylistic issues 'max-nested-callbacks': [1, 5] } }; diff --git a/typescript.js b/typescript.js index c0e6961..ff4dce8 100644 --- a/typescript.js +++ b/typescript.js @@ -2,13 +2,11 @@ module.exports = { plugins: ['eslint-plugin-jsdoc'], - settings: { jsdoc: { mode: 'typescript' } }, - rules: { 'jsdoc/require-returns': 0, 'jsdoc/require-throws': 0, diff --git a/vue.js b/vue.js index ce06ccd..4722093 100644 --- a/vue.js +++ b/vue.js @@ -1,6 +1,6 @@ 'use strict'; -const path = require('path'); +const path = require('node:path'); const resolveFrom = require('resolve-from'); module.exports = { @@ -8,15 +8,11 @@ module.exports = { path.dirname(require.resolve('eslint-plugin-vue')), 'vue-eslint-parser' ), - parserOptions: { sourceType: 'module' }, - plugins: ['eslint-plugin-vue'], - rules: { - // Other 'no-param-reassign': [ 1, { @@ -24,12 +20,8 @@ module.exports = { ignorePropertyModificationsFor: ['state'] } ], - - // Base rules 'vue/comment-directive': 2, 'vue/jsx-uses-vars': 2, - - // Extension rules 'vue/no-loss-of-precision': 1, 'vue/array-bracket-newline': [1, 'consistent'], 'vue/comma-spacing': [ @@ -83,8 +75,6 @@ module.exports = { keywords: true } ], - - // Essential 'vue/no-useless-template-attributes': 2, 'vue/no-reserved-props': 2, 'vue/no-computed-properties-in-data': 2, @@ -169,8 +159,6 @@ module.exports = { 'vue/valid-v-text': 2, 'vue/no-unused-components': 1, 'vue/require-prop-type-constructor': 2, - - // Strongly recommended 'vue/first-attribute-linebreak': [ 2, { singleline: 'ignore', multiline: 'below' } @@ -207,8 +195,6 @@ module.exports = { 'vue/v-bind-style': [2, 'shorthand'], 'vue/v-on-style': [2, 'shorthand'], 'vue/no-template-shadow': 2, - - // Recommended 'vue/no-multiple-slot-args': 2, 'vue/no-lone-template': 1, 'vue/component-tags-order': [ @@ -218,11 +204,9 @@ module.exports = { 'vue/attributes-order': 2, 'vue/html-quotes': [2, 'double'], 'vue/order-in-components': 2, - 'vue/this-in-template': [1, 'never'], // TODO: review later + 'vue/this-in-template': [1, 'never'], 'vue/no-use-v-if-with-v-for': 2, 'vue/no-v-html': 1, - - // Uncategorized 'vue/prefer-separate-static-class': 0, 'vue/no-v-text': 2, 'vue/no-use-computed-property-like-method': 1, @@ -368,12 +352,9 @@ module.exports = { 'vue/require-typed-ref': 1, 'vue/v-if-else-key': 2, 'vue/valid-define-options': 1, - - // Extension rules 'vue/array-element-newline': [1, 'consistent'], 'vue/no-console': 2 }, - overrides: [ { files: ['*.vue'],