From ceb94389337d030f816cc7f05ee2debf7d6848d8 Mon Sep 17 00:00:00 2001 From: Nathan Richards Date: Mon, 15 Apr 2024 19:23:21 +0200 Subject: [PATCH] spike: trying to get eslint v9 working --- .eslintrc | 4 -- .eslintrc.base | 75 --------------------------------- eslint.config.base.js | 80 ++++++++++++++++++++++++++++++++++++ eslint.config.js | 19 +++++++++ package.json | 1 + packages/widget/package.json | 2 +- yarn.lock | 8 ++++ 7 files changed, 109 insertions(+), 80 deletions(-) delete mode 100644 .eslintrc delete mode 100644 .eslintrc.base create mode 100644 eslint.config.base.js create mode 100644 eslint.config.js diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 5a06547f3..000000000 --- a/.eslintrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "root": true, - "extends": ["react-app", "plugin:prettier/recommended", "./.eslintrc.base"] -} diff --git a/.eslintrc.base b/.eslintrc.base deleted file mode 100644 index cd0cfe4a6..000000000 --- a/.eslintrc.base +++ /dev/null @@ -1,75 +0,0 @@ -{ - "env": { - "es2021": true, - "browser": true, - "node": true - }, - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaFeatures": { - "jsx": true, - "modules": true - }, - "ecmaVersion": "latest", - "sourceType": "module" - }, - "rules": { - "@typescript-eslint/consistent-type-imports": "warn", - "@typescript-eslint/explicit-module-boundary-types": "off", - "@typescript-eslint/no-shadow": "off", - "@typescript-eslint/no-unused-vars": "warn", - "class-methods-use-this": "off", - "comma-dangle": ["error", "always-multiline"], - "curly": 1, - "import/extensions": "off", - "import/no-default-export": "error", - "import/no-extraneous-dependencies": "off", - "import/no-unresolved": 0, - "import/prefer-default-export": "off", - "indent": "off", - "jsx-quotes": ["error", "prefer-double"], - "linebreak-style": "off", - "max-len": "off", - "newline-per-chained-call": "off", - "no-bitwise": "off", - "no-console": [ - "error", - { - "allow": ["warn", "error"] - } - ], - "no-continue": "off", - "no-implicit-any-catch": "off", - "no-nested-ternary": "off", - "no-param-reassign": "off", - "no-plusplus": "off", - "no-restricted-syntax": "off", - "no-shadow": "off", - "no-unused-expressions": "warn", - "no-unused-vars": "off", - "no-var": "warn", - "object-curly-newline": "off", - "prettier/prettier": "error", - "react/function-component-definition": "off", - "react/jsx-filename-extension": [ - 1, - { - "extensions": [".ts", ".tsx"] - } - ], - "react/jsx-one-expression-per-line": "off", - "react/jsx-props-no-spreading": "off", - "react/jsx-uses-react": "off", - "react/prop-types": 0, - "react/react-in-jsx-scope": "off", - "react/require-default-props": "off", - "quotes": [ - "error", - "single", - { - "avoidEscape": true, - "allowTemplateLiterals": true - } - ] - } -} diff --git a/eslint.config.base.js b/eslint.config.base.js new file mode 100644 index 000000000..97e9f610d --- /dev/null +++ b/eslint.config.base.js @@ -0,0 +1,80 @@ +import typescriptParser from '@typescript-eslint/parser'; +import globals from 'globals'; + +export const eslintBaseConfig = { + languageOptions: { + parser: typescriptParser, + parserOptions: { + ecmaFeatures: { + jsx: true, + modules: true, + }, + ecmaVersion: 'latest', + sourceType: 'module', + }, + globals: { + ...globals.browser, + ...globals.node, + ...globals.es2021, + }, + }, + rules: { + // '@typescript-eslint/consistent-type-imports': 'warn', + // '@typescript-eslint/explicit-module-boundary-types': 'off', + // '@typescript-eslint/no-shadow': 'off', + // '@typescript-eslint/no-unused-vars': 'warn', + 'class-methods-use-this': 'off', + 'comma-dangle': ['error', 'always-multiline'], + curly: 1, + // 'import/extensions': 'off', + // 'import/no-default-export': 'error', + // 'import/no-extraneous-dependencies': 'off', + // 'import/no-unresolved': 0, + // 'import/prefer-default-export': 'off', + indent: 'off', + 'jsx-quotes': ['error', 'prefer-double'], + 'linebreak-style': 'off', + 'max-len': 'off', + 'newline-per-chained-call': 'off', + 'no-bitwise': 'off', + 'no-console': [ + 'error', + { + allow: ['warn', 'error'], + }, + ], + 'no-continue': 'off', + 'no-implicit-any-catch': 'off', + 'no-nested-ternary': 'off', + 'no-param-reassign': 'off', + 'no-plusplus': 'off', + 'no-restricted-syntax': 'off', + 'no-shadow': 'off', + 'no-unused-expressions': 'warn', + 'no-unused-vars': 'off', + 'no-var': 'warn', + 'object-curly-newline': 'off', + 'prettier/prettier': 'error', + 'react/function-component-definition': 'off', + // 'react/jsx-filename-extension': [ + // 1, + // { + // extensions: ['.ts', '.tsx'], + // }, + // ], + 'react/jsx-one-expression-per-line': 'off', + 'react/jsx-props-no-spreading': 'off', + 'react/jsx-uses-react': 'off', + 'react/prop-types': 0, + 'react/react-in-jsx-scope': 'off', + 'react/require-default-props': 'off', + quotes: [ + 'error', + 'single', + { + avoidEscape: true, + allowTemplateLiterals: true, + }, + ], + }, +}; diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 000000000..4da048bdc --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,19 @@ +// import { FlatCompat } from '@eslint/eslintrc'; +import { eslintBaseConfig } from './eslint.config.base.js'; +import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'; + +// set up for compat.extends('') - this can be used to add config in a legacy style. +// import * as path from 'path'; +// import { fileURLToPath } from 'url'; +// +// const __filename = fileURLToPath(import.meta.url); +// const __dirname = path.dirname(__filename); +// const compat = new FlatCompat({ resolvePluginsRelativeTo: __dirname }); + +export default [ + eslintPluginPrettierRecommended, + eslintBaseConfig, + { + files: ['src/**/*.{ts,tsx}'], + }, +]; diff --git a/package.json b/package.json index 5602b4cae..480737844 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "eslint-plugin-prettier": "^5.1.3", "eslint-plugin-react": "^7.34.1", "eslint-plugin-react-hooks": "^4.6.0", + "globals": "^15.0.0", "husky": "^9.0.11", "lerna": "8.1.2", "lint-staged": "^15.2.2", diff --git a/packages/widget/package.json b/packages/widget/package.json index e4a2cbce1..4f892bce6 100644 --- a/packages/widget/package.json +++ b/packages/widget/package.json @@ -17,7 +17,7 @@ "check:types": "tsc --noEmit", "check:circular-deps": "madge --circular $(find ./src -name '*.ts' -o -name '*.tsx')", "check:circular-deps-graph": "madge --circular $(find ./src -name '*.ts' -o -name '*.tsx') --image graph.svg", - "lint": "eslint --ext .tsx --ext .ts ./src", + "lint": "eslint -c ../../eslint.config.js ./src", "pre-commit:validate": "yarn lint --fix", "pre-push:validate": "yarn check:types & yarn check:circular-deps" }, diff --git a/yarn.lock b/yarn.lock index c965ac1ad..9d243c74d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12791,6 +12791,13 @@ __metadata: languageName: node linkType: hard +"globals@npm:^15.0.0": + version: 15.0.0 + resolution: "globals@npm:15.0.0" + checksum: 10/f2f927fe457a5ed2c27b00b77ca22ec31fe5624aac2da178e228a5bcc9928df0f1853e79d6499e04283d184ea13e26cc8127e890098490c9fee616363cdf0d76 + languageName: node + linkType: hard + "globalthis@npm:^1.0.3": version: 1.0.3 resolution: "globalthis@npm:1.0.3" @@ -18533,6 +18540,7 @@ __metadata: eslint-plugin-prettier: "npm:^5.1.3" eslint-plugin-react: "npm:^7.34.1" eslint-plugin-react-hooks: "npm:^4.6.0" + globals: "npm:^15.0.0" husky: "npm:^9.0.11" lerna: "npm:8.1.2" lint-staged: "npm:^15.2.2"