From 43cfc5f3bdae4aaec463702fcc09202d072738e1 Mon Sep 17 00:00:00 2001 From: Pat Cavit Date: Mon, 10 Feb 2025 15:12:09 -0800 Subject: [PATCH 1/2] chore: eslint v9 --- .eslintignore | 2 - .eslintrc.cjs | 47 - .vscode/settings.json | 9 +- eslint.config.js | 540 ++++++ package-lock.json | 2786 +++++++++++++++-------------- package.json | 39 +- rollup.config.js | 94 - src/component-helper.js | 12 +- src/component-tree.js | 92 +- src/index.js | 2 - tests/api/specimens/grandchild.js | 1 - tests/api/verbose.test.js | 2 +- tests/basic.test.js | 7 +- tests/helper.test.js | 32 +- tests/invoked-load.test.js | 2 +- tests/invoked.test.js | 7 +- tests/load.test.js | 4 +- tests/props.test.js | 2 +- tests/util/async.js | 2 +- tests/util/context.js | 2 +- tests/util/describe.js | 6 +- tests/util/snapshot.js | 8 +- tests/util/trees.js | 40 +- 23 files changed, 2134 insertions(+), 1604 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.cjs create mode 100644 eslint.config.js delete mode 100644 rollup.config.js delete mode 100644 src/index.js diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index a60030e..0000000 --- a/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -dist/ -coverage/ diff --git a/.eslintrc.cjs b/.eslintrc.cjs deleted file mode 100644 index 0b2b1bf..0000000 --- a/.eslintrc.cjs +++ /dev/null @@ -1,47 +0,0 @@ -"use strict"; - -module.exports = { - extends : [ - "@tivac", - "plugin:jsdoc/recommended", - ], - - - parserOptions : { - sourceType : "module", - }, - - env : { - node : true, - browser : true, - es2020 : true, - }, - - settings : { - jsdoc : { - mode : "typescript", - }, - }, - - rules : { - "max-statements" : [ "warn", 25 ], - - "newline-after-var" : "off", - - // Block some features - "no-restricted-syntax" : [ - "error", - - // with() is so dangerous - "WithStatement", - - // Object spread - { - selector : "ExperimentalSpreadProperty", - message : "Object spread doesn't work in all environments", - }, - ], - - "jsdoc/tag-lines" : "off", - }, -}; diff --git a/.vscode/settings.json b/.vscode/settings.json index 57dfb57..ab506ba 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,10 @@ { - "xstate.showVisualEditorWarnings": false + "xstate.showVisualEditorWarnings": false, + + // Javascript + "[javascript]": { + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit" + }, + }, } \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..0646f26 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,540 @@ +import js from "@eslint/js"; +import stylistic from "@stylistic/eslint-plugin"; +import jsdoc from "eslint-plugin-jsdoc"; +import unicorn from "eslint-plugin-unicorn"; +import globals from "globals"; + +/** @type {import("eslint").Linter.Config[]} */ +const eslintConfig = [ + stylistic.configs["all-flat"], + jsdoc.configs["flat/recommended"], + unicorn.configs["flat/recommended"], + + { + name : "Base Config", + + plugins : { + jsdoc, + }, + + linterOptions : { + reportUnusedDisableDirectives : true, + }, + + languageOptions : { + globals : { + ...globals.browser, + }, + }, + + rules : { + ...js.configs.recommended.rules, + + // #region ESLint Core Rules + "accessor-pairs" : "off", + "array-callback-return" : "warn", + "arrow-body-style" : [ "warn", "as-needed" ], + "block-scoped-var" : "warn", + "camelcase" : [ + "warn", + { + properties : "never", + // whitelist names that match our custom colors, EX white1_80 + allow : [ String.raw`\w+_\d+` ], + }, + ], + "complexity" : [ "warn", 15 ], + "consistent-return" : "off", + "consistent-this" : [ "warn", "self" ], + "constructor-super" : "error", + "curly" : "error", + "default-case" : "warn", + "dot-notation" : "warn", + "eqeqeq" : "warn", + "for-direction" : "warn", + "func-names" : "off", + "func-style" : "off", + "getter-return" : "error", + "guard-for-in" : "off", + "id-length" : "off", + "id-match" : "off", + "init-declarations" : "off", + "max-nested-callbacks" : "off", + "max-params" : [ "warn", 4 ], + "new-cap" : [ "error", { + // Note: We support "?.", ".", "[" for characters that come AFTER the method name. + capIsNewExceptionPattern : String.raw`^(?:hud|engine|game\w+)(\.|\?\.|\[).`, + }], + "max-statements" : [ "warn", 25, { ignoreTopLevelFunctions : true }], + "no-alert" : "warn", + "no-array-constructor" : "error", + "no-await-in-loop" : "warn", + "no-bitwise" : "error", + "no-caller" : "error", + "no-case-declarations" : "error", + "no-class-assign" : "error", + "no-compare-neg-zero" : "error", + "no-cond-assign" : "error", + "no-console" : "warn", + "no-const-assign" : "error", + "no-constant-condition" : "error", + "no-continue" : "off", + "no-control-regex" : "off", + "no-debugger" : "warn", + "no-delete-var" : "error", + "no-div-regex" : "warn", + "no-dupe-args" : "error", + "no-dupe-class-members" : "error", + "no-dupe-keys" : "error", + "no-duplicate-case" : "error", + "no-else-return" : "error", + "no-empty-character-class" : "warn", + "no-empty-function" : "warn", + "no-empty-pattern" : "warn", + "no-empty" : "warn", + "no-eq-null" : "off", + "no-eval" : "error", + "no-ex-assign" : "error", + "no-extend-native" : "error", + "no-extra-bind" : "warn", + "no-extra-boolean-cast" : "warn", + "no-extra-label" : "error", + "no-fallthrough" : "warn", + "no-func-assign" : "warn", + "no-implicit-coercion" : "warn", + "no-implicit-globals" : "error", + "no-implied-eval" : "error", + "no-inline-comments" : "off", + "no-inner-declarations" : "off", + "no-invalid-regexp" : "error", + "no-invalid-this" : "off", + "no-irregular-whitespace" : "warn", + "no-iterator" : "error", + "no-label-var" : "error", + "no-labels" : "error", + "no-lone-blocks" : "warn", + "no-lonely-if" : "error", + "no-loop-func" : "warn", + "no-magic-numbers" : "off", + "no-multi-str" : "error", + "no-negated-condition" : "off", + "no-nested-ternary" : "error", + "no-new-func" : "off", + "no-new-wrappers" : "error", + "no-new" : "off", + "no-obj-calls" : "off", + "no-object-constructor" : "error", + "no-octal-escape" : "error", + "no-octal" : "error", + "no-param-reassign" : "off", + "no-plusplus" : "off", + "no-proto" : "error", + "no-redeclare" : "warn", + "no-regex-spaces" : "warn", + "no-restricted-syntax" : [ + "error", + { + // with + selector : "WithStatement", + message : "with breaks everything, don't use it", + }, + ], + "no-return-assign" : "warn", + "no-script-url" : "error", + "no-self-compare" : "warn", + "no-sequences" : "error", + "no-shadow-restricted-names" : "error", + "no-shadow" : "warn", + "no-sparse-arrays" : "warn", + "no-ternary" : "off", + "no-this-before-super" : "error", + "no-throw-literal" : "warn", + "no-undef-init" : "error", + "no-undef" : "error", + "no-undefined" : "off", + "no-underscore-dangle" : "off", + "no-unexpected-multiline" : "error", + "no-unmodified-loop-condition" : "error", + "no-unneeded-ternary" : "warn", + "no-unreachable" : "error", + "no-unused-expressions" : "warn", + "no-unused-vars" : [ "warn", { + args : "after-used", + ignoreRestSiblings : true, + caughtErrors : "none", + varsIgnorePattern : "^_", + argsIgnorePattern : "^_", + }], + "no-use-before-define" : "warn", + "no-useless-call" : "warn", + "no-useless-concat" : "warn", + "no-useless-constructor" : "error", + "no-var" : "off", + "no-void" : "error", + "no-warning-comments" : "off", + "no-with" : "error", + "object-shorthand" : "warn", + "one-var" : [ + "error", + { + var : "always", + let : "never", + const : "never", + }, + ], + "operator-assignment" : "off", + "prefer-arrow-callback" : "error", + "prefer-const" : "warn", + "prefer-destructuring" : [ "warn", { + VariableDeclarator : { + array : true, + object : true, + }, + + // Destructuring in assignments looks wonky, don't warn about it + AssignmentExpression : { + array : false, + object : false, + }, + }], + "prefer-rest-params" : "warn", + "prefer-spread" : "warn", + "prefer-template" : "warn", + "radix" : "warn", + "require-jsdoc" : "off", + "require-yield" : "error", + "sort-vars" : "off", + "strict" : "off", + "use-isnan" : "error", + "valid-jsdoc" : "off", + "valid-typeof" : "error", + "vars-on-top" : "warn", + "yoda" : "warn", + + // #region Stylistic Rules + + "@stylistic/array-bracket-spacing" : [ + "warn", + "always", + { + arraysInArrays : false, + singleValue : true, + objectsInArrays : false, + }, + ], + + "@stylistic/array-bracket-newline" : [ "warn", "consistent" ], + "@stylistic/array-element-newline" : [ "warn", "consistent" ], + "@stylistic/arrow-parens" : [ "error", "always" ], + "@stylistic/arrow-spacing" : "error", + "@stylistic/block-spacing" : [ "warn", "always" ], + "@stylistic/brace-style" : "error", + + "@stylistic/comma-dangle" : [ + "warn", + { + arrays : "always-multiline", + exports : "always-multiline", + functions : "ignore", + imports : "always-multiline", + objects : "always-multiline", + }, + ], + + "@stylistic/comma-spacing" : "warn", + "@stylistic/comma-style" : [ "warn", "last" ], + "@stylistic/computed-property-spacing" : [ "warn", "never" ], + + "@stylistic/curly-newline" : [ "warn", { + multiline : true, + minElements : 1, + + FunctionExpression : { + minElements : 1, + }, + }], + + "@stylistic/dot-location" : [ "error", "property" ], + "@stylistic/eol-last" : "warn", + "@stylistic/func-call-spacing" : [ "warn", "never" ], + "@stylistic/function-call-argument-newline" : [ "warn", "consistent" ], + "@stylistic/function-call-spacing" : "warn", + "@stylistic/function-paren-newline" : "off", + "@stylistic/generator-star-spacing" : "error", + "@stylistic/implicit-arrow-linebreak" : "off", + "@stylistic/indent" : [ "error", 4, { + MemberExpression : 0, + }], + "@stylistic/indent-binary-ops" : [ "error", 4 ], + "@stylistic/jsx-quotes" : "off", + "@stylistic/key-spacing" : [ + "warn", + { + mode : "minimum", + beforeColon : true, + afterColon : true, + }, + ], + + "@stylistic/keyword-spacing" : [ + "warn", + { + before : true, + after : false, + overrides : { + case : { after : true }, + const : { after : true }, + default : { after : true }, + do : { after : true }, + else : { after : true }, + export : { after : true }, + from : { after : true }, + import : { after : true }, + let : { after : true }, + return : { after : true }, + try : { after : true }, + var : { after : true }, + of : { after : true }, + in : { after : true }, + }, + }, + ], + + "@stylistic/line-comment-position" : [ "warn", { position : "above" }], + "@stylistic/linebreak-style" : "off", + "@stylistic/lines-around-comment" : [ + "off", + { + beforeBlockComment : true, + beforeLineComment : true, + allowBlockStart : true, + allowObjectStart : true, + allowArrayStart : true, + }, + ], + + "@stylistic/lines-between-class-members" : "warn", + + "@stylistic/max-len" : [ "warn", { + code : 130, + // Ignoring common SVG & HTML patterns + ignorePattern : String.raw`M\d|