From 0f81063c3d0353a63ef0bdc15faafd3eb498e229 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 3 Aug 2024 17:04:53 +0200 Subject: [PATCH] Migrate deprecated rules to `@stylistic` --- index.js | 1365 +++++++++++++++++++++++----------------------- package.json | 23 +- readme.md | 21 +- space-browser.js | 2 +- space.js | 2 +- test/test.js | 24 +- 6 files changed, 722 insertions(+), 715 deletions(-) diff --git a/index.js b/index.js index 8b16c4f..89ff2bd 100644 --- a/index.js +++ b/index.js @@ -1,700 +1,707 @@ import globals from 'globals'; +import stylistic from '@stylistic/eslint-plugin'; -const config = { - languageOptions: { - sourceType: 'module', - parserOptions: { - ecmaFeatures: { - jsx: true, - }, +const rules = { + '@stylistic/comma-dangle': [ + 'error', + 'always-multiline', + ], + 'for-direction': 'error', + 'getter-return': 'error', + 'no-async-promise-executor': 'error', + 'no-await-in-loop': 'error', + 'no-compare-neg-zero': 'error', + 'no-cond-assign': 'error', + 'no-constant-condition': 'error', + 'no-control-regex': 'error', + 'no-debugger': 'error', + 'no-dupe-args': 'error', + 'no-dupe-else-if': 'error', + 'no-dupe-keys': 'error', + 'no-duplicate-case': 'error', + 'no-empty-character-class': 'error', + 'no-empty': [ + 'error', + { + allowEmptyCatch: true, }, - globals: { - ...globals.es2021, - ...globals.node, + ], + 'no-empty-static-block': 'error', + 'no-ex-assign': 'error', + 'no-extra-boolean-cast': 'error', + // Disabled because of https://github.com/xojs/eslint-config-xo/pull/87 + // 'no-extra-boolean-cast': [ + // 'error', + // { + // enforceForInnerExpressions: true + // }, + // ], + // Disabled because of https://github.com/eslint/eslint/issues/6028 + // '@stylistic/no-extra-parens': [ + // 'error', + // 'all', + // { + // conditionalAssign: false, + // nestedBinaryExpressions: false, + // ignoreJSX: 'multi-line' + // } + // ], + '@stylistic/no-extra-semi': 'error', + 'no-func-assign': 'error', + 'no-import-assign': 'error', + 'no-inner-declarations': 'error', + 'no-invalid-regexp': 'error', + 'no-irregular-whitespace': 'error', + 'no-loss-of-precision': 'error', + 'no-misleading-character-class': 'error', + 'no-obj-calls': 'error', + 'no-promise-executor-return': 'error', + 'no-prototype-builtins': 'error', + 'no-regex-spaces': 'error', + 'no-setter-return': 'error', + 'no-sparse-arrays': 'error', + 'no-template-curly-in-string': 'error', + 'no-unreachable': 'error', + 'no-unreachable-loop': 'error', + 'no-unsafe-finally': 'error', + 'no-unsafe-negation': [ + 'error', + { + enforceForOrderingRelations: true, }, - }, - linterOptions: { - reportUnusedDisableDirectives: 'error', - }, - rules: { - 'comma-dangle': [ - 'error', - 'always-multiline', - ], - 'for-direction': 'error', - 'getter-return': 'error', - 'no-async-promise-executor': 'error', - 'no-await-in-loop': 'error', - 'no-compare-neg-zero': 'error', - 'no-cond-assign': 'error', - 'no-constant-condition': 'error', - 'no-control-regex': 'error', - 'no-debugger': 'error', - 'no-dupe-args': 'error', - 'no-dupe-else-if': 'error', - 'no-dupe-keys': 'error', - 'no-duplicate-case': 'error', - 'no-empty-character-class': 'error', - 'no-empty': [ - 'error', - { - allowEmptyCatch: true, - }, - ], - 'no-empty-static-block': 'error', - 'no-ex-assign': 'error', - 'no-extra-boolean-cast': 'error', - // Disabled because of https://github.com/xojs/eslint-config-xo/pull/87 - // 'no-extra-boolean-cast': [ - // 'error', - // { - // enforceForInnerExpressions: true - // }, - // ], - // Disabled because of https://github.com/eslint/eslint/issues/6028 - // 'no-extra-parens': [ - // 'error', - // 'all', - // { - // conditionalAssign: false, - // nestedBinaryExpressions: false, - // ignoreJSX: 'multi-line' - // } - // ], - 'no-extra-semi': 'error', - 'no-func-assign': 'error', - 'no-import-assign': 'error', - 'no-inner-declarations': 'error', - 'no-invalid-regexp': 'error', - 'no-irregular-whitespace': 'error', - 'no-loss-of-precision': 'error', - 'no-misleading-character-class': 'error', - 'no-obj-calls': 'error', - 'no-promise-executor-return': 'error', - 'no-prototype-builtins': 'error', - 'no-regex-spaces': 'error', - 'no-setter-return': 'error', - 'no-sparse-arrays': 'error', - 'no-template-curly-in-string': 'error', - 'no-unreachable': 'error', - 'no-unreachable-loop': 'error', - 'no-unsafe-finally': 'error', - 'no-unsafe-negation': [ - 'error', - { - enforceForOrderingRelations: true, - }, - ], - 'no-unsafe-optional-chaining': [ - 'error', - { - disallowArithmeticOperators: true, - }, - ], - 'no-useless-backreference': 'error', - 'use-isnan': 'error', - 'valid-typeof': [ - 'error', - { - requireStringLiterals: false, - }, - ], - 'no-unexpected-multiline': 'error', - 'accessor-pairs': [ - 'error', - { - enforceForClassMembers: true, - }, - ], - 'array-callback-return': [ - 'error', - { - allowImplicit: true, - }, - ], - 'block-scoped-var': 'error', - complexity: 'warn', - curly: 'error', - 'default-case': 'error', - 'default-case-last': 'error', - 'dot-notation': 'error', - 'dot-location': [ - 'error', - 'property', - ], - eqeqeq: 'error', - 'grouped-accessor-pairs': [ - 'error', - 'getBeforeSet', - ], - 'guard-for-in': 'error', - 'no-alert': 'error', - 'no-caller': 'error', - 'no-case-declarations': 'error', - 'no-constructor-return': 'error', - 'no-else-return': [ - 'error', - { - allowElseIf: false, - }, - ], - 'no-empty-pattern': 'error', - 'no-eq-null': 'error', - 'no-eval': 'error', - 'no-extend-native': 'error', - 'no-extra-bind': 'error', - 'no-extra-label': 'error', - 'no-fallthrough': 'error', - 'no-floating-decimal': 'error', - 'no-global-assign': 'error', - 'no-implicit-coercion': 'error', - 'no-implicit-globals': 'error', - 'no-implied-eval': 'error', - 'no-iterator': 'error', - 'no-labels': 'error', - 'no-lone-blocks': 'error', - 'no-multi-spaces': 'error', - 'no-multi-str': 'error', - 'no-new-func': 'error', - 'no-new-wrappers': 'error', - 'no-nonoctal-decimal-escape': 'error', - 'no-object-constructor': 'error', - 'no-new': 'error', - 'no-octal-escape': 'error', - 'no-octal': 'error', - 'no-proto': 'error', - 'no-redeclare': 'error', - 'no-return-assign': [ - 'error', - 'always', - ], - 'no-return-await': 'error', - 'no-script-url': 'error', - 'no-self-assign': [ - 'error', - { - props: true, - }, - ], - 'no-self-compare': 'error', - 'no-sequences': 'error', - 'no-throw-literal': 'error', - 'no-unmodified-loop-condition': 'error', - 'no-unused-expressions': [ - 'error', - { - enforceForJSX: true, - }, - ], - 'no-unused-labels': 'error', - 'no-useless-call': 'error', - 'no-useless-catch': 'error', - 'no-useless-concat': 'error', - 'no-useless-escape': 'error', - 'no-useless-return': 'error', - 'no-void': 'error', - 'no-warning-comments': 'warn', - 'no-with': 'error', + ], + 'no-unsafe-optional-chaining': [ + 'error', + { + disallowArithmeticOperators: true, + }, + ], + 'no-useless-backreference': 'error', + 'use-isnan': 'error', + 'valid-typeof': [ + 'error', + { + requireStringLiterals: false, + }, + ], + 'no-unexpected-multiline': 'error', + 'accessor-pairs': [ + 'error', + { + enforceForClassMembers: true, + }, + ], + 'array-callback-return': [ + 'error', + { + allowImplicit: true, + }, + ], + 'block-scoped-var': 'error', + complexity: 'warn', + curly: 'error', + 'default-case': 'error', + 'default-case-last': 'error', + 'dot-notation': 'error', + '@stylistic/dot-location': [ + 'error', + 'property', + ], + eqeqeq: 'error', + 'grouped-accessor-pairs': [ + 'error', + 'getBeforeSet', + ], + 'guard-for-in': 'error', + 'no-alert': 'error', + 'no-caller': 'error', + 'no-case-declarations': 'error', + 'no-constructor-return': 'error', + 'no-else-return': [ + 'error', + { + allowElseIf: false, + }, + ], + 'no-empty-pattern': 'error', + 'no-eq-null': 'error', + 'no-eval': 'error', + 'no-extend-native': 'error', + 'no-extra-bind': 'error', + 'no-extra-label': 'error', + 'no-fallthrough': 'error', + '@stylistic/no-floating-decimal': 'error', + 'no-global-assign': 'error', + 'no-implicit-coercion': 'error', + 'no-implicit-globals': 'error', + 'no-implied-eval': 'error', + 'no-iterator': 'error', + 'no-labels': 'error', + 'no-lone-blocks': 'error', + '@stylistic/no-multi-spaces': 'error', + 'no-multi-str': 'error', + 'no-new-func': 'error', + 'no-new-wrappers': 'error', + 'no-nonoctal-decimal-escape': 'error', + 'no-object-constructor': 'error', + 'no-new': 'error', + 'no-octal-escape': 'error', + 'no-octal': 'error', + 'no-proto': 'error', + 'no-redeclare': 'error', + 'no-return-assign': [ + 'error', + 'always', + ], + 'no-return-await': 'error', + 'no-script-url': 'error', + 'no-self-assign': [ + 'error', + { + props: true, + }, + ], + 'no-self-compare': 'error', + 'no-sequences': 'error', + 'no-throw-literal': 'error', + 'no-unmodified-loop-condition': 'error', + 'no-unused-expressions': [ + 'error', + { + enforceForJSX: true, + }, + ], + 'no-unused-labels': 'error', + 'no-useless-call': 'error', + 'no-useless-catch': 'error', + 'no-useless-concat': 'error', + 'no-useless-escape': 'error', + 'no-useless-return': 'error', + 'no-void': 'error', + 'no-warning-comments': 'warn', + 'no-with': 'error', - // Disabled for now as Firefox doesn't support named capture groups and I'm tired of getting issues about the use of named capture groups... - // 'prefer-named-capture-group': 'error' + // Disabled for now as Firefox doesn't support named capture groups and I'm tired of getting issues about the use of named capture groups... + // 'prefer-named-capture-group': 'error' - 'prefer-promise-reject-errors': [ - 'error', - { - allowEmptyReject: true, - }, - ], - 'prefer-regex-literals': [ - 'error', - { - disallowRedundantWrapping: true, - }, - ], - radix: 'error', + 'prefer-promise-reject-errors': [ + 'error', + { + allowEmptyReject: true, + }, + ], + 'prefer-regex-literals': [ + 'error', + { + disallowRedundantWrapping: true, + }, + ], + radix: 'error', - // Disabled for now as it causes too much churn - // TODO: Enable it in the future when I have time to deal with - // the churn and the rule is stable and has an autofixer. - // Still doesn't have a fixer as of ESLint 7.24.0. - // 'require-unicode-regexp': 'error', + // Disabled for now as it causes too much churn + // TODO: Enable it in the future when I have time to deal with + // the churn and the rule is stable and has an autofixer. + // Still doesn't have a fixer as of ESLint 7.24.0. + // 'require-unicode-regexp': 'error', - 'wrap-iife': [ - 'error', - 'inside', - { - functionPrototypeMethods: true, - }, - ], - yoda: 'error', - 'no-delete-var': 'error', - 'no-label-var': 'error', - 'no-restricted-globals': [ - 'error', - 'event', - // TODO: Enable this in 2025. - // { - // name: 'Buffer', - // message: 'Use Uint8Array instead. See: https://sindresorhus.com/blog/goodbye-nodejs-buffer', - // }, - { - name: 'atob', - message: 'This API is deprecated. Use https://github.com/sindresorhus/uint8array-extras instead.', - }, - { - name: 'btoa', - message: 'This API is deprecated. Use https://github.com/sindresorhus/uint8array-extras instead.', - }, - ], - 'no-shadow-restricted-names': 'error', - 'no-undef-init': 'error', - 'no-undef': [ - 'error', - { - typeof: true, - }, - ], - 'no-unused-vars': [ - 'error', - { - vars: 'all', - varsIgnorePattern: /^_/.source, - args: 'after-used', - ignoreRestSiblings: true, - argsIgnorePattern: /^_/.source, - caughtErrors: 'all', - caughtErrorsIgnorePattern: /^_$/.source, - }, - ], - 'no-buffer-constructor': 'error', - 'no-restricted-imports': [ - 'error', - 'domain', - 'freelist', - 'smalloc', - 'punycode', - 'sys', - 'querystring', - 'colors', - // TODO: Enable this in 2025. - // { - // name: 'buffer', - // message: 'Use Uint8Array instead. See: https://sindresorhus.com/blog/goodbye-nodejs-buffer', - // }, - // { - // name: 'node:buffer', - // message: 'Use Uint8Array instead. See: https://sindresorhus.com/blog/goodbye-nodejs-buffer', - // }, - ], - 'array-bracket-newline': [ - 'error', - 'consistent', - ], - 'array-bracket-spacing': [ - 'error', - 'never', - ], - 'array-element-newline': [ - 'error', - 'consistent', - ], - 'brace-style': [ - 'error', - '1tbs', - { - allowSingleLine: false, - }, - ], - camelcase: [ - 'error', - { - properties: 'always', - }, - ], - 'capitalized-comments': [ - 'error', - 'always', - { - // You can also ignore this rule by wrapping the first word in quotes. - // c8 => https://github.com/bcoe/c8 - ignorePattern: /pragma|ignore|prettier-ignore|webpack\w+:|c8|type-coverage:/.source, - ignoreInlineComments: true, - ignoreConsecutiveComments: true, - }, - ], - 'comma-spacing': [ - 'error', - { - before: false, - after: true, - }, - ], - 'comma-style': [ - 'error', - 'last', - ], - 'computed-property-spacing': [ - 'error', - 'never', - { - enforceForClassMembers: true, - }, - ], - 'eol-last': 'error', - 'func-call-spacing': [ - 'error', - 'never', - ], - 'func-name-matching': [ - 'error', - { - considerPropertyDescriptor: true, - }, - ], - 'func-names': [ - 'error', - 'never', - ], - 'function-call-argument-newline': [ - 'error', - 'consistent', - ], - indent: [ - 'error', - 'tab', - { - SwitchCase: 1, - }, - ], - 'jsx-quotes': [ - 'error', - 'prefer-single', - ], - 'key-spacing': [ - 'error', - { - beforeColon: false, - afterColon: true, - }, - ], - 'keyword-spacing': 'error', - 'linebreak-style': [ - process.platform === 'win32' ? 'off' : 'error', - 'unix', - ], - 'lines-between-class-members': [ - 'error', - { - enforce: [ - { - blankLine: 'always', - prev: '*', - next: 'method', - }, - { - blankLine: 'always', - prev: 'method', - next: 'field', - }, - { - blankLine: 'never', - prev: 'field', - next: 'field', - }, - ], - }, - ], - 'logical-assignment-operators': [ - 'error', - 'always', - { - enforceForIfStatements: true, - }, - ], - 'max-depth': 'warn', - 'max-len': [ - 'warn', - { - code: 200, - ignoreComments: true, - ignoreUrls: true, - }, - ], - 'max-lines': [ - 'warn', - { - max: 1500, - skipComments: true, - }, - ], - 'max-nested-callbacks': [ - 'warn', - 4, - ], - 'max-params': [ - 'warn', - { - max: 4, - }, - ], - 'max-statements-per-line': 'error', - 'new-cap': [ - 'error', - { - newIsCap: true, - capIsNew: true, - }, - ], - 'new-parens': 'error', - 'no-array-constructor': 'error', - 'no-bitwise': 'error', - 'no-lonely-if': 'error', - 'no-mixed-operators': 'error', - 'no-mixed-spaces-and-tabs': 'error', - 'no-multi-assign': 'error', - 'no-multiple-empty-lines': [ - 'error', - { - max: 1, - }, - ], - 'no-negated-condition': 'error', - 'no-whitespace-before-property': 'error', - 'no-trailing-spaces': 'error', - 'no-unneeded-ternary': 'error', - 'object-curly-spacing': [ - 'error', - 'never', - ], - 'object-curly-newline': [ - 'error', - { - ObjectExpression: { - multiline: true, - minProperties: 4, - consistent: true, - }, - ObjectPattern: { - multiline: true, - consistent: true, - }, - ImportDeclaration: { - multiline: true, - minProperties: 4, - consistent: true, - }, - ExportDeclaration: { - multiline: true, - minProperties: 4, - consistent: true, + '@stylistic/wrap-iife': [ + 'error', + 'inside', + { + functionPrototypeMethods: true, + }, + ], + yoda: 'error', + 'no-delete-var': 'error', + 'no-label-var': 'error', + 'no-restricted-globals': [ + 'error', + 'event', + // TODO: Enable this in 2025. + // { + // name: 'Buffer', + // message: 'Use Uint8Array instead. See: https://sindresorhus.com/blog/goodbye-nodejs-buffer', + // }, + { + name: 'atob', + message: 'This API is deprecated. Use https://github.com/sindresorhus/uint8array-extras instead.', + }, + { + name: 'btoa', + message: 'This API is deprecated. Use https://github.com/sindresorhus/uint8array-extras instead.', + }, + ], + 'no-shadow-restricted-names': 'error', + 'no-undef-init': 'error', + 'no-undef': [ + 'error', + { + typeof: true, + }, + ], + 'no-unused-vars': [ + 'error', + { + vars: 'all', + varsIgnorePattern: /^_/.source, + args: 'after-used', + ignoreRestSiblings: true, + argsIgnorePattern: /^_/.source, + caughtErrors: 'all', + caughtErrorsIgnorePattern: /^_$/.source, + }, + ], + 'no-buffer-constructor': 'error', + 'no-restricted-imports': [ + 'error', + 'domain', + 'freelist', + 'smalloc', + 'punycode', + 'sys', + 'querystring', + 'colors', + // TODO: Enable this in 2025. + // { + // name: 'buffer', + // message: 'Use Uint8Array instead. See: https://sindresorhus.com/blog/goodbye-nodejs-buffer', + // }, + // { + // name: 'node:buffer', + // message: 'Use Uint8Array instead. See: https://sindresorhus.com/blog/goodbye-nodejs-buffer', + // }, + ], + '@stylistic/array-bracket-newline': [ + 'error', + 'consistent', + ], + '@stylistic/array-bracket-spacing': [ + 'error', + 'never', + ], + '@stylistic/array-element-newline': [ + 'error', + 'consistent', + ], + '@stylistic/brace-style': [ + 'error', + '1tbs', + { + allowSingleLine: false, + }, + ], + camelcase: [ + 'error', + { + properties: 'always', + }, + ], + 'capitalized-comments': [ + 'error', + 'always', + { + // You can also ignore this rule by wrapping the first word in quotes. + // c8 => https://github.com/bcoe/c8 + ignorePattern: /pragma|ignore|prettier-ignore|webpack\w+:|c8|type-coverage:/.source, + ignoreInlineComments: true, + ignoreConsecutiveComments: true, + }, + ], + '@stylistic/comma-spacing': [ + 'error', + { + before: false, + after: true, + }, + ], + '@stylistic/comma-style': [ + 'error', + 'last', + ], + '@stylistic/computed-property-spacing': [ + 'error', + 'never', + { + enforceForClassMembers: true, + }, + ], + '@stylistic/eol-last': 'error', + '@stylistic/func-call-spacing': [ + 'error', + 'never', + ], + 'func-name-matching': [ + 'error', + { + considerPropertyDescriptor: true, + }, + ], + 'func-names': [ + 'error', + 'never', + ], + '@stylistic/function-call-argument-newline': [ + 'error', + 'consistent', + ], + '@stylistic/indent': [ + 'error', + 'tab', + { + SwitchCase: 1, + }, + ], + '@stylistic/jsx-quotes': [ + 'error', + 'prefer-single', + ], + '@stylistic/key-spacing': [ + 'error', + { + beforeColon: false, + afterColon: true, + }, + ], + '@stylistic/keyword-spacing': 'error', + '@stylistic/linebreak-style': [ + process.platform === 'win32' ? 'off' : 'error', + 'unix', + ], + '@stylistic/lines-between-class-members': [ + 'error', + { + enforce: [ + { + blankLine: 'always', + prev: '*', + next: 'method', }, - }, - ], - 'one-var': [ - 'error', - 'never', - ], - 'one-var-declaration-per-line': 'error', - 'operator-assignment': [ - 'error', - 'always', - ], - 'operator-linebreak': [ - 'error', - 'before', - ], - 'padded-blocks': [ - 'error', - 'never', - { - allowSingleLineBlocks: false, - }, - ], - 'padding-line-between-statements': [ - 'error', - { - blankLine: 'always', - prev: 'multiline-block-like', - next: '*', - }, - ], - 'prefer-exponentiation-operator': 'error', - 'prefer-object-spread': 'error', - 'quote-props': [ - 'error', - 'as-needed', - ], - quotes: [ - 'error', - 'single', - ], - 'semi-spacing': [ - 'error', - { - before: false, - after: true, - }, - ], - 'semi-style': [ - 'error', - 'last', - ], - semi: [ - 'error', - 'always', - ], - 'space-before-blocks': [ - 'error', - 'always', - ], - 'space-before-function-paren': [ - 'error', - { - anonymous: 'always', - named: 'never', - asyncArrow: 'always', - }, - ], - 'space-in-parens': [ - 'error', - 'never', - ], - 'space-infix-ops': 'error', - 'space-unary-ops': 'error', - 'spaced-comment': [ - 'error', - 'always', - { - line: { - exceptions: [ - '-', - '+', - '*', - ], - markers: [ - '!', - '/', - '=>', - ], + { + blankLine: 'always', + prev: 'method', + next: 'field', }, - block: { - exceptions: [ - '-', - '+', - '*', - ], - markers: [ - '!', - '*', - ], - balanced: true, + { + blankLine: 'never', + prev: 'field', + next: 'field', }, + ], + }, + ], + 'logical-assignment-operators': [ + 'error', + 'always', + { + enforceForIfStatements: true, + }, + ], + 'max-depth': 'warn', + '@stylistic/max-len': [ + 'warn', + { + code: 200, + ignoreComments: true, + ignoreUrls: true, + }, + ], + 'max-lines': [ + 'warn', + { + max: 1500, + skipComments: true, + }, + ], + 'max-nested-callbacks': [ + 'warn', + 4, + ], + 'max-params': [ + 'warn', + { + max: 4, + }, + ], + '@stylistic/max-statements-per-line': 'error', + 'new-cap': [ + 'error', + { + newIsCap: true, + capIsNew: true, + }, + ], + '@stylistic/new-parens': 'error', + 'no-array-constructor': 'error', + 'no-bitwise': 'error', + 'no-lonely-if': 'error', + '@stylistic/no-mixed-operators': 'error', + '@stylistic/no-mixed-spaces-and-tabs': 'error', + 'no-multi-assign': 'error', + '@stylistic/no-multiple-empty-lines': [ + 'error', + { + max: 1, + }, + ], + 'no-negated-condition': 'error', + '@stylistic/no-whitespace-before-property': 'error', + '@stylistic/no-trailing-spaces': 'error', + 'no-unneeded-ternary': 'error', + '@stylistic/object-curly-spacing': [ + 'error', + 'never', + ], + '@stylistic/object-curly-newline': [ + 'error', + { + ObjectExpression: { + multiline: true, + minProperties: 4, + consistent: true, + }, + ObjectPattern: { + multiline: true, + consistent: true, + }, + ImportDeclaration: { + multiline: true, + minProperties: 4, + consistent: true, + }, + ExportDeclaration: { + multiline: true, + minProperties: 4, + consistent: true, }, - ], - 'switch-colon-spacing': [ - 'error', - { - after: true, - before: false, - }, - ], - 'template-tag-spacing': [ - 'error', - 'never', - ], - 'unicode-bom': [ - 'error', - 'never', - ], - 'arrow-body-style': 'error', - 'arrow-parens': [ - 'error', - 'as-needed', - ], - 'arrow-spacing': [ - 'error', - { - before: true, - after: true, - }, - ], - 'constructor-super': 'error', - 'generator-star-spacing': [ - 'error', - 'both', - ], - 'no-class-assign': 'error', - 'no-const-assign': 'error', - 'no-constant-binary-expression': 'error', - 'no-dupe-class-members': 'error', - 'no-new-native-nonconstructor': 'error', - 'no-this-before-super': 'error', - 'no-useless-computed-key': [ - 'error', - { - enforceForClassMembers: true, - }, - ], - 'no-useless-constructor': 'error', - 'no-useless-rename': 'error', - 'no-var': 'error', - 'object-shorthand': [ - 'error', - 'always', - { - avoidExplicitReturnArrows: true, - }, - ], - 'prefer-arrow-callback': [ - 'error', - { - allowNamedFunctions: true, + }, + ], + 'one-var': [ + 'error', + 'never', + ], + '@stylistic/one-var-declaration-per-line': 'error', + 'operator-assignment': [ + 'error', + 'always', + ], + '@stylistic/operator-linebreak': [ + 'error', + 'before', + ], + '@stylistic/padded-blocks': [ + 'error', + 'never', + { + allowSingleLineBlocks: false, + }, + ], + '@stylistic/padding-line-between-statements': [ + 'error', + { + blankLine: 'always', + prev: 'multiline-block-like', + next: '*', + }, + ], + 'prefer-exponentiation-operator': 'error', + 'prefer-object-spread': 'error', + '@stylistic/quote-props': [ + 'error', + 'as-needed', + ], + '@stylistic/quotes': [ + 'error', + 'single', + ], + '@stylistic/semi-spacing': [ + 'error', + { + before: false, + after: true, + }, + ], + '@stylistic/semi-style': [ + 'error', + 'last', + ], + '@stylistic/semi': [ + 'error', + 'always', + ], + '@stylistic/space-before-blocks': [ + 'error', + 'always', + ], + '@stylistic/space-before-function-paren': [ + 'error', + { + anonymous: 'always', + named: 'never', + asyncArrow: 'always', + }, + ], + '@stylistic/space-in-parens': [ + 'error', + 'never', + ], + '@stylistic/space-infix-ops': 'error', + '@stylistic/space-unary-ops': 'error', + '@stylistic/spaced-comment': [ + 'error', + 'always', + { + line: { + exceptions: [ + '-', + '+', + '*', + ], + markers: [ + '!', + '/', + '=>', + ], }, - ], - 'prefer-const': [ - 'error', - { - destructuring: 'all', + block: { + exceptions: [ + '-', + '+', + '*', + ], + markers: [ + '!', + '*', + ], + balanced: true, }, - ], - 'prefer-destructuring': [ - 'error', - { - // `array` is disabled because it forces destructuring on - // stupid stuff like `foo.bar = process.argv[2];` - // TODO: Open ESLint issue about this - VariableDeclarator: { - array: false, - object: true, - }, - AssignmentExpression: { - array: false, + }, + ], + '@stylistic/switch-colon-spacing': [ + 'error', + { + after: true, + before: false, + }, + ], + '@stylistic/template-tag-spacing': [ + 'error', + 'never', + ], + 'unicode-bom': [ + 'error', + 'never', + ], + 'arrow-body-style': 'error', + '@stylistic/arrow-parens': [ + 'error', + 'as-needed', + ], + '@stylistic/arrow-spacing': [ + 'error', + { + before: true, + after: true, + }, + ], + 'constructor-super': 'error', + '@stylistic/generator-star-spacing': [ + 'error', + 'both', + ], + 'no-class-assign': 'error', + 'no-const-assign': 'error', + 'no-constant-binary-expression': 'error', + 'no-dupe-class-members': 'error', + 'no-new-native-nonconstructor': 'error', + 'no-this-before-super': 'error', + 'no-useless-computed-key': [ + 'error', + { + enforceForClassMembers: true, + }, + ], + 'no-useless-constructor': 'error', + 'no-useless-rename': 'error', + 'no-var': 'error', + 'object-shorthand': [ + 'error', + 'always', + { + avoidExplicitReturnArrows: true, + }, + ], + 'prefer-arrow-callback': [ + 'error', + { + allowNamedFunctions: true, + }, + ], + 'prefer-const': [ + 'error', + { + destructuring: 'all', + }, + ], + 'prefer-destructuring': [ + 'error', + { + // `array` is disabled because it forces destructuring on + // stupid stuff like `foo.bar = process.argv[2];` + // TODO: Open ESLint issue about this + VariableDeclarator: { + array: false, + object: true, + }, + AssignmentExpression: { + array: false, - // Disabled because object assignment destructuring requires parens wrapping: - // `let foo; ({foo} = object);` - object: false, - }, + // Disabled because object assignment destructuring requires parens wrapping: + // `let foo; ({foo} = object);` + object: false, }, - { - enforceForRenamedProperties: false, + }, + { + enforceForRenamedProperties: false, + }, + ], + 'prefer-numeric-literals': 'error', + 'prefer-object-has-own': 'error', + 'prefer-rest-params': 'error', + 'prefer-spread': 'error', + 'require-yield': 'error', + '@stylistic/rest-spread-spacing': [ + 'error', + 'never', + ], + 'symbol-description': 'error', + '@stylistic/template-curly-spacing': 'error', + '@stylistic/yield-star-spacing': [ + 'error', + 'both', + ], +}; + +const config = { + languageOptions: { + globals: { + ...globals.es2021, + ...globals.nodeBuiltin, + }, + ecmaVersion: 'latest', + sourceType: 'module', + parserOptions: { + ecmaFeatures: { + jsx: true, }, - ], - 'prefer-numeric-literals': 'error', - 'prefer-object-has-own': 'error', - 'prefer-rest-params': 'error', - 'prefer-spread': 'error', - 'require-yield': 'error', - 'rest-spread-spacing': [ - 'error', - 'never', - ], - 'symbol-description': 'error', - 'template-curly-spacing': 'error', - 'yield-star-spacing': [ - 'error', - 'both', - ], + }, + }, + linterOptions: { + reportUnusedDisableDirectives: 'error', + }, + plugins: { + '@stylistic': stylistic, }, + rules, }; export default [config]; diff --git a/package.json b/package.json index efa0cdd..f0fb23b 100644 --- a/package.json +++ b/package.json @@ -3,13 +3,6 @@ "version": "0.45.0", "description": "ESLint shareable config for XO", "license": "MIT", - "type": "module", - "exports": { - ".": "./index.js", - "./browser": "./browser.js", - "./space": "./space.js", - "./space/browser": "./space-browser.js" - }, "repository": "xojs/eslint-config-xo", "funding": "https://github.com/sponsors/sindresorhus", "author": { @@ -17,12 +10,19 @@ "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, + "type": "module", + "exports": { + ".": "./index.js", + "./browser": "./browser.js", + "./space": "./space.js", + "./space/browser": "./space-browser.js" + }, "sideEffects": false, "engines": { - "node": ">=18" + "node": ">=18.18" }, "scripts": { - "test": "eslint . && ava" + "test": "eslint && ava" }, "files": [ "index.js", @@ -59,14 +59,15 @@ "simple" ], "dependencies": { + "@stylistic/eslint-plugin": "^2.6.1", "confusing-browser-globals": "1.0.11", "globals": "^15.3.0" }, "devDependencies": { "ava": "^6.1.3", - "eslint": "^9.4.0" + "eslint": "^9.8.0" }, "peerDependencies": { - "eslint": ">=8.56.0" + "eslint": ">=9.8.0" } } diff --git a/readme.md b/readme.md index b8c2303..7d80191 100644 --- a/readme.md +++ b/readme.md @@ -16,43 +16,42 @@ npm install --save-dev eslint-config-xo ## Usage -Add some ESLint config to your `eslint.config.js`: - ```js -import eslintConfigXo from 'eslint-config-xo'; +// eslint.config.js +import xo from 'eslint-config-xo'; export default [ - ...eslintConfigXo, + ...xo, ]; ``` This package also exposes [`eslint-config-xo/browser`](browser.js) if you're in the browser: ```js -import eslintConfigXoBrowser from 'eslint-config-xo/browser'; +import xoBrowser from 'eslint-config-xo/browser'; export default [ - ...eslintConfigXoBrowser, + ...xoBrowser, ]; ``` This package also exposes [`eslint-config-xo/space`](space.js) if you're in favor of 2-space indent: ```js -import eslintConfigXoSpace from 'eslint-config-xo/space'; +import xoSpace from 'eslint-config-xo/space'; export default [ - ...eslintConfigXoSpace, + ...xoSpace, ]; ``` This package also exposes [`eslint-config-xo/space/browser`](space-browser.js) if you're in favor of 2-space indent and in browser: ```js -import eslintConfigXoSpaceBrowser from 'eslint-config-xo/space/browser'; +import xoSpaceBrowser from 'eslint-config-xo/space/browser'; export default [ - ...eslintConfigXoSpaceBrowser, + ...xoSpaceBrowser, ]; ``` @@ -77,5 +76,5 @@ tl;dr You miss out on a lot by just using this config. ## Related - [eslint-config-xo-space](https://github.com/xojs/eslint-config-xo-space) - ESLint shareable config for XO with 2-space indent -- [eslint-config-xo-react](https://github.com/xojs/eslint-config-xo-react) - ESLint shareable config for React to be used with this config - [eslint-config-xo-typescript](https://github.com/xojs/eslint-config-xo-typescript) - ESLint shareable config for TypeScript to be used with this config +- [eslint-config-xo-react](https://github.com/xojs/eslint-config-xo-react) - ESLint shareable config for React to be used with this config diff --git a/space-browser.js b/space-browser.js index 551a610..2e92eb5 100644 --- a/space-browser.js +++ b/space-browser.js @@ -7,7 +7,7 @@ export default [ ...config, rules: { ...config.rules, - indent: [ + '@stylistic/indent': [ 'error', 2, { diff --git a/space.js b/space.js index f701655..3ec8530 100644 --- a/space.js +++ b/space.js @@ -7,7 +7,7 @@ export default [ ...config, rules: { ...config.rules, - indent: [ + '@stylistic/indent': [ 'error', 2, { diff --git a/test/test.js b/test/test.js index 472130c..5ac49d4 100644 --- a/test/test.js +++ b/test/test.js @@ -1,9 +1,9 @@ import test from 'ava'; import {ESLint} from 'eslint'; -import eslintConfigXoNode from '../index.js'; -import eslintConfigXoBrowser from '../browser.js'; -import eslintConfigXoSpaceNode from '../space.js'; -import eslintConfigXoSpaceBrowser from '../space-browser.js'; +import configXoNode from '../index.js'; +import configXoBrowser from '../browser.js'; +import configXoSpaceNode from '../space.js'; +import configXoSpaceBrowser from '../space-browser.js'; const hasRule = (errors, ruleId) => errors.some(error => error.ruleId === ruleId); @@ -19,17 +19,17 @@ async function runEslint(string, config) { } test('node', async t => { - for (const config of [eslintConfigXoNode, eslintConfigXoSpaceNode]) { + for (const config of [configXoNode, configXoSpaceNode]) { t.true(Array.isArray(config)); // eslint-disable-next-line no-await-in-loop const errors = await runEslint('\'use strict\';\nconsole.log("unicorn")\n', config); - t.true(hasRule(errors, 'quotes'), JSON.stringify(errors)); + t.true(hasRule(errors, '@stylistic/quotes'), JSON.stringify(errors)); } }); test('browser', async t => { - for (const config of [eslintConfigXoBrowser, eslintConfigXoSpaceBrowser]) { + for (const config of [configXoBrowser, configXoSpaceBrowser]) { t.true(Array.isArray(config)); // eslint-disable-next-line no-await-in-loop @@ -50,24 +50,24 @@ export function foo() { config, } of [ { - config: eslintConfigXoSpaceNode, + config: configXoSpaceNode, expected: true, }, { - config: eslintConfigXoSpaceBrowser, + config: configXoSpaceBrowser, expected: true, }, { - config: eslintConfigXoNode, + config: configXoNode, expected: false, }, { - config: eslintConfigXoBrowser, + config: configXoBrowser, expected: false, }, ]) { // eslint-disable-next-line no-await-in-loop const errors = await runEslint(fixture, config); - t.is(hasRule(errors, 'indent'), expected, JSON.stringify(errors)); + t.is(hasRule(errors, '@stylistic/indent'), expected, JSON.stringify(errors)); } });