From 16b7e936626cdea6020731b17198f29cfcf1e037 Mon Sep 17 00:00:00 2001 From: Simon Reinisch Date: Wed, 13 Nov 2024 19:24:03 +0100 Subject: [PATCH] Remove barall files and simplify ESLint config --- eslint.config.mjs | 25 ++++--------------- package.json | 2 +- packages/vanilla/src/index.ts | 11 ++++++-- packages/vanilla/src/types.ts | 2 +- .../src/utils/{constants.ts => browser.ts} | 0 packages/vanilla/src/utils/css.ts | 7 +++++- packages/vanilla/src/utils/index.ts | 8 ------ packages/vanilla/src/utils/shouldTrigger.ts | 12 ++++----- 8 files changed, 28 insertions(+), 39 deletions(-) rename packages/vanilla/src/utils/{constants.ts => browser.ts} (100%) delete mode 100644 packages/vanilla/src/utils/index.ts diff --git a/eslint.config.mjs b/eslint.config.mjs index d107f38..de198b4 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -10,24 +10,7 @@ export default [ ...vue.configs['flat/recommended'], react.configs.flat.recommended, { - files: ['**/*.{js,mjs}'], - rules: { - semi: ['error', 'always'], - 'no-console': 'error' - } - }, - { - files: ['**/*.ts'], - languageOptions: { - parser: tsParser - }, - rules: { - '@typescript-eslint/no-non-null-assertion': 'off', - 'no-console': 'error' - } - }, - { - files: ['**/*.tsx'], + files: ['**/*.ts', '**/*.tsx', '**/*.mjs'], languageOptions: { parser: tsParser, parserOptions: { @@ -44,10 +27,12 @@ export default [ } }, rules: { + '@typescript-eslint/no-non-null-assertion': 'off', 'react/react-in-jsx-scope': 'off', 'react/prop-types': 'off', - 'no-console': 'error' - }, + 'no-console': 'error', + quotes: ['error', 'single'] + } }, { files: ['**/*.vue'], diff --git a/package.json b/package.json index 8745099..485b5ac 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "dev": "pnpm run --parallel dev", "build": "pnpm run --recursive build", - "lint": "eslint 'packages/*/{src,demo}/*.{ts,tsx,vue,js}' --cache", + "lint": "eslint 'packages/*/{src,demo}/**/*.{ts,tsx,vue,js}' --cache", "lint:fix": "pnpm run lint --fix", "test:ci": "pnpm run lint:fix && pnpm run build", "release:major": "lerna version major", diff --git a/packages/vanilla/src/index.ts b/packages/vanilla/src/index.ts index ce527e3..4bd3e6b 100644 --- a/packages/vanilla/src/index.ts +++ b/packages/vanilla/src/index.ts @@ -1,7 +1,14 @@ import {EventTarget} from './EventEmitter'; import type {AreaLocation, Coordinates, ScrollEvent, SelectionEvents, SelectionOptions, SelectionStore} from './types'; import {PartialSelectionOptions} from './types'; -import {css, domRect, frames, Frames, intersects, isSafariBrowser, isTouchDevice, off, on, selectAll, SelectAllSelectors, simplifyEvent, shouldTrigger} from './utils'; +import {css} from './utils/css'; +import {domRect} from './utils/domRect'; +import {Frames, frames} from './utils/frames'; +import {intersects} from './utils/intersects'; +import {isSafariBrowser, isTouchDevice} from './utils/browser'; +import {on, off, simplifyEvent} from './utils/events'; +import {selectAll, SelectAllSelectors} from './utils/selectAll'; +import {shouldTrigger} from './utils/shouldTrigger'; // Re-export types export * from './types'; @@ -39,7 +46,7 @@ export default class SelectionArea extends EventTarget { // Dynamically constructed area rect private _areaLocation: AreaLocation = {y1: 0, x2: 0, y2: 0, x1: 0}; - private _areaRect = domRect(); + private _areaRect = domRect(); // If a single click is being performed, it's a single-click until the user dragged the mouse private _singleClick = true; diff --git a/packages/vanilla/src/types.ts b/packages/vanilla/src/types.ts index 6f72373..d14397c 100644 --- a/packages/vanilla/src/types.ts +++ b/packages/vanilla/src/types.ts @@ -1,5 +1,5 @@ import type SelectionArea from './index'; -import type {Intersection} from './utils'; +import type {Intersection} from './utils/intersects'; export type DeepPartial = T extends unknown[] ? T : diff --git a/packages/vanilla/src/utils/constants.ts b/packages/vanilla/src/utils/browser.ts similarity index 100% rename from packages/vanilla/src/utils/constants.ts rename to packages/vanilla/src/utils/browser.ts diff --git a/packages/vanilla/src/utils/css.ts b/packages/vanilla/src/utils/css.ts index 5dff536..91d6386 100644 --- a/packages/vanilla/src/utils/css.ts +++ b/packages/vanilla/src/utils/css.ts @@ -19,10 +19,15 @@ export function css( if (typeof attr === 'object') { for (const [key, value] of Object.entries(attr)) { - value !== undefined && (style[key as any] = unitify(value)); + if (value !== undefined) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + style[key as any] = unitify(value); + } + } } else if (val !== undefined) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any style[attr as any] = unitify(val); } } diff --git a/packages/vanilla/src/utils/index.ts b/packages/vanilla/src/utils/index.ts deleted file mode 100644 index 066507a..0000000 --- a/packages/vanilla/src/utils/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -export * from './css'; -export * from './events'; -export * from './intersects'; -export * from './selectAll'; -export * from './constants'; -export * from './frames'; -export * from './shouldTrigger'; -export * from './domRect'; diff --git a/packages/vanilla/src/utils/shouldTrigger.ts b/packages/vanilla/src/utils/shouldTrigger.ts index e3f6d39..e0c625f 100644 --- a/packages/vanilla/src/utils/shouldTrigger.ts +++ b/packages/vanilla/src/utils/shouldTrigger.ts @@ -1,4 +1,4 @@ -import {Trigger} from "../types"; +import {Trigger} from '../types'; /** * Determines whether a MouseEvent should execute until completion depending on @@ -11,21 +11,21 @@ import {Trigger} from "../types"; export function shouldTrigger(event: MouseEvent, triggers: Trigger[]): boolean { for (const trigger of triggers) { // The trigger requires only a specific button to be pressed - if (typeof trigger === "number") { + if (typeof trigger === 'number') { return event.button === trigger; } // The trigger requires a specific button to be pressed AND some modifiers - if (typeof trigger === "object") { + if (typeof trigger === 'object') { const reqButtonIsPressed = trigger.button === event.button; const allReqModifiersArePressed = trigger.modifiers.every((modifier) => { switch (modifier) { - case "alt": + case 'alt': return event.altKey; - case "ctrl": + case 'ctrl': return event.ctrlKey || event.metaKey; - case "shift": + case 'shift': return event.shiftKey; } });