Skip to content

Commit

Permalink
chore: update eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed Jun 1, 2022
1 parent e4bee05 commit fe5a51e
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 195 deletions.
177 changes: 18 additions & 159 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -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;
22 changes: 22 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
12 changes: 4 additions & 8 deletions playground/main.ts
Original file line number Diff line number Diff line change
@@ -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<HTMLDivElement>(".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");
Expand Down
15 changes: 6 additions & 9 deletions src/TeleBox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1307,7 +1303,8 @@ function noop(): void {
}

type PropKeys<K = keyof TeleBox> = K extends keyof TeleBox
? TeleBox[K] extends Function
? // eslint-disable-next-line @typescript-eslint/ban-types
TeleBox[K] extends Function
? never
: K
: never;
Expand Down
2 changes: 1 addition & 1 deletion src/TeleBoxCollector/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/TeleBoxManager/MaxTitleBar/index.ts
Original file line number Diff line number Diff line change
@@ -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<TeleBox, "id" | "title" | "readonly">;

Expand Down
19 changes: 6 additions & 13 deletions src/TeleBoxManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/TeleBoxManager/typings.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
5 changes: 3 additions & 2 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -15,4 +16,4 @@ export default ({ command, mode }) => {
minify: isProd,
},
};
};
});

0 comments on commit fe5a51e

Please sign in to comment.