diff --git a/.eslintrc.js b/.eslintrc.js index 7594b9d..f0003c2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,171 +1,30 @@ /* eslint-env node */ -module.exports = { +/** @type {import("eslint").Linter.Config */ +const config = { + root: true, + env: { + browser: true, + }, + parser: "@typescript-eslint/parser", + plugins: ["@typescript-eslint"], extends: [ "eslint:recommended", - "plugin:jsx-a11y/recommended", - "plugin:@netless/recommended", + "plugin:@typescript-eslint/recommended", + "prettier", ], - plugins: ["jsx-a11y", "prettier"], - parserOptions: { - project: "./tsconfig.lint.json", - ecmaVersion: 2018, - sourceType: "module", - ecmaFeatures: { - jsx: true, - }, - }, rules: { - // http://eslint.org/docs/rules/ - "array-callback-return": "warn", - "default-case": ["warn", { commentPattern: "^no default$" }], - "dot-location": ["warn", "property"], - "new-parens": "warn", - "no-array-constructor": "warn", - "no-caller": "warn", - "no-cond-assign": ["warn", "except-parens"], - "no-const-assign": "warn", - "no-control-regex": "warn", - "no-delete-var": "warn", - "no-dupe-args": "warn", - // support typescript overload - // typescript does its own check - "no-dupe-class-members": "off", - "no-dupe-keys": "warn", - "no-duplicate-case": "warn", - "no-empty-character-class": "warn", - "no-empty-pattern": "warn", - "no-eval": "warn", - "no-ex-assign": "warn", - "no-extend-native": "warn", - "no-extra-bind": "warn", - "no-extra-label": "warn", - "no-fallthrough": "warn", - "no-func-assign": "warn", - "no-implied-eval": "warn", - "no-invalid-regexp": "warn", - "no-iterator": "warn", - "no-label-var": "warn", - "no-labels": ["warn", { allowLoop: true, allowSwitch: false }], - "no-lone-blocks": "warn", - "no-loop-func": "warn", - "no-mixed-operators": [ - "warn", - { - groups: [ - ["&", "|", "^", "~", "<<", ">>", ">>>"], - ["==", "!=", "===", "!==", ">", ">=", "<", "<="], - ["&&", "||"], - ["in", "instanceof"], - ], - allowSamePrecedence: false, - }, - ], - "no-multi-str": "warn", - "no-native-reassign": "warn", - "no-negated-in-lhs": "warn", - "no-new-func": "warn", - "no-new-object": "warn", - "no-new-symbol": "warn", - "no-new-wrappers": "warn", - "no-obj-calls": "warn", - "no-octal": "warn", - "no-octal-escape": "warn", - // TODO: Remove this option in the next major release of CRA. - // https://eslint.org/docs/user-guide/migrating-to-6.0.0#-the-no-redeclare-rule-is-now-more-strict-by-default - "no-redeclare": "off", - "no-regex-spaces": "warn", - "no-restricted-syntax": ["warn", "WithStatement"], - "no-script-url": "warn", - "no-self-assign": "warn", - "no-self-compare": "warn", - "no-sequences": "warn", - "no-shadow-restricted-names": "warn", - "no-sparse-arrays": "warn", - "no-template-curly-in-string": "warn", - "no-this-before-super": "warn", - "no-throw-literal": "warn", - "no-undef": "error", - "no-unreachable": "warn", - "no-unused-expressions": [ + "@typescript-eslint/consistent-type-imports": ["warn"], + "@typescript-eslint/no-empty-interface": "off", + "@typescript-eslint/no-explicit-any": "off", + "prefer-const": [ "error", { - allowShortCircuit: true, - allowTernary: true, - allowTaggedTemplates: true, - }, - ], - "no-unused-labels": "warn", - "no-unused-vars": "off", - "no-useless-computed-key": "warn", - "no-useless-concat": "warn", - "no-useless-constructor": "warn", - "no-useless-escape": "warn", - "no-useless-rename": [ - "warn", - { - ignoreDestructuring: false, - ignoreImport: false, - ignoreExport: false, + destructuring: "all", }, ], - "no-with": "warn", - "no-whitespace-before-property": "warn", - "require-yield": "warn", - "rest-spread-spacing": ["warn", "never"], - strict: ["warn", "never"], - "unicode-bom": ["warn", "never"], - "use-isnan": "warn", - "valid-typeof": "warn", - "getter-return": "warn", - - // https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules - "jsx-a11y/alt-text": "off", - "jsx-a11y/anchor-has-content": "warn", - "jsx-a11y/aria-activedescendant-has-tabindex": "warn", - "jsx-a11y/aria-props": "warn", - "jsx-a11y/aria-proptypes": "warn", - "jsx-a11y/aria-role": ["warn", { ignoreNonDOM: true }], - "jsx-a11y/aria-unsupported-elements": "warn", - "jsx-a11y/heading-has-content": "warn", - "jsx-a11y/iframe-has-title": "warn", - "jsx-a11y/img-redundant-alt": "warn", - "jsx-a11y/no-access-key": "warn", - "jsx-a11y/no-distracting-elements": "warn", - "jsx-a11y/no-redundant-roles": "warn", - "jsx-a11y/role-has-required-aria-props": "warn", - "jsx-a11y/role-supports-aria-props": "warn", - "jsx-a11y/scope": "warn", - "jsx-a11y/media-has-caption": "off", - "jsx-a11y/anchor-is-valid": "off", - - "jsx-a11y/click-events-have-key-events": "off", - "jsx-a11y/no-static-element-interactions": "off", - "jsx-a11y/mouse-events-have-key-events": "off", - "@typescript-eslint/no-redeclare": "off", - "no-use-before-define": "off", - "@typescript-eslint/explicit-function-return-type": "off", }, - - overrides: [ - { - // enable the rule specifically for TypeScript files - files: ["*.ts", "*.tsx"], - globals: { - JSX: true, - }, - rules: { - "@typescript-eslint/explicit-function-return-type": [ - "error", - { - allowExpressions: true, - allowTypedFunctionExpressions: true, - allowHigherOrderFunctions: true, - allowDirectConstAssertionInArrowFunctions: true, - allowConciseArrowFunctionExpressionsStartingWithVoid: true, - }, - ], - }, - }, - ], }; + +// eslint-disable-next-line no-undef +module.exports = config; diff --git a/cspell.json b/cspell.json new file mode 100644 index 0000000..66cfc66 --- /dev/null +++ b/cspell.json @@ -0,0 +1,22 @@ +{ + "language": "en", + "ignorePaths": [ + "**/coverage/**", + "**/node_modules/**", + "**/dist/**", + "cspell.config.js", + "pnpm-lock.yaml", + "CHANGELOG.md" + ], + "words": [ + "autohiding", + "btns", + "callout", + "Classname", + "CRIMX", + "minlength", + "overscroll", + "pnpm", + "vite" + ] +} diff --git a/playground/main.ts b/playground/main.ts index 249916c..8c1677c 100644 --- a/playground/main.ts +++ b/playground/main.ts @@ -1,15 +1,11 @@ import "./style.scss"; import faker from "faker"; -import { - TeleBoxCollector, - TeleBoxColorScheme, - TeleBoxManager, - TeleBoxRect, -} from "../src"; +import type { TeleBoxColorScheme, TeleBoxRect } from "../src"; +import { TeleBoxCollector, TeleBoxManager } from "../src"; -const btns = document.querySelector(".btns")!; -const board = document.querySelector(".board")!; +const btns = document.querySelector(".btns") as HTMLDivElement; +const board = document.querySelector(".board") as HTMLDivElement; const createBtn = (title: string): HTMLButtonElement => { const btn = document.createElement("button"); diff --git a/src/TeleBox/index.ts b/src/TeleBox/index.ts index c97e427..9d29a73 100644 --- a/src/TeleBox/index.ts +++ b/src/TeleBox/index.ts @@ -4,14 +4,10 @@ import EventEmitter from "eventemitter3"; import styler from "stylefire"; import shallowequal from "shallowequal"; import { SideEffectManager } from "side-effect-manager"; -import { - combine, - ReadonlyVal, - Val, - ValEnhancedResult, - withValueEnhancer, -} from "value-enhancer"; -import { DefaultTitleBar, TeleTitleBar } from "../TeleTitleBar"; +import type { ReadonlyVal, ValEnhancedResult } from "value-enhancer"; +import { combine, Val, withValueEnhancer } from "value-enhancer"; +import type { TeleTitleBar } from "../TeleTitleBar"; +import { DefaultTitleBar } from "../TeleTitleBar"; import { clamp, flattenEvent, @@ -1307,7 +1303,8 @@ function noop(): void { } type PropKeys = K extends keyof TeleBox - ? TeleBox[K] extends Function + ? // eslint-disable-next-line @typescript-eslint/ban-types + TeleBox[K] extends Function ? never : K : never; diff --git a/src/TeleBoxCollector/index.ts b/src/TeleBoxCollector/index.ts index 9fe885a..60f3c54 100644 --- a/src/TeleBoxCollector/index.ts +++ b/src/TeleBoxCollector/index.ts @@ -1,6 +1,6 @@ import "./style.scss"; import collectorSVG from "./icons/collector.svg"; -import { TeleStyles } from "../typings"; +import type { TeleStyles } from "../typings"; export interface TeleBoxCollectorConfig { visible?: boolean; diff --git a/src/TeleBoxManager/MaxTitleBar/index.ts b/src/TeleBoxManager/MaxTitleBar/index.ts index aba4db7..1a865d6 100644 --- a/src/TeleBoxManager/MaxTitleBar/index.ts +++ b/src/TeleBoxManager/MaxTitleBar/index.ts @@ -1,9 +1,10 @@ import "./style.scss"; import type { TeleBox } from "../../TeleBox"; -import { DefaultTitleBar, DefaultTitleBarConfig } from "../../TeleTitleBar"; +import type { DefaultTitleBarConfig } from "../../TeleTitleBar"; +import { DefaultTitleBar } from "../../TeleTitleBar"; import { TELE_BOX_STATE } from "../../TeleBox/constants"; -import { TeleBoxRect, TeleBoxState } from "../../TeleBox/typings"; +import type { TeleBoxRect, TeleBoxState } from "../../TeleBox/typings"; export type MaxTitleBarTeleBox = Pick; diff --git a/src/TeleBoxManager/index.ts b/src/TeleBoxManager/index.ts index cc16bf7..be992ea 100644 --- a/src/TeleBoxManager/index.ts +++ b/src/TeleBoxManager/index.ts @@ -6,7 +6,8 @@ import type { TeleBoxState, } from "../TeleBox/typings"; import { TeleBoxCollector } from "../TeleBoxCollector"; -import { ReadonlyTeleBox, TeleBox } from "../TeleBox"; +import type { ReadonlyTeleBox } from "../TeleBox"; +import { TeleBox } from "../TeleBox"; import { TELE_BOX_EVENT, TELE_BOX_STATE } from "../TeleBox/constants"; import { TELE_BOX_MANAGER_EVENT } from "./constants"; import type { @@ -17,19 +18,11 @@ import type { TeleBoxManagerUpdateConfig, } from "./typings"; import { MaxTitleBar } from "./MaxTitleBar"; -import { - TeleBoxColorScheme, - TELE_BOX_COLOR_SCHEME, - TELE_BOX_DELEGATE_EVENT, -} from ".."; +import type { TeleBoxColorScheme } from ".."; +import { TELE_BOX_COLOR_SCHEME, TELE_BOX_DELEGATE_EVENT } from ".."; import { SideEffectManager } from "side-effect-manager"; -import { - combine, - ReadonlyVal, - Val, - ValEnhancedResult, - withValueEnhancer, -} from "value-enhancer"; +import type { ReadonlyVal, ValEnhancedResult } from "value-enhancer"; +import { combine, Val, withValueEnhancer } from "value-enhancer"; export * from "./typings"; export * from "./constants"; diff --git a/src/TeleBoxManager/typings.ts b/src/TeleBoxManager/typings.ts index 91e17bc..3a73ed6 100644 --- a/src/TeleBoxManager/typings.ts +++ b/src/TeleBoxManager/typings.ts @@ -1,5 +1,5 @@ import type EventEmitter from "eventemitter3"; -import { TeleBoxColorScheme } from ".."; +import type { TeleBoxColorScheme } from ".."; import type { ReadonlyTeleBox, TeleBoxState } from "../TeleBox"; import type { TeleBoxConfig } from "../TeleBox/typings"; import type { TeleBoxCollector } from "../TeleBoxCollector"; diff --git a/vite.config.js b/vite.config.js index d6cf639..c99ef26 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,7 +1,8 @@ /* eslint-env node */ import path from "path"; +import { defineConfig } from "vite"; -export default ({ command, mode }) => { +export default defineConfig(({ mode }) => { const isProd = mode === "production"; return { @@ -15,4 +16,4 @@ export default ({ command, mode }) => { minify: isProd, }, }; -}; +});