From 95e5a22f77c094d1f3b63f698eb54e13b7978e59 Mon Sep 17 00:00:00 2001 From: Julian Dehm Date: Wed, 27 Nov 2024 17:32:47 +0100 Subject: [PATCH] replace deprecated .eslintrc with eslint.config.mjs I tried to include all the rules and plugins from the old config as far as they are compatible with eslint 9. eslint-config-standard and eslint-config-standard-react seem to be dead and have been forked into neoconfig.The promise and n plugin is included in neoconfig afaik and doesn't need to be added explicitly. --- .eslintrc | 57 ----------------------------------------------- eslint.config.mjs | 50 +++++++++++++++++++++++++++++++++++++++++ package.json | 12 +++++----- 3 files changed, 55 insertions(+), 64 deletions(-) delete mode 100644 .eslintrc create mode 100644 eslint.config.mjs diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 6714fd420..000000000 --- a/.eslintrc +++ /dev/null @@ -1,57 +0,0 @@ -{ - "parser": "@babel/eslint-parser", - "parserOptions": { - "ecmaVersion": 6, - "sourceType": "module", - "requireConfigFile": false, - "ecmaFeatures": { - "experimentalObjectRestSpread": true - } - }, - "env": { - "browser": true, - "commonjs": true, - "es6": true, - "jquery": true, - "jest/globals": true - }, - "extends": [ - "standard", - "standard-jsx", - "plugin:jsx-a11y/recommended", - "plugin:react/recommended", - "plugin:import/recommended", - "plugin:n/recommended", - "plugin:react-hooks/recommended", - "plugin:promise/recommended" - ], - "rules": { - "jsx-quotes": [2, "prefer-double"], - "jsx-a11y/no-onchange": "off", - "react/prop-types": "off", - "n/no-missing-require": "off", - "n/no-unsupported-features/es-syntax": "off", - "n/no-missing-import": "off", - "n/no-unpublished-import": "off", - "n/no-extraneous-import": "off", - "no-restricted-syntax": ["error", "TemplateLiteral"] - }, - "plugins": [ - "jsx-a11y", - "jest", - "promise" - ], - "ignorePatterns": [ - "node_modules/", - "venv/" - ], - "settings": { - "import/core-modules": [ django ], - "import/resolver": { - "node": { - "extensions": [".js", ".jsx"] - } - } - } -} - diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 000000000..54f3c4533 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,50 @@ +import globals from "globals"; +import hooksPlugin from "eslint-plugin-react-hooks"; +import importPlugin from "eslint-plugin-import"; +import jsxA11y from "eslint-plugin-jsx-a11y"; +import pluginJest from "eslint-plugin-jest"; +import pluginJs from "@eslint/js"; +import neostandard, { plugins } from "neostandard"; + +export default [ + ...neostandard(), + jsxA11y.flatConfigs.recommended, + importPlugin.flatConfigs.recommended, + { + files: ["**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx,jest.jsx,jest.js}"], + ignores: ["node_modules/", "venv/", "static/"], + languageOptions: { + ...jsxA11y.flatConfigs.recommended.languageOptions, + globals: { + ...globals.browser, + ...pluginJest.environments.globals.globals, + ...globals.jquery, + }, + ecmaVersion: "latest", + parserOptions: { + ecmaFeatures: { + jsx: true, + "experimentalObjectRestSpread": true, + }, + }, + }, + plugins: { + jest: pluginJest, + "react-hooks": hooksPlugin, + }, + rules: { + "no-restricted-syntax": ["error", "TemplateLiteral"], + "jsx-a11y/no-onchange": "off", + "@stylistic/jsx-quotes": [2, "prefer-double"], + ...hooksPlugin.configs.recommended.rules, + }, + settings: { + "import/core-modules": ["django"], + "import/resolver": { + node: { + extensions: [".js", ".jsx"], + }, + }, + }, + }, +]; diff --git a/package.json b/package.json index 1049b47db..88ae2aa9d 100644 --- a/package.json +++ b/package.json @@ -36,32 +36,30 @@ "@babel/plugin-transform-runtime": "7.25.9", "@babel/preset-env": "7.26.0", "@babel/preset-react": "7.25.9", + "@eslint/js": "9.13.0", "@maplibre/maplibre-gl-leaflet": "0.0.22", "@react-leaflet/core": "^2.1.0", "@testing-library/jest-dom": "6.4.8", "@testing-library/react": "15.0.7", "eslint": "9.15.0", - "eslint-config-standard": "17.1.0", - "eslint-config-standard-jsx": "11.0.0", "eslint-plugin-import": "2.31.0", "eslint-plugin-jest": "28.9.0", "eslint-plugin-jsx-a11y": "6.10.2", - "eslint-plugin-n": "17.14.0", - "eslint-plugin-promise": "7.2.1", - "eslint-plugin-react": "7.37.2", "eslint-plugin-react-hooks": "5.0.0", "esquery": "1.6.0", + "globals": "15.12.0", "husky": "9.0.11", "jest": "29.7.0", "jest-environment-jsdom": "29.7.0", - "lint-staged": "15.2.10" + "lint-staged": "15.2.10", + "neostandard": "0.11.7" }, "repository": { "type": "git", "url": "git@github.com:liqd/adhocracy4.git" }, "scripts": { - "lint": "eslint adhocracy4 --ext .js,.jsx", + "lint": "eslint adhocracy4", "lint-staged": "lint-staged", "lint-fix": "eslint --fix --ext .js,.jsx .", "prepare": "husky",