From d9eac00b7835dd41ac74c065acb8ff755457c0dc Mon Sep 17 00:00:00 2001 From: Simon Reinisch Date: Mon, 28 Oct 2024 15:09:58 +0100 Subject: [PATCH] Update ESLint to v9 --- .eslintrc | 72 -- .github/workflows/main.yml | 6 + .gitignore | 1 + eslint.config.mjs | 67 ++ package.json | 38 +- packages/preact/src/SelectionArea.tsx | 1 - packages/react/src/SelectionArea.tsx | 1 - packages/vanilla/demo/index.ts | 3 +- packages/vanilla/src/EventEmitter.ts | 1 - packages/vanilla/src/index.ts | 1 - packages/vue/demo/App.vue | 71 +- packages/vue/src/SelectionArea.vue | 2 +- pnpm-lock.yaml | 1170 ++++++++++++------------- 13 files changed, 693 insertions(+), 741 deletions(-) delete mode 100644 .eslintrc create mode 100644 eslint.config.mjs diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 93e38c8..0000000 --- a/.eslintrc +++ /dev/null @@ -1,72 +0,0 @@ -{ - "globals": { - "VERSION": true - }, - "extends": [ - "eslint:recommended" - ], - "plugins": [ - "@typescript-eslint" - ], - "rules": { - "semi": ["error", "always"], - "no-console": "error" - }, - "overrides": [ - { - "files": "*.ts", - "parser": "@typescript-eslint/parser", - "extends": [ - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended" - ], - "rules": { - "@typescript-eslint/no-non-null-assertion": "off" - } - }, - { - "files": "*.tsx", - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module", - "ecmaFeatures": { - "jsx": true - } - }, - "extends": [ - "plugin:react/recommended", - "plugin:@typescript-eslint/recommended" - ], - "plugins": [ - "react" - ], - "settings": { - "react": { - "version": "detect" - } - }, - "rules": { - "react/react-in-jsx-scope": "off", - "react/prop-types": "off" - } - }, - { - "files": "*.vue", - "parser": "vue-eslint-parser", - "parserOptions": { - "parser": "@typescript-eslint/parser", - "extraFileExtensions": [".vue"] - }, - "extends": [ - "eslint:recommended", - "plugin:vue/vue3-essential", - "@vue/eslint-config-typescript/recommended" - ], - "rules": { - "vue/multi-word-component-names": "off", - "no-console": "error" - } - } - ] -} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 272af06..06c1011 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,6 +24,12 @@ jobs: - name: Install dependencies run: pnpm install + - name: Setup ESLint cache + uses: actions/cache@v4 + with: + path: ./.eslintcache + key: ${{ runner.os }}-eslint-${{ hashFiles('**/pnpm-lock.yaml', '**/eslint.config.mjs') }} + - name: Lint run: pnpm run lint diff --git a/.gitignore b/.gitignore index 1b1fa53..1da1e0f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ dist *.iml .idea/ .log +.eslintcache diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..d107f38 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,67 @@ +import js from '@eslint/js'; +import ts from 'typescript-eslint'; +import react from 'eslint-plugin-react'; +import vue from 'eslint-plugin-vue'; +import tsParser from '@typescript-eslint/parser'; + +export default [ + js.configs.recommended, + ...ts.configs.recommended, + ...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'], + languageOptions: { + parser: tsParser, + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + ecmaFeatures: { + jsx: true + } + } + }, + settings: { + react: { + version: 'detect' + } + }, + rules: { + 'react/react-in-jsx-scope': 'off', + 'react/prop-types': 'off', + 'no-console': 'error' + }, + }, + { + files: ['**/*.vue'], + languageOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + parserOptions: { + extraFileExtensions: ['.vue'], + parser: tsParser + } + }, + rules: { + 'vue/multi-word-component-names': 'off', + 'no-console': 'error' + } + } +]; diff --git a/package.json b/package.json index 9dd1501..8745099 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}'", + "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", @@ -18,28 +18,30 @@ "release:patch": "lerna version patch" }, "devDependencies": { + "@eslint/js": "9.13.0", "@preact/preset-vite": "2.9.1", - "@types/node": "22.5.5", - "@types/react": "18.3.8", - "@types/react-dom": "18.3.0", - "@typescript-eslint/eslint-plugin": "8.6.0", - "@typescript-eslint/parser": "8.6.0", - "@vitejs/plugin-react": "4.3.1", + "@types/node": "22.8.1", + "@types/react": "18.3.12", + "@types/react-dom": "18.3.1", + "@typescript-eslint/eslint-plugin": "8.11.0", + "@typescript-eslint/parser": "8.11.0", + "@vitejs/plugin-react": "4.3.3", "@vitejs/plugin-vue": "5.1.4", - "@vue/compiler-sfc": "3.5.8", - "@vue/eslint-config-typescript": "13.0.0", - "eslint": "8.57.1", - "eslint-plugin-react": "7.36.1", - "eslint-plugin-vue": "9.28.0", + "@vue/compiler-sfc": "3.5.12", + "@vue/eslint-config-typescript": "14.1.3", + "eslint": "9.13.0", + "eslint-plugin-react": "7.37.2", + "eslint-plugin-vue": "9.30.0", "lerna": "8.1.8", - "preact": "10.24.0", + "preact": "10.24.3", "react": "18.3.1", "react-dom": "18.3.1", - "typescript": "5.6.2", - "vite": "5.4.7", + "typescript": "5.6.3", + "typescript-eslint": "8.11.0", + "vite": "5.4.10", "vite-plugin-banner": "0.8.0", - "vite-plugin-dts": "4.2.1", - "vue": "3.5.8", - "vue-tsc": "2.1.6" + "vite-plugin-dts": "4.3.0", + "vue": "3.5.12", + "vue-tsc": "2.1.8" } } diff --git a/packages/preact/src/SelectionArea.tsx b/packages/preact/src/SelectionArea.tsx index e8626ba..0948133 100644 --- a/packages/preact/src/SelectionArea.tsx +++ b/packages/preact/src/SelectionArea.tsx @@ -1,4 +1,3 @@ -/* eslint-disable no-use-before-define */ import VanillaSelectionArea from '@viselect/vanilla'; import {SelectionEvents, PartialSelectionOptions} from '@viselect/vanilla'; import {createContext, createRef, FunctionalComponent, JSX} from 'preact'; diff --git a/packages/react/src/SelectionArea.tsx b/packages/react/src/SelectionArea.tsx index 203f9cf..bb4f27b 100644 --- a/packages/react/src/SelectionArea.tsx +++ b/packages/react/src/SelectionArea.tsx @@ -1,4 +1,3 @@ -/* eslint-disable no-use-before-define */ import VanillaSelectionArea from '@viselect/vanilla'; import {SelectionEvents, PartialSelectionOptions} from '@viselect/vanilla'; import React, {useEffect, createContext, useContext, useRef, useState} from 'react'; diff --git a/packages/vanilla/demo/index.ts b/packages/vanilla/demo/index.ts index 5663b4c..ae217fc 100644 --- a/packages/vanilla/demo/index.ts +++ b/packages/vanilla/demo/index.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import SelectionArea from '../src'; import './index.css'; @@ -40,7 +41,7 @@ const selection = new SelectionArea({ } }); -/* eslint-disable no-console */ + selection .on('beforestart', (evt) => console.log('beforestart', evt)) .on('start', (evt) => console.log('start', evt)) diff --git a/packages/vanilla/src/EventEmitter.ts b/packages/vanilla/src/EventEmitter.ts index 4a5f620..46f85ff 100644 --- a/packages/vanilla/src/EventEmitter.ts +++ b/packages/vanilla/src/EventEmitter.ts @@ -32,7 +32,6 @@ export class EventTarget { } // Let's also support on, off and emit like node - /* eslint-disable no-invalid-this */ public on = this.addEventListener; public off = this.removeEventListener; public emit = this.dispatchEvent; diff --git a/packages/vanilla/src/index.ts b/packages/vanilla/src/index.ts index c7d1d18..6d77636 100644 --- a/packages/vanilla/src/index.ts +++ b/packages/vanilla/src/index.ts @@ -749,7 +749,6 @@ export default class SelectionArea extends EventTarget { super.unbindAllListeners(); } - /* eslint-disable no-invalid-this */ disable = this._toggleStartEvents.bind(this, false); enable = this._toggleStartEvents; diff --git a/packages/vue/demo/App.vue b/packages/vue/demo/App.vue index 78a6546..49f9d5b 100644 --- a/packages/vue/demo/App.vue +++ b/packages/vue/demo/App.vue @@ -1,29 +1,50 @@