From 23e053e24ff661f406b47270336b3b557afc114a Mon Sep 17 00:00:00 2001 From: "C. Fuhrman" Date: Sun, 2 Feb 2025 12:40:12 -0500 Subject: [PATCH] =?UTF-8?q?normaliser=20config=20eslint=20M=C3=AAme=20conf?= =?UTF-8?q?ig=20pour=20extension=20VS=20Code=20et=20npx=20eslint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EvalueTonSavoir.code-workspace | 15 +++++- client/.eslintrc.cjs | 19 ------- client/eslint.config.js | 97 +++++++++++++++++++++++++--------- client/package-lock.json | 71 +++++++++++++++++++++++++ client/package.json | 3 ++ 5 files changed, 159 insertions(+), 46 deletions(-) delete mode 100644 client/.eslintrc.cjs diff --git a/EvalueTonSavoir.code-workspace b/EvalueTonSavoir.code-workspace index f18d936..2ee3b1c 100644 --- a/EvalueTonSavoir.code-workspace +++ b/EvalueTonSavoir.code-workspace @@ -16,5 +16,18 @@ "jest.disabledWorkspaceFolders": [ "EvalueTonSavoir" ] - } + }, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true + }, + "eslint.validate": [ + "javascript", + "typescript", + "javascriptreact", + "typescriptreact" + ], + // use the same eslint config as `npx eslint` + "eslint.experimental.useFlatConfig": true, + "eslint.nodePath": "./node_modules" + } diff --git a/client/.eslintrc.cjs b/client/.eslintrc.cjs deleted file mode 100644 index 43f6c4c..0000000 --- a/client/.eslintrc.cjs +++ /dev/null @@ -1,19 +0,0 @@ -// eslint-disable-next-line no-undef -module.exports = { - root: true, - env: { browser: true, es2020: true }, - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:react-hooks/recommended', - ], - ignorePatterns: ['dist', '.eslintrc.cjs'], - parser: '@typescript-eslint/parser', - plugins: ['react-refresh'], - rules: { - 'react-refresh/only-export-components': [ - 'warn', - { allowConstantExport: true }, - ], - }, -} diff --git a/client/eslint.config.js b/client/eslint.config.js index 56b57bd..4da1290 100644 --- a/client/eslint.config.js +++ b/client/eslint.config.js @@ -1,33 +1,78 @@ +import react from "eslint-plugin-react"; +import typescriptEslint from "@typescript-eslint/eslint-plugin"; +import typescriptParser from "@typescript-eslint/parser"; import globals from "globals"; import pluginJs from "@eslint/js"; -import tseslint from "typescript-eslint"; -import pluginReact from "eslint-plugin-react"; +import jest from "eslint-plugin-jest"; +import reactRefresh from "eslint-plugin-react-refresh"; +import unusedImports from "eslint-plugin-unused-imports"; +import eslintComments from "eslint-plugin-eslint-comments"; /** @type {import('eslint').Linter.Config[]} */ export default [ - { - ignores: ["dist/**"], // Place this at the root level - }, - { - files: ["src/**/*.{js,mjs,cjs,ts,jsx,tsx}"], - // ignores: ["./dist/**"], - languageOptions: { - globals: globals.browser, + { + ignores: ["node_modules", "dist/**/*"], }, - rules: { - "no-unused-vars": ["error", { - "argsIgnorePattern": "^_", - "varsIgnorePattern": "^_", - "caughtErrorsIgnorePattern": "^_" // Ignore catch clause parameters that start with _ - }], - }, - settings: { - react: { - version: "detect", // Automatically detect the React version - }, - }, - }, - pluginJs.configs.recommended, - ...tseslint.configs.recommended, - pluginReact.configs.flat.recommended, + { + files: ["**/*.{js,jsx,mjs,cjs,ts,tsx}"], + languageOptions: { + parser: typescriptParser, + parserOptions: { + ecmaFeatures: { + jsx: true, + }, + }, + globals: { + ...globals.serviceworker, + ...globals.browser, + ...globals.jest, + ...globals.node, + process: "readonly", + }, + }, + plugins: { + "@typescript-eslint": typescriptEslint, + react, + jest, + "react-refresh": reactRefresh, + "unused-imports": unusedImports, + "eslint-comments": eslintComments + }, + rules: { + // Auto-fix unused variables + "@typescript-eslint/no-unused-vars": "off", + "no-unused-vars": "off", + "unused-imports/no-unused-vars": [ + "warn", + { + "vars": "all", + "varsIgnorePattern": "^_", + "args": "after-used", + "argsIgnorePattern": "^_", + "destructuredArrayIgnorePattern": "^_" + } + ], + + // Handle directive comments + "eslint-comments/no-unused-disable": "warn", + "eslint-comments/no-unused-enable": "warn", + + // Jest configurations + "jest/valid-expect": ["error", { "alwaysAwait": true }], + "jest/prefer-to-have-length": "warn", + "jest/no-disabled-tests": "warn", + "jest/no-focused-tests": "error", + "jest/no-identical-title": "error", + + // React refresh + "react-refresh/only-export-components": ["warn", { + allowConstantExport: true + }], + }, + settings: { + react: { + version: "detect", + }, + }, + } ]; diff --git a/client/package-lock.json b/client/package-lock.json index 9b6d01c..534304c 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -54,9 +54,12 @@ "@typescript-eslint/parser": "^8.5.0", "@vitejs/plugin-react-swc": "^3.7.2", "eslint": "^9.18.0", + "eslint-plugin-eslint-comments": "^3.2.0", + "eslint-plugin-jest": "^28.11.0", "eslint-plugin-react": "^7.37.3", "eslint-plugin-react-hooks": "^5.1.0-rc-206df66e-20240912", "eslint-plugin-react-refresh": "^0.4.12", + "eslint-plugin-unused-imports": "^4.1.4", "globals": "^15.14.0", "identity-obj-proxy": "^3.0.0", "jest": "^29.7.0", @@ -6695,6 +6698,59 @@ } } }, + "node_modules/eslint-plugin-eslint-comments": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-eslint-comments/-/eslint-plugin-eslint-comments-3.2.0.tgz", + "integrity": "sha512-0jkOl0hfojIHHmEHgmNdqv4fmh7300NdpA9FFpF7zaoLvB/QeXOGNLIo86oAveJFrfB1p05kC8hpEMHM8DwWVQ==", + "dev": true, + "dependencies": { + "escape-string-regexp": "^1.0.5", + "ignore": "^5.0.5" + }, + "engines": { + "node": ">=6.5.0" + }, + "funding": { + "url": "https://github.com/sponsors/mysticatea" + }, + "peerDependencies": { + "eslint": ">=4.19.1" + } + }, + "node_modules/eslint-plugin-eslint-comments/node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "dev": true, + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/eslint-plugin-jest": { + "version": "28.11.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-28.11.0.tgz", + "integrity": "sha512-QAfipLcNCWLVocVbZW8GimKn5p5iiMcgGbRzz8z/P5q7xw+cNEpYqyzFMtIF/ZgF2HLOyy+dYBut+DoYolvqig==", + "dev": true, + "dependencies": { + "@typescript-eslint/utils": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "engines": { + "node": "^16.10.0 || ^18.12.0 || >=20.0.0" + }, + "peerDependencies": { + "@typescript-eslint/eslint-plugin": "^6.0.0 || ^7.0.0 || ^8.0.0", + "eslint": "^7.0.0 || ^8.0.0 || ^9.0.0", + "jest": "*" + }, + "peerDependenciesMeta": { + "@typescript-eslint/eslint-plugin": { + "optional": true + }, + "jest": { + "optional": true + } + } + }, "node_modules/eslint-plugin-react": { "version": "7.37.4", "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.37.4.tgz", @@ -6793,6 +6849,21 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/eslint-plugin-unused-imports": { + "version": "4.1.4", + "resolved": "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-4.1.4.tgz", + "integrity": "sha512-YptD6IzQjDardkl0POxnnRBhU1OEePMV0nd6siHaRBbd+lyh6NAhFEobiznKU7kTsSsDeSD62Pe7kAM1b7dAZQ==", + "dev": true, + "peerDependencies": { + "@typescript-eslint/eslint-plugin": "^8.0.0-0 || ^7.0.0 || ^6.0.0 || ^5.0.0", + "eslint": "^9.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "@typescript-eslint/eslint-plugin": { + "optional": true + } + } + }, "node_modules/eslint-scope": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.2.0.tgz", diff --git a/client/package.json b/client/package.json index 939257a..1888165 100644 --- a/client/package.json +++ b/client/package.json @@ -58,9 +58,12 @@ "@typescript-eslint/parser": "^8.5.0", "@vitejs/plugin-react-swc": "^3.7.2", "eslint": "^9.18.0", + "eslint-plugin-eslint-comments": "^3.2.0", + "eslint-plugin-jest": "^28.11.0", "eslint-plugin-react": "^7.37.3", "eslint-plugin-react-hooks": "^5.1.0-rc-206df66e-20240912", "eslint-plugin-react-refresh": "^0.4.12", + "eslint-plugin-unused-imports": "^4.1.4", "globals": "^15.14.0", "identity-obj-proxy": "^3.0.0", "jest": "^29.7.0",