From a9ad1a4ca7285dfd46d540fb87a097e6b7194584 Mon Sep 17 00:00:00 2001 From: Abraham Guo Date: Fri, 22 Dec 2023 11:08:47 -0600 Subject: [PATCH] WIP --- .eslintrc.js | 3 + .gitignore | 1 + README.md | 26 ++++- eslint.base.config.js | 11 ++ eslint.config.js | 22 ++-- index.js | 180 +++++++++++++++++++++++++++++ package-lock.json | 206 +++++++++++++++++----------------- package.json | 1 + scripts/generate-stylistic.js | 99 ++++++++++------ test-lint/@stylistic.js | 6 + 10 files changed, 403 insertions(+), 152 deletions(-) create mode 100644 test-lint/@stylistic.js diff --git a/.eslintrc.js b/.eslintrc.js index 5ecbea2..786c5f4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -32,6 +32,9 @@ module.exports = { { avoidEscape: true, allowTemplateLiterals: false }, ], }, + parserOptions: { + ecmaVersion: "latest", + }, }, { files: ["**/*.test.js"], diff --git a/.gitignore b/.gitignore index fbad133..06798c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /build/ /node_modules/ /test-config/ +/.idea/ \ No newline at end of file diff --git a/README.md b/README.md index 259d354..ab435de 100644 --- a/README.md +++ b/README.md @@ -277,7 +277,7 @@ Example ESLint configuration: ### [lines-around-comment] \(deprecated) -(The following applies to [@typescript-eslint/lines-around-comment] as well.) +(The following applies to [@stylistic/lines-around-comment], [@stylistic/js/lines-around-comment], [@stylistic/ts/lines-around-comment], and[@typescript-eslint/lines-around-comment] as well.) **This rule can be used with certain options.** @@ -336,7 +336,7 @@ Example ESLint configuration: ### [max-len] \(deprecated) -(The following applies to [vue/max-len] as well.) +(The following applies to [@stylistic/max-len], [@stylistic/js/max-len], and [vue/max-len] as well.) **This rule requires special attention when writing code.** @@ -359,6 +359,8 @@ Example ESLint configuration: ### [no-confusing-arrow] \(deprecated) +(The following applies to [@stylistic/no-confusing-arrow] and [@stylistic/js/no-confusing-arrow] as well.) + **This rule requires certain options.** For example, the rule could warn about this line: @@ -409,6 +411,8 @@ Example ESLint configuration: ### [no-mixed-operators] \(deprecated) +(The following applies to [@stylistic/no-mixed-operators] and [@stylistic/js/no-mixed-operators] as well.) + **This rule requires special attention when writing code.** This rule forbids mixing certain operators, such as `&&` and `||`. @@ -462,6 +466,8 @@ Example ESLint configuration: ### [no-tabs] \(deprecated) +(The following applies to [@stylistic/no-tabs] and [@stylistic/js/no-tabs] as well.) + **This rule requires certain options.** This rule disallows the use of tab characters. By default the rule forbids _all_ tab characters. That can be used just fine with Prettier as long as you don’t configure Prettier to indent using tabs. @@ -548,7 +554,7 @@ Example configuration: ### [quotes] \(deprecated) -(The following applies to [babel/quotes] and [@typescript-eslint/quotes] as well.) +(The following applies to [babel/quotes], [@stylistic/quotes], [@stylistic/js/quotes], [@stylistic/ts/quotes], and [@typescript-eslint/quotes] as well.) **This rule requires certain options and certain Prettier options.** @@ -853,6 +859,20 @@ When you’re done, run `npm test` to verify that you got it all right. It runs [MIT](LICENSE). [@babel/eslint-plugin]: https://github.com/babel/babel/tree/main/eslint/babel-eslint-plugin +[@stylistic/lines-around-comment]: https://eslint.style/rules/default/lines-around-comment +[@stylistic/js/lines-around-comment]: https://eslint.style/rules/js/lines-around-comment +[@stylistic/ts/lines-around-comment]: https://eslint.style/rules/ts/lines-around-comment +[@stylistic/max-len]: https://eslint.style/rules/default/max-len +[@stylistic/js/max-len]: https://eslint.style/rules/js/max-len +[@stylistic/no-confusing-arrow]: https://eslint.style/rules/default/no-confusing-arrow +[@stylistic/js/no-confusing-arrow]: https://eslint.style/rules/js/no-confusing-arrow +[@stylistic/no-mixed-operators]: https://eslint.style/rules/default/no-mixed-operators +[@stylistic/js/no-mixed-operators]: https://eslint.style/rules/js/no-mixed-operators +[@stylistic/no-tabs]: https://eslint.style/rules/default/no-tabs +[@stylistic/js/no-tabs]: https://eslint.style/rules/js/no-tabs +[@stylistic/quotes]: https://eslint.style/rules/default/quotes +[@stylistic/js/quotes]: https://eslint.style/rules/js/quotes +[@stylistic/ts/quotes]: https://eslint.style/rules/ts/quotes [@typescript-eslint/eslint-plugin]: https://github.com/typescript-eslint/typescript-eslint [@typescript-eslint/lines-around-comment]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/lines-around-comment.md [@typescript-eslint/quotes]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/quotes.md diff --git a/eslint.base.config.js b/eslint.base.config.js index 1dd2330..4843901 100644 --- a/eslint.base.config.js +++ b/eslint.base.config.js @@ -15,6 +15,10 @@ const google = require("eslint-config-google"); const prettier = require("eslint-plugin-prettier"); const react = require("eslint-plugin-react"); const standard = require("eslint-plugin-standard"); +const stylistic = require("@stylistic/eslint-plugin"); +const stylisticJs = require("@stylistic/eslint-plugin-js"); +const stylisticTs = require("@stylistic/eslint-plugin-ts"); +const stylisticJsx = require("@stylistic/eslint-plugin-jsx"); const typescriptEslint = require("@typescript-eslint/eslint-plugin"); const unicorn = require("eslint-plugin-unicorn"); const vue = require("eslint-plugin-vue"); @@ -42,6 +46,10 @@ module.exports = [ prettier, react, standard, + "@stylistic": stylistic, + "@stylistic/js": stylisticJs, + "@stylistic/ts": stylisticTs, + "@stylistic/jsx": stylisticJsx, unicorn, vue, }, @@ -53,6 +61,9 @@ module.exports = [ { rules: react.configs.all.rules, }, + { + rules: stylistic.configs["all-flat"].rules, + }, { rules: unicorn.configs.recommended.rules, }, diff --git a/eslint.config.js b/eslint.config.js index 3678394..1f2b6d2 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -21,13 +21,17 @@ module.exports = [ { rules: eslintrc.rules, }, - ...eslintrc.overrides.map(({ env = {}, ...override }) => ({ - ...override, - languageOptions: { - globals: Object.entries(env).reduce( - (acc, [key, enabled]) => (enabled ? { ...acc, ...globals[key] } : acc), - {} - ), - }, - })), + ...eslintrc.overrides.map( + ({ env = {}, parserOptions = {}, ...override }) => ({ + ...override, + languageOptions: { + globals: Object.entries(env).reduce( + (acc, [key, enabled]) => + enabled ? { ...acc, ...globals[key] } : acc, + {} + ), + parserOptions, + }, + }) + ), ]; diff --git a/index.js b/index.js index 73e4f71..6bde09f 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,20 @@ module.exports = { // in the deprecated section below. "curly": specialRule, "no-unexpected-multiline": specialRule, + "@stylistic/lines-around-comment": specialRule, + "@stylistic/max-len": specialRule, + "@stylistic/no-confusing-arrow": specialRule, + "@stylistic/no-mixed-operators": specialRule, + "@stylistic/no-tabs": specialRule, + "@stylistic/quotes": specialRule, + "@stylistic/js/lines-around-comment": specialRule, + "@stylistic/js/max-len": specialRule, + "@stylistic/js/no-confusing-arrow": specialRule, + "@stylistic/js/no-mixed-operators": specialRule, + "@stylistic/js/no-tabs": specialRule, + "@stylistic/js/quotes": specialRule, + "@stylistic/ts/lines-around-comment": specialRule, + "@stylistic/ts/quotes": specialRule, "@typescript-eslint/lines-around-comment": specialRule, "@typescript-eslint/quotes": specialRule, "babel/quotes": specialRule, @@ -22,6 +36,172 @@ module.exports = { // The rest are rules that you never need to enable when using Prettier. "@babel/object-curly-spacing": "off", "@babel/semi": "off", + "@stylistic/array-bracket-newline": "off", + "@stylistic/array-bracket-spacing": "off", + "@stylistic/array-element-newline": "off", + "@stylistic/arrow-parens": "off", + "@stylistic/arrow-spacing": "off", + "@stylistic/block-spacing": "off", + "@stylistic/brace-style": "off", + "@stylistic/comma-dangle": "off", + "@stylistic/comma-spacing": "off", + "@stylistic/comma-style": "off", + "@stylistic/computed-property-spacing": "off", + "@stylistic/dot-location": "off", + "@stylistic/eol-last": "off", + "@stylistic/func-call-spacing": "off", + "@stylistic/function-call-argument-newline": "off", + "@stylistic/function-call-spacing": "off", + "@stylistic/function-paren-newline": "off", + "@stylistic/generator-star-spacing": "off", + "@stylistic/implicit-arrow-linebreak": "off", + "@stylistic/indent": "off", + "@stylistic/jsx-quotes": "off", + "@stylistic/key-spacing": "off", + "@stylistic/keyword-spacing": "off", + "@stylistic/linebreak-style": "off", + "@stylistic/max-statements-per-line": "off", + "@stylistic/multiline-ternary": "off", + "@stylistic/new-parens": "off", + "@stylistic/newline-per-chained-call": "off", + "@stylistic/no-extra-parens": "off", + "@stylistic/no-extra-semi": "off", + "@stylistic/no-floating-decimal": "off", + "@stylistic/no-mixed-spaces-and-tabs": "off", + "@stylistic/no-multi-spaces": "off", + "@stylistic/no-multiple-empty-lines": "off", + "@stylistic/no-trailing-spaces": "off", + "@stylistic/no-whitespace-before-property": "off", + "@stylistic/nonblock-statement-body-position": "off", + "@stylistic/object-curly-newline": "off", + "@stylistic/object-curly-spacing": "off", + "@stylistic/object-property-newline": "off", + "@stylistic/one-var-declaration-per-line": "off", + "@stylistic/operator-linebreak": "off", + "@stylistic/padded-blocks": "off", + "@stylistic/quote-props": "off", + "@stylistic/rest-spread-spacing": "off", + "@stylistic/semi": "off", + "@stylistic/semi-spacing": "off", + "@stylistic/semi-style": "off", + "@stylistic/space-before-blocks": "off", + "@stylistic/space-before-function-paren": "off", + "@stylistic/space-in-parens": "off", + "@stylistic/space-infix-ops": "off", + "@stylistic/space-unary-ops": "off", + "@stylistic/switch-colon-spacing": "off", + "@stylistic/template-curly-spacing": "off", + "@stylistic/template-tag-spacing": "off", + "@stylistic/wrap-iife": "off", + "@stylistic/wrap-regex": "off", + "@stylistic/yield-star-spacing": "off", + "@stylistic/member-delimiter-style": "off", + "@stylistic/type-annotation-spacing": "off", + "@stylistic/jsx-child-element-spacing": "off", + "@stylistic/jsx-closing-bracket-location": "off", + "@stylistic/jsx-closing-tag-location": "off", + "@stylistic/jsx-curly-newline": "off", + "@stylistic/jsx-curly-spacing": "off", + "@stylistic/jsx-equals-spacing": "off", + "@stylistic/jsx-first-prop-new-line": "off", + "@stylistic/jsx-indent": "off", + "@stylistic/jsx-indent-props": "off", + "@stylistic/jsx-max-props-per-line": "off", + "@stylistic/jsx-newline": "off", + "@stylistic/jsx-one-expression-per-line": "off", + "@stylistic/jsx-props-no-multi-spaces": "off", + "@stylistic/jsx-tag-spacing": "off", + "@stylistic/jsx-wrap-multilines": "off", + "@stylistic/indent-binary-ops": "off", + "@stylistic/type-generic-spacing": "off", + "@stylistic/type-named-tuple-spacing": "off", + "@stylistic/js/array-bracket-newline": "off", + "@stylistic/js/array-bracket-spacing": "off", + "@stylistic/js/array-element-newline": "off", + "@stylistic/js/arrow-parens": "off", + "@stylistic/js/arrow-spacing": "off", + "@stylistic/js/block-spacing": "off", + "@stylistic/js/brace-style": "off", + "@stylistic/js/comma-dangle": "off", + "@stylistic/js/comma-spacing": "off", + "@stylistic/js/comma-style": "off", + "@stylistic/js/computed-property-spacing": "off", + "@stylistic/js/dot-location": "off", + "@stylistic/js/eol-last": "off", + "@stylistic/js/func-call-spacing": "off", + "@stylistic/js/function-call-argument-newline": "off", + "@stylistic/js/function-call-spacing": "off", + "@stylistic/js/function-paren-newline": "off", + "@stylistic/js/generator-star-spacing": "off", + "@stylistic/js/implicit-arrow-linebreak": "off", + "@stylistic/js/indent": "off", + "@stylistic/js/jsx-quotes": "off", + "@stylistic/js/key-spacing": "off", + "@stylistic/js/keyword-spacing": "off", + "@stylistic/js/linebreak-style": "off", + "@stylistic/js/max-statements-per-line": "off", + "@stylistic/js/multiline-ternary": "off", + "@stylistic/js/new-parens": "off", + "@stylistic/js/newline-per-chained-call": "off", + "@stylistic/js/no-extra-parens": "off", + "@stylistic/js/no-extra-semi": "off", + "@stylistic/js/no-floating-decimal": "off", + "@stylistic/js/no-mixed-spaces-and-tabs": "off", + "@stylistic/js/no-multi-spaces": "off", + "@stylistic/js/no-multiple-empty-lines": "off", + "@stylistic/js/no-trailing-spaces": "off", + "@stylistic/js/no-whitespace-before-property": "off", + "@stylistic/js/nonblock-statement-body-position": "off", + "@stylistic/js/object-curly-newline": "off", + "@stylistic/js/object-curly-spacing": "off", + "@stylistic/js/object-property-newline": "off", + "@stylistic/js/one-var-declaration-per-line": "off", + "@stylistic/js/operator-linebreak": "off", + "@stylistic/js/padded-blocks": "off", + "@stylistic/js/quote-props": "off", + "@stylistic/js/rest-spread-spacing": "off", + "@stylistic/js/semi": "off", + "@stylistic/js/semi-spacing": "off", + "@stylistic/js/semi-style": "off", + "@stylistic/js/space-before-blocks": "off", + "@stylistic/js/space-before-function-paren": "off", + "@stylistic/js/space-in-parens": "off", + "@stylistic/js/space-infix-ops": "off", + "@stylistic/js/space-unary-ops": "off", + "@stylistic/js/switch-colon-spacing": "off", + "@stylistic/js/template-curly-spacing": "off", + "@stylistic/js/template-tag-spacing": "off", + "@stylistic/js/wrap-iife": "off", + "@stylistic/js/wrap-regex": "off", + "@stylistic/js/yield-star-spacing": "off", + "@stylistic/ts/block-spacing": "off", + "@stylistic/ts/brace-style": "off", + "@stylistic/ts/comma-dangle": "off", + "@stylistic/ts/comma-spacing": "off", + "@stylistic/ts/func-call-spacing": "off", + "@stylistic/ts/function-call-spacing": "off", + "@stylistic/ts/indent": "off", + "@stylistic/ts/key-spacing": "off", + "@stylistic/ts/keyword-spacing": "off", + "@stylistic/ts/member-delimiter-style": "off", + "@stylistic/ts/no-extra-parens": "off", + "@stylistic/ts/no-extra-semi": "off", + "@stylistic/ts/object-curly-spacing": "off", + "@stylistic/ts/semi": "off", + "@stylistic/ts/space-before-blocks": "off", + "@stylistic/ts/space-before-function-paren": "off", + "@stylistic/ts/space-infix-ops": "off", + "@stylistic/ts/type-annotation-spacing": "off", + "@stylistic/jsx/jsx-child-element-spacing": "off", + "@stylistic/jsx/jsx-closing-bracket-location": "off", + "@stylistic/jsx/jsx-closing-tag-location": "off", + "@stylistic/jsx/jsx-curly-newline": "off", + "@stylistic/jsx/jsx-curly-spacing": "off", + "@stylistic/jsx/jsx-equals-spacing": "off", + "@stylistic/jsx/jsx-first-prop-new-line": "off", + "@stylistic/jsx/jsx-indent": "off", + "@stylistic/jsx/jsx-indent-props": "off", + "@stylistic/jsx/jsx-max-props-per-line": "off", "@typescript-eslint/block-spacing": "off", "@typescript-eslint/brace-style": "off", "@typescript-eslint/comma-dangle": "off", diff --git a/package-lock.json b/package-lock.json index 8d49b0f..0f10acf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "@babel/plugin-syntax-flow": "7.23.3", "@babel/plugin-syntax-jsx": "7.23.3", "@babel/plugin-transform-react-jsx": "7.23.4", - "@stylistic/eslint-plugin": "^1.5.0", + "@stylistic/eslint-plugin": "1.5.1", "@typescript-eslint/eslint-plugin": "6.13.1", "@typescript-eslint/parser": "6.13.1", "eslint": "8.55.0", @@ -75,21 +75,21 @@ } }, "node_modules/@babel/core": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.5.tgz", - "integrity": "sha512-Cwc2XjUrG4ilcfOw4wBAK+enbdgwAcAJCfGUItPBKR7Mjw4aEfAFYrLxeRp4jWgtNIKn3n2AlBOfwwafl+42/g==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.6.tgz", + "integrity": "sha512-FxpRyGjrMJXh7X3wGLGhNDCRiwpWEF74sKjTLDJSG5Kyvow3QZaG0Adbqzi9ZrVjTWpsX+2cxWXD71NMg93kdw==", "dev": true, "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.23.5", - "@babel/generator": "^7.23.5", - "@babel/helper-compilation-targets": "^7.22.15", + "@babel/generator": "^7.23.6", + "@babel/helper-compilation-targets": "^7.23.6", "@babel/helper-module-transforms": "^7.23.3", - "@babel/helpers": "^7.23.5", - "@babel/parser": "^7.23.5", + "@babel/helpers": "^7.23.6", + "@babel/parser": "^7.23.6", "@babel/template": "^7.22.15", - "@babel/traverse": "^7.23.5", - "@babel/types": "^7.23.5", + "@babel/traverse": "^7.23.6", + "@babel/types": "^7.23.6", "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -139,12 +139,12 @@ } }, "node_modules/@babel/generator": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.5.tgz", - "integrity": "sha512-BPssCHrBD+0YrxviOa3QzpqwhNIXKEtOa2jQrm4FlmkC2apYgRnQcmPWiGZDlGxiNtltnUFolMe8497Esry+jA==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.6.tgz", + "integrity": "sha512-qrSfCYxYQB5owCmGLbl8XRpX1ytXlpueOb0N0UmQwA073KZxejgQTzAmJezxvpwQD9uGtK2shHdi55QT+MbjIw==", "dev": true, "dependencies": { - "@babel/types": "^7.23.5", + "@babel/types": "^7.23.6", "@jridgewell/gen-mapping": "^0.3.2", "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" @@ -166,14 +166,14 @@ } }, "node_modules/@babel/helper-compilation-targets": { - "version": "7.22.15", - "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.22.15.tgz", - "integrity": "sha512-y6EEzULok0Qvz8yyLkCvVX+02ic+By2UdOhylwUOvOn9dvYc9mKICJuuU1n1XBI02YWsNsnrY1kc6DVbjcXbtw==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.23.6.tgz", + "integrity": "sha512-9JB548GZoQVmzrFgp8o7KxdgkTGm6xs9DW0o/Pim72UDjzr5ObUQ6ZzYPqA+g9OTS2bBQoctLJrky0RDCAWRgQ==", "dev": true, "dependencies": { - "@babel/compat-data": "^7.22.9", - "@babel/helper-validator-option": "^7.22.15", - "browserslist": "^4.21.9", + "@babel/compat-data": "^7.23.5", + "@babel/helper-validator-option": "^7.23.5", + "browserslist": "^4.22.2", "lru-cache": "^5.1.1", "semver": "^6.3.1" }, @@ -307,14 +307,14 @@ } }, "node_modules/@babel/helpers": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.23.5.tgz", - "integrity": "sha512-oO7us8FzTEsG3U6ag9MfdF1iA/7Z6dz+MtFhifZk8C8o453rGJFFWUP1t+ULM9TUIAzC9uxXEiXjOiVMyd7QPg==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.23.6.tgz", + "integrity": "sha512-wCfsbN4nBidDRhpDhvcKlzHWCTlgJYUUdSJfzXb2NuBssDSIjc3xcb+znA7l+zYsFljAcGM0aFkN40cR3lXiGA==", "dev": true, "dependencies": { "@babel/template": "^7.22.15", - "@babel/traverse": "^7.23.5", - "@babel/types": "^7.23.5" + "@babel/traverse": "^7.23.6", + "@babel/types": "^7.23.6" }, "engines": { "node": ">=6.9.0" @@ -335,9 +335,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.5.tgz", - "integrity": "sha512-hOOqoiNXrmGdFbhgCzu6GiURxUgM27Xwd/aPuu8RfHEZPBzL1Z54okAHAQjXfcQNwvrlkAmAp4SlRTZ45vlthQ==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.6.tgz", + "integrity": "sha512-Z2uID7YJ7oNvAI20O9X0bblw7Qqs8Q2hFy0R9tAfnfLkp5MW0UH9eUvnDSnFwKZ0AvgS1ucqR4KzvVHgnke1VQ==", "dev": true, "bin": { "parser": "bin/babel-parser.js" @@ -572,20 +572,20 @@ } }, "node_modules/@babel/traverse": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.5.tgz", - "integrity": "sha512-czx7Xy5a6sapWWRx61m1Ke1Ra4vczu1mCTtJam5zRTBOonfdJ+S/B6HYmGYu3fJtr8GGET3si6IhgWVBhJ/m8w==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.6.tgz", + "integrity": "sha512-czastdK1e8YByZqezMPFiZ8ahwVMh/ESl9vPgvgdB9AmFMGP5jfpFax74AQgl5zj4XHzqeYAg2l8PuUeRS1MgQ==", "dev": true, "dependencies": { "@babel/code-frame": "^7.23.5", - "@babel/generator": "^7.23.5", + "@babel/generator": "^7.23.6", "@babel/helper-environment-visitor": "^7.22.20", "@babel/helper-function-name": "^7.23.0", "@babel/helper-hoist-variables": "^7.22.5", "@babel/helper-split-export-declaration": "^7.22.6", - "@babel/parser": "^7.23.5", - "@babel/types": "^7.23.5", - "debug": "^4.1.0", + "@babel/parser": "^7.23.6", + "@babel/types": "^7.23.6", + "debug": "^4.3.1", "globals": "^11.1.0" }, "engines": { @@ -602,9 +602,9 @@ } }, "node_modules/@babel/types": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.5.tgz", - "integrity": "sha512-ON5kSOJwVO6xXVRTvOI0eOnWe7VdUcIpsovGo9U/Br4Ie4UVFQTboO2cYnDhAGU6Fp+UxSiT+pMft0SMHfuq6w==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.6.tgz", + "integrity": "sha512-+uarb83brBzPKN38NX1MkB6vb6+mwvR6amUulqAE7ccQw1pEl+bCia9TbdG1lsnFP7lZySvUn37CHyXQdfTwzg==", "dev": true, "dependencies": { "@babel/helper-string-parser": "^7.23.4", @@ -1595,15 +1595,15 @@ } }, "node_modules/@stylistic/eslint-plugin": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin/-/eslint-plugin-1.5.0.tgz", - "integrity": "sha512-XmlB5nxk06nlnx1/ka0l+WNqHcjnnXfDts4ZaCvrpCY/6l8lNtHwLwdCKF/UpBYNuRWI/HLWCTtQc0jjfwrfBA==", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin/-/eslint-plugin-1.5.1.tgz", + "integrity": "sha512-y7ynUMh5Hq1MhYApAccl1iuQem5Sf2JSEIjV/qsBfmW1WfRDs74V+0kLkcOn1Y600W3t8orIFrrEuWmJSetAgw==", "dev": true, "dependencies": { - "@stylistic/eslint-plugin-js": "1.5.0", - "@stylistic/eslint-plugin-jsx": "1.5.0", - "@stylistic/eslint-plugin-plus": "1.5.0", - "@stylistic/eslint-plugin-ts": "1.5.0" + "@stylistic/eslint-plugin-js": "1.5.1", + "@stylistic/eslint-plugin-jsx": "1.5.1", + "@stylistic/eslint-plugin-plus": "1.5.1", + "@stylistic/eslint-plugin-ts": "1.5.1" }, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -1613,16 +1613,15 @@ } }, "node_modules/@stylistic/eslint-plugin-js": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin-js/-/eslint-plugin-js-1.5.0.tgz", - "integrity": "sha512-TuGQv1bsIshkbJUInCewp4IUWy24W5RFiVNMV0quPSkuZ8gsYoqq6kLHvvaxpjxN9TvwSoOIwnhgrYKei2Tgcw==", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin-js/-/eslint-plugin-js-1.5.1.tgz", + "integrity": "sha512-iZF0rF+uOhAmOJYOJx1Yvmm3CZ1uz9n0SRd9dpBYHA3QAvfABUORh9LADWwZCigjHJkp2QbCZelGFJGwGz7Siw==", "dev": true, "dependencies": { "acorn": "^8.11.2", "escape-string-regexp": "^4.0.0", "eslint-visitor-keys": "^3.4.3", - "espree": "^9.6.1", - "graphemer": "^1.4.0" + "espree": "^9.6.1" }, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -1644,12 +1643,12 @@ } }, "node_modules/@stylistic/eslint-plugin-jsx": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin-jsx/-/eslint-plugin-jsx-1.5.0.tgz", - "integrity": "sha512-sqFdA1mS0jwovAatS8xFAiwxPbcy69S2AUjrGMxyhxaKbELPjvqbxPYJL+35ylT0xqirUlm118xZIFDooC8koQ==", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin-jsx/-/eslint-plugin-jsx-1.5.1.tgz", + "integrity": "sha512-JuX+jsbVdpZ6EZXkbxYr9ERcGc0ndSMFgOuwEPHhOWPZ+7F8JP/nzpBjrRf7dUPMX7ezTYLZ2a3KRGRNme6rWQ==", "dev": true, "dependencies": { - "@stylistic/eslint-plugin-js": "^1.5.0", + "@stylistic/eslint-plugin-js": "^1.5.1", "estraverse": "^5.3.0" }, "engines": { @@ -1660,9 +1659,9 @@ } }, "node_modules/@stylistic/eslint-plugin-plus": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin-plus/-/eslint-plugin-plus-1.5.0.tgz", - "integrity": "sha512-+A4qXFuM6V7x25Hj+xqfVIUbEckG+MUSvL6m83M6YtRq3d5zLW+giKKEL7eSCAw12MwnoDwPcEhqIJK6BRDR3w==", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin-plus/-/eslint-plugin-plus-1.5.1.tgz", + "integrity": "sha512-yxkFHsUgoqEf/j1Og0FGkpEmeQoqx0CMmtgoyZGr34hka0ElCy9fRpsFkLcwx60SfiHXspbvs2YUMXiWIffnjg==", "dev": true, "dependencies": { "@typescript-eslint/utils": "^6.13.2" @@ -1672,14 +1671,13 @@ } }, "node_modules/@stylistic/eslint-plugin-ts": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin-ts/-/eslint-plugin-ts-1.5.0.tgz", - "integrity": "sha512-OusNGWRXnOV+ywnoXmBFoMtU6Ig/MX1bEu5Jigqmy2cIT8GRMMn7jUl/bXevkv2o66MYnC7PT1Q/3GvN7t0/eg==", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin-ts/-/eslint-plugin-ts-1.5.1.tgz", + "integrity": "sha512-oXM1V7Jp8G9+udxQTy+Igo79LR2e5HXiWqlA/3v+/PAqWxniR9nJqJSBjtQKJTPsGplDqn/ASpHUOETP4EI/4A==", "dev": true, "dependencies": { - "@stylistic/eslint-plugin-js": "1.5.0", - "@typescript-eslint/utils": "^6.13.2", - "graphemer": "^1.4.0" + "@stylistic/eslint-plugin-js": "1.5.1", + "@typescript-eslint/utils": "^6.13.2" }, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -1702,9 +1700,9 @@ } }, "node_modules/@types/babel__generator": { - "version": "7.6.7", - "resolved": "https://registry.npmjs.org/@types/babel__generator/-/babel__generator-7.6.7.tgz", - "integrity": "sha512-6Sfsq+EaaLrw4RmdFWE9Onp63TOUue71AWb4Gpa6JxzgTYtimbM086WnYTy2U67AofR++QKCo08ZP6pwx8YFHQ==", + "version": "7.6.8", + "resolved": "https://registry.npmjs.org/@types/babel__generator/-/babel__generator-7.6.8.tgz", + "integrity": "sha512-ASsj+tpEDsEiFr1arWrlN6V3mdfjRMZt6LtK/Vp/kreFLnr5QH5+DhvD5nINYZXzwJvXeGq+05iUXcAzVrqWtw==", "dev": true, "dependencies": { "@babel/types": "^7.0.0" @@ -1769,9 +1767,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.10.3", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.3.tgz", - "integrity": "sha512-XJavIpZqiXID5Yxnxv3RUDKTN5b81ddNC3ecsA0SoFXz/QU8OGBwZGMomiq0zw+uuqbL/krztv/DINAQ/EV4gg==", + "version": "20.10.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.5.tgz", + "integrity": "sha512-nNPsNE65wjMxEKI93yOP+NPGGBJz/PoN3kZsVLee0XMiJolxSekEVD8wRwBUBqkwc7UWop0edW50yrCQW4CyRw==", "dev": true, "dependencies": { "undici-types": "~5.26.4" @@ -2107,17 +2105,17 @@ "dev": true }, "node_modules/@typescript-eslint/utils": { - "version": "6.13.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.13.2.tgz", - "integrity": "sha512-b9Ptq4eAZUym4idijCRzl61oPCwwREcfDI8xGk751Vhzig5fFZR9CyzDz4Sp/nxSLBYxUPyh4QdIDqWykFhNmQ==", + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.15.0.tgz", + "integrity": "sha512-eF82p0Wrrlt8fQSRL0bGXzK5nWPRV2dYQZdajcfzOD9+cQz9O7ugifrJxclB+xVOvWvagXfqS4Es7vpLP4augw==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.12", "@types/semver": "^7.5.0", - "@typescript-eslint/scope-manager": "6.13.2", - "@typescript-eslint/types": "6.13.2", - "@typescript-eslint/typescript-estree": "6.13.2", + "@typescript-eslint/scope-manager": "6.15.0", + "@typescript-eslint/types": "6.15.0", + "@typescript-eslint/typescript-estree": "6.15.0", "semver": "^7.5.4" }, "engines": { @@ -2132,13 +2130,13 @@ } }, "node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/scope-manager": { - "version": "6.13.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.13.2.tgz", - "integrity": "sha512-CXQA0xo7z6x13FeDYCgBkjWzNqzBn8RXaE3QVQVIUm74fWJLkJkaHmHdKStrxQllGh6Q4eUGyNpMe0b1hMkXFA==", + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.15.0.tgz", + "integrity": "sha512-+BdvxYBltqrmgCNu4Li+fGDIkW9n//NrruzG9X1vBzaNK+ExVXPoGB71kneaVw/Jp+4rH/vaMAGC6JfMbHstVg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.13.2", - "@typescript-eslint/visitor-keys": "6.13.2" + "@typescript-eslint/types": "6.15.0", + "@typescript-eslint/visitor-keys": "6.15.0" }, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -2149,9 +2147,9 @@ } }, "node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/types": { - "version": "6.13.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.13.2.tgz", - "integrity": "sha512-7sxbQ+EMRubQc3wTfTsycgYpSujyVbI1xw+3UMRUcrhSy+pN09y/lWzeKDbvhoqcRbHdc+APLs/PWYi/cisLPg==", + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.15.0.tgz", + "integrity": "sha512-yXjbt//E4T/ee8Ia1b5mGlbNj9fB9lJP4jqLbZualwpP2BCQ5is6BcWwxpIsY4XKAhmdv3hrW92GdtJbatC6dQ==", "dev": true, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -2162,13 +2160,13 @@ } }, "node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/typescript-estree": { - "version": "6.13.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.13.2.tgz", - "integrity": "sha512-SuD8YLQv6WHnOEtKv8D6HZUzOub855cfPnPMKvdM/Bh1plv1f7Q/0iFUDLKKlxHcEstQnaUU4QZskgQq74t+3w==", + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.15.0.tgz", + "integrity": "sha512-7mVZJN7Hd15OmGuWrp2T9UvqR2Ecg+1j/Bp1jXUEY2GZKV6FXlOIoqVDmLpBiEiq3katvj/2n2mR0SDwtloCew==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.13.2", - "@typescript-eslint/visitor-keys": "6.13.2", + "@typescript-eslint/types": "6.15.0", + "@typescript-eslint/visitor-keys": "6.15.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -2189,12 +2187,12 @@ } }, "node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/visitor-keys": { - "version": "6.13.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.13.2.tgz", - "integrity": "sha512-OGznFs0eAQXJsp+xSd6k/O1UbFi/K/L7WjqeRoFE7vadjAF9y0uppXhYNQNEqygjou782maGClOoZwPqF0Drlw==", + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.15.0.tgz", + "integrity": "sha512-1zvtdC1a9h5Tb5jU9x3ADNXO9yjP8rXlaoChu0DQX40vf5ACVpYIVIZhIMZ6d5sDXH7vq4dsZBT1fEGj8D2n2w==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.13.2", + "@typescript-eslint/types": "6.15.0", "eslint-visitor-keys": "^3.4.1" }, "engines": { @@ -2860,9 +2858,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001566", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001566.tgz", - "integrity": "sha512-ggIhCsTxmITBAMmK8yZjEhCO5/47jKXPu6Dha/wuCS4JePVL+3uiDEBuhu2aIoT+bqTOR8L76Ip1ARL9xYsEJA==", + "version": "1.0.30001571", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001571.tgz", + "integrity": "sha512-tYq/6MoXhdezDLFZuCO/TKboTzuQ/xR5cFdgXPfDtM7/kchBO3b4VWghE/OAi/DV7tTdhmLjZiZBZi1fA/GheQ==", "dev": true, "funding": [ { @@ -3291,9 +3289,9 @@ } }, "node_modules/default-browser/node_modules/npm-run-path": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.1.0.tgz", - "integrity": "sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.2.0.tgz", + "integrity": "sha512-W4/tgAXFqFA0iL7fk0+uQ3g7wkL8xJmx3XdK0VGb4cHW//eZTtKGvFBBoRKVTpY7n6ze4NL9ly7rgXcHufqXKg==", "dev": true, "dependencies": { "path-key": "^4.0.0" @@ -3430,9 +3428,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.605", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.605.tgz", - "integrity": "sha512-V52j+P5z6cdRqTjPR/bYNxx7ETCHIkm5VIGuyCy3CMrfSnbEpIlLnk5oHmZo7gYvDfh2TfHeanB6rawyQ23ktg==", + "version": "1.4.616", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.616.tgz", + "integrity": "sha512-1n7zWYh8eS0L9Uy+GskE0lkBUNK83cXTVJI0pU3mGprFsbfSdAc15VTFbo+A+Bq4pwstmL30AVcEU3Fo463lNg==", "dev": true }, "node_modules/emittery": { @@ -4290,9 +4288,9 @@ "dev": true }, "node_modules/fastq": { - "version": "1.15.0", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", - "integrity": "sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==", + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.16.0.tgz", + "integrity": "sha512-ifCoaXsDrsdkWTtiNJX5uzHDsrck5TzfKKDcuFFTIrrc/BS076qgEIfoIy1VeZqViznfKiysPYTh/QeHtnIsYA==", "dev": true, "dependencies": { "reusify": "^1.0.4" diff --git a/package.json b/package.json index 13a13d1..ec7dd99 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "@babel/plugin-syntax-flow": "7.23.3", "@babel/plugin-syntax-jsx": "7.23.3", "@babel/plugin-transform-react-jsx": "7.23.4", + "@stylistic/eslint-plugin": "1.5.1", "@typescript-eslint/eslint-plugin": "6.13.1", "@typescript-eslint/parser": "6.13.1", "eslint": "8.55.0", diff --git a/scripts/generate-stylistic.js b/scripts/generate-stylistic.js index e6e4b88..67e3824 100644 --- a/scripts/generate-stylistic.js +++ b/scripts/generate-stylistic.js @@ -1,40 +1,67 @@ +"use strict"; + +const getRules = (postfix) => + Object.keys(require(`@stylistic/eslint-plugin${postfix}`).rules); + +const plugins = Object.entries({ + js: "", + ts: "@typescript-eslint/", + jsx: "react/", + plus: "", +}).map(([stylisticPlugin, externalPlugin]) => ({ + rules: getRules(`-${stylisticPlugin}`), + stylisticPlugin, + externalPlugin, +})); + +// Validate that the unified plugin contains an equal number of rules as the individual plugin +require("assert/strict").strictEqual( + ...[[getRules("")], plugins.map(({ rules }) => rules)].map( + (group) => new Set(group.flat()).size + ) +); + +const rulesBySeverity = {}; +for (const delimiter of ["", "/"]) + for (const { stylisticPlugin, externalPlugin, rules } of plugins) + for (const rule of rules) { + const severity = + stylisticPlugin == "plus" + ? "off" + : require("..").rules[ + externalPlugin + + rule.replace(/^(func)tion(-call-spacing$)/, "$1$2") + ]; + (rulesBySeverity[severity] ??= {})[ + `@stylistic/${delimiter && stylisticPlugin + delimiter}${rule}` + ] = severity; + } + +const rulesForREADME = [ + ...`${require("fs").readFileSync(`${__dirname}/../README.md`)}`.matchAll( + /### \[(.+)]/g + ), +] + .map(([, base]) => + Object.keys(rulesBySeverity[0]).filter((rule) => rule.endsWith(`/${base}`)) + ) + .filter(({ length }) => length); + console.log( - [[``], [`-js`, `-ts`, `-jsx`, `-plus`]].map( - (group) => - new Set( - group.flatMap((plugin) => - Object.keys(require(`@stylistic/eslint-plugin${plugin}`).rules) - ) - ).size + rulesBySeverity, + rulesForREADME.map( + (rules) => + `(The following applies to ${rules + .map((rule) => `[${rule}]`) + .join(`${rules.length == 2 ? " and" : ","} `)} as well.)` ), - Object.fromEntries( - Object.entries({ - js: ``, - ts: `@typescript-eslint/`, - jsx: `react/`, - plus: ``, + rulesForREADME + .flat() + .map((rule) => { + const ruleWithoutPrefix = rule.replace("@stylistic/", ""); + return `[${rule}]: https://eslint.style/rules/${ + ruleWithoutPrefix.includes("/") ? "" : "default/" + }${ruleWithoutPrefix}`; }) - .flatMap(([stylisticPlugin, externalPlugin]) => - Object.entries( - require( - `@stylistic/eslint-plugin${ - stylisticPlugin && `-${stylisticPlugin}` - }` - ).rules - ).map(([name, { meta }]) => [ - `@stylistic/${stylisticPlugin && `${stylisticPlugin}/`}${name}`, - { - level: - stylisticPlugin == `plus` - ? `off` - : require(`.`).rules[ - externalPlugin + - name.replace(/^(func)tion(-call-spacing$)/, `$1$2`) - ], - fixable: meta.fixable, - }, - ]) - ) - .sort((a, b) => `${a[1].level}`.localeCompare(b[1].level)) - ) + .join("\n") ); diff --git a/test-lint/@stylistic.js b/test-lint/@stylistic.js new file mode 100644 index 0000000..34f6bc9 --- /dev/null +++ b/test-lint/@stylistic.js @@ -0,0 +1,6 @@ +"use strict"; + +// Prettier wants a newline after the condition, but `eslint-config-google` does not. +if (cart.items && cart.items[0] && cart.items[0].quantity === 0) { + updateCart(cart); +}