From 4094e9770643da4ec30ceeca07d3da691362ea90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20F=C3=BCting?= Date: Thu, 5 Dec 2024 13:09:40 +0100 Subject: [PATCH] feat-400: eslint runs successfully --- web/eslint.config.mjs | 545 +++++++++--------- web/lib/findModuleRoot.js | 4 +- .../__tests__/parseAminoacidMutation.test.ts | 2 +- .../__tests__/parseNucleotideMutation.test.ts | 2 +- .../Common/__tests__/parseVariant.test.ts | 2 +- web/src/types/styled.d.ts | 1 - 6 files changed, 268 insertions(+), 288 deletions(-) diff --git a/web/eslint.config.mjs b/web/eslint.config.mjs index 300a3f33ea..cb4a440f74 100644 --- a/web/eslint.config.mjs +++ b/web/eslint.config.mjs @@ -1,324 +1,305 @@ -import { fixupConfigRules, fixupPluginRules } from "@eslint/compat"; -import arrayFunc from "eslint-plugin-array-func"; -import cflint from "eslint-plugin-cflint"; -import _import from "eslint-plugin-import"; -import jest from "eslint-plugin-jest"; -import jsxA11Y from "eslint-plugin-jsx-a11y"; -import lodash from "eslint-plugin-lodash"; -import noLoops from "eslint-plugin-no-loops"; -import noSecrets from "eslint-plugin-no-secrets"; -import node from "eslint-plugin-node"; -import onlyAscii from "eslint-plugin-only-ascii"; -import promise from "eslint-plugin-promise"; -import react from "eslint-plugin-react"; -import reactHooks from "eslint-plugin-react-hooks"; -import reactPerf from "eslint-plugin-react-perf"; -import security from "eslint-plugin-security"; -import sonarjs from "eslint-plugin-sonarjs"; -import unicorn from "eslint-plugin-unicorn"; -import onlyWarn from "eslint-plugin-only-warn"; -import typescriptEslint from "@typescript-eslint/eslint-plugin"; -import prettier from "eslint-plugin-prettier"; -import globals from "globals"; -import tsParser from "@typescript-eslint/parser"; -import path from "node:path"; -import { fileURLToPath } from "node:url"; -import js from "@eslint/js"; -import { FlatCompat } from "@eslint/eslintrc"; - -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); +import { fixupConfigRules, fixupPluginRules } from '@eslint/compat' +import arrayFunc from 'eslint-plugin-array-func' +import cflint from 'eslint-plugin-cflint' +import importPlugin from 'eslint-plugin-import' +import jsxA11Y from 'eslint-plugin-jsx-a11y' +import lodash from 'eslint-plugin-lodash' +import noLoops from 'eslint-plugin-no-loops' +import noSecrets from 'eslint-plugin-no-secrets' +import node from 'eslint-plugin-node' +import onlyAscii from 'eslint-plugin-only-ascii' +import promise from 'eslint-plugin-promise' +import react from 'eslint-plugin-react' +import reactHooks from 'eslint-plugin-react-hooks' +import reactPerf from 'eslint-plugin-react-perf' +import security from 'eslint-plugin-security' +import sonarjs from 'eslint-plugin-sonarjs' +import unicorn from 'eslint-plugin-unicorn' +import onlyWarn from 'eslint-plugin-only-warn' +import typescriptEslint from '@typescript-eslint/eslint-plugin' +import prettier from 'eslint-plugin-prettier' +import globals from 'globals' +import tsParser from '@typescript-eslint/parser' +import path from 'node:path' +import { fileURLToPath } from 'node:url' +import js from '@eslint/js' +import { FlatCompat } from '@eslint/eslintrc' + +const __filename = fileURLToPath(import.meta.url) +const __dirname = path.dirname(__filename) const compat = new FlatCompat({ - baseDirectory: __dirname, - recommendedConfig: js.configs.recommended, - allConfig: js.configs.all -}); + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, + allConfig: js.configs.all, +}) -export default [{ +export default [ + { ignores: [ - "**/3rdparty", - "**/.build", - "**/.cache", - "**/.env", - "**/.eslintrc.js", - "**/.github", - "**/.idea", - "**/.ignore", - "**/.reports", - "**/.vscode", - "config/next/lib/EmitFilePlugin.js", - "infra/lambda-at-edge/basicAuth.js", - "**/node_modules", - "**/public", - "**/styles", - "**/tsconfig.json", + '**/3rdparty', + '**/.build', + '**/.next', + '**/.coverage', + '**/.playwright-report', + '**/.cache', + '**/.env', + '**/.github', + '**/.idea', + '**/.ignore', + '**/.reports', + '**/.vscode', + 'config/next/lib/EmitFilePlugin.js', + 'infra/lambda-at-edge/basicAuth.js', + '**/node_modules', + '**/public', + '**/styles', + '**/tsconfig.json', ], -}, ...fixupConfigRules(compat.extends( - "eslint:recommended", - "airbnb", - "airbnb-typescript", - "airbnb/hooks", - "react-app", - "next/core-web-vitals", - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended", - "plugin:@typescript-eslint/recommended-requiring-type-checking", - "plugin:array-func/all", - "plugin:import/errors", - "plugin:import/typescript", - "plugin:import/warnings", - "plugin:jest/recommended", - "plugin:jest/style", - "plugin:jsx-a11y/recommended", - "plugin:lodash/recommended", - "plugin:promise/recommended", - "plugin:react/recommended", - "plugin:react-perf/all", - "plugin:security/recommended", - "plugin:sonarjs/recommended", - "plugin:unicorn/recommended", - "plugin:prettier/recommended", -)), { + }, + { plugins: { - "array-func": fixupPluginRules(arrayFunc), - cflint, - import: fixupPluginRules(_import), - jest: fixupPluginRules(jest), - "jsx-a11y": fixupPluginRules(jsxA11Y), - lodash: fixupPluginRules(lodash), - "no-loops": noLoops, - "no-secrets": noSecrets, - node, - "only-ascii": onlyAscii, - promise: fixupPluginRules(promise), - react: fixupPluginRules(react), - "react-hooks": fixupPluginRules(reactHooks), - "react-perf": fixupPluginRules(reactPerf), - security: fixupPluginRules(security), - sonarjs: fixupPluginRules(sonarjs), - unicorn: fixupPluginRules(unicorn), - "only-warn": onlyWarn, - "@typescript-eslint": fixupPluginRules(typescriptEslint), - prettier: fixupPluginRules(prettier), + 'array-func': arrayFunc, + 'cflint': fixupPluginRules(cflint), + 'import': importPlugin, + 'jsx-a11y': jsxA11Y, + 'lodash': lodash, + 'no-loops': noLoops, + 'no-secrets': noSecrets, + node, + 'only-ascii': onlyAscii, + promise, + react, + 'react-hooks': reactHooks, + 'react-perf': reactPerf, + security, + sonarjs, + unicorn, + 'only-warn': onlyWarn, + '@typescript-eslint': typescriptEslint, + prettier, }, linterOptions: { - reportUnusedDisableDirectives: true, + reportUnusedDisableDirectives: true, }, languageOptions: { - globals: { - ...globals.browser, - ...globals.jest, - ...globals.node, + globals: { + ...globals.browser, + ...globals.node, + }, + + parser: tsParser, + ecmaVersion: 'latest', + sourceType: 'module', + + parserOptions: { + ecmaFeatures: { + jsx: true, }, - parser: tsParser, - ecmaVersion: "latest", - sourceType: "module", - - parserOptions: { - ecmaFeatures: { - jsx: true, - globalReturn: false, - }, - - project: ["/home/simon/eth/covariants/web/tsconfig.eslint.json"], - tsconfigRootDir: "/home/simon/eth/covariants/web", - warnOnUnsupportedTypeScriptVersion: true, - }, + project: ['./tsconfig.eslint.json'], + warnOnUnsupportedTypeScriptVersion: true, + }, }, settings: { - react: { - version: "detect", - }, + 'react': { + version: 'detect', + }, - "import/parsers": { - "@typescript-eslint/parser": [".js", ".jsx", ".ts", ".tsx"], - }, + 'import/parsers': { + '@typescript-eslint/parser': ['.js', '.jsx', '.ts', '.tsx'], + }, - "import/resolver": { - typescript: { - alwaysTryTypes: true, - }, + 'import/resolver': { + typescript: { + alwaysTryTypes: true, }, + }, }, rules: { - "@next/next/no-title-in-document-head": "off", - "@typescript-eslint/array-type": "off", - "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/explicit-module-boundary-types": "off", - "@typescript-eslint/lines-between-class-members": "off", - "@typescript-eslint/naming-convention": "off", - "@typescript-eslint/no-empty-function": "off", - "@typescript-eslint/no-shadow": "off", - "@typescript-eslint/unbound-method": ["off"], - "array-func/prefer-array-from": "off", - camelcase: "warn", - "cflint/no-substr": "warn", - "cflint/no-this-assignment": "warn", - - "import/extensions": ["warn", "ignorePackages", { - js: "never", - jsx: "never", - mjs: "never", - ts: "never", - tsx: "never", - }], - - "import/no-extraneous-dependencies": ["warn", { - devDependencies: true, - }], - - "import/no-webpack-loader-syntax": "off", - "import/no-cycle": "off", - "import/order": "warn", - "import/prefer-default-export": "off", - "jest/consistent-test-it": "warn", - "jest/expect-expect": "warn", - "jest/no-done-callback": "warn", - - "jsx-a11y/label-has-associated-control": ["warn", { - assert: "either", - }], - - "lodash/chaining": "off", - "lodash/import-scope": "off", - "lodash/prefer-constant": "off", - "lodash/prefer-lodash-chain": "off", - "lodash/prefer-lodash-method": "off", - "lodash/prefer-lodash-typecheck": "off", - "lodash/prefer-noop": "off", - "lodash/prop-shorthand": "off", - "max-classes-per-file": "off", - - "no-console": ["warn", { - allow: ["info", "warn", "error"], - }], - - "no-loops/no-loops": "warn", - - "no-param-reassign": ["warn", { - ignorePropertyModificationsFor: ["draft"], - }], + '@next/next/no-title-in-document-head': 'off', + '@typescript-eslint/array-type': 'off', + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/lines-between-class-members': 'off', + '@typescript-eslint/naming-convention': 'off', + '@typescript-eslint/no-empty-function': 'off', + '@typescript-eslint/no-shadow': 'off', + '@typescript-eslint/unbound-method': ['off'], + 'array-func/prefer-array-from': 'off', + 'camelcase': 'warn', + 'cflint/no-substr': 'warn', + 'cflint/no-this-assignment': 'warn', + + 'import/extensions': [ + 'warn', + 'ignorePackages', + { + js: 'never', + jsx: 'never', + mjs: 'never', + ts: 'never', + tsx: 'never', + }, + ], - "no-secrets/no-secrets": ["warn", { - tolerance: 5, - }], + 'import/no-extraneous-dependencies': [ + 'warn', + { + devDependencies: true, + }, + ], - "no-shadow": "off", - "only-ascii/only-ascii": "warn", - "prefer-for-of": "off", - "prettier/prettier": "warn", - "react/jsx-curly-brace-presence": "off", + 'import/no-webpack-loader-syntax': 'off', + 'import/no-cycle': 'off', + 'import/order': 'warn', + 'import/prefer-default-export': 'off', - "react/jsx-filename-extension": ["warn", { - extensions: [".js", ".jsx", ".ts", ".tsx"], - }], + 'jsx-a11y/label-has-associated-control': [ + 'warn', + { + assert: 'either', + }, + ], + + 'lodash/chaining': 'off', + 'lodash/import-scope': 'off', + 'lodash/prefer-constant': 'off', + 'lodash/prefer-lodash-chain': 'off', + 'lodash/prefer-lodash-method': 'off', + 'lodash/prefer-lodash-typecheck': 'off', + 'lodash/prefer-noop': 'off', + 'lodash/prop-shorthand': 'off', + 'max-classes-per-file': 'off', + + 'no-console': [ + 'warn', + { + allow: ['info', 'warn', 'error'], + }, + ], - "react/jsx-props-no-spreading": "off", - "react/no-unused-prop-types": "off", - "react/prop-types": "off", - "react/require-default-props": "off", - "react/state-in-constructor": "off", - "security/detect-non-literal-fs-filename": "off", - "security/detect-object-injection": "off", - "sonarjs/cognitive-complexity": ["warn", 20], - "unicorn/escape-case": "off", - "unicorn/filename-case": "off", - "unicorn/new-for-builtins": "off", - "unicorn/no-abusive-eslint-disable": "warn", - "unicorn/no-array-callback-reference": "off", - "unicorn/no-array-for-each": "off", - "unicorn/no-array-reduce": "off", - "unicorn/no-fn-reference-in-iterator": "off", - "unicorn/no-null": "off", - "unicorn/no-reduce": "off", - "unicorn/no-useless-undefined": "off", - "unicorn/no-zero-fractions": "off", - "unicorn/prefer-node-protocol": "off", - "unicorn/prefer-query-selector": "off", - "unicorn/prefer-spread": "off", - "unicorn/prevent-abbreviations": "off", + 'no-loops/no-loops': 'warn', - "lines-between-class-members": ["warn", "always", { - exceptAfterSingleLine: true, - }], + 'no-param-reassign': [ + 'warn', + { + ignorePropertyModificationsFor: ['draft'], + }, + ], - "require-await": "off", - "@typescript-eslint/require-await": "off", - "no-unused-expressions": "off", - "@typescript-eslint/no-unused-expressions": "warn", - "@typescript-eslint/no-duplicate-imports": "off", - }, -}, { - files: ["src/pages/**/*", "src/types/**/*"], + 'no-secrets/no-secrets': [ + 'warn', + { + tolerance: 5, + }, + ], + + 'no-shadow': 'off', + 'only-ascii/only-ascii': 'warn', + 'prefer-for-of': 'off', + 'prettier/prettier': 'warn', + 'react/jsx-curly-brace-presence': 'off', + + 'react/jsx-filename-extension': [ + 'warn', + { + extensions: ['.js', '.jsx', '.ts', '.tsx'], + }, + ], + + 'react/jsx-props-no-spreading': 'off', + 'react/no-unused-prop-types': 'off', + 'react/prop-types': 'off', + 'react/require-default-props': 'off', + 'react/state-in-constructor': 'off', + 'security/detect-non-literal-fs-filename': 'off', + 'security/detect-object-injection': 'off', + 'sonarjs/cognitive-complexity': ['warn', 20], + 'unicorn/escape-case': 'off', + 'unicorn/filename-case': 'off', + 'unicorn/new-for-builtins': 'off', + 'unicorn/no-abusive-eslint-disable': 'warn', + 'unicorn/no-array-callback-reference': 'off', + 'unicorn/no-array-for-each': 'off', + 'unicorn/no-array-reduce': 'off', + 'unicorn/no-fn-reference-in-iterator': 'off', + 'unicorn/no-null': 'off', + 'unicorn/no-reduce': 'off', + 'unicorn/no-useless-undefined': 'off', + 'unicorn/no-zero-fractions': 'off', + 'unicorn/prefer-node-protocol': 'off', + 'unicorn/prefer-query-selector': 'off', + 'unicorn/prefer-spread': 'off', + 'unicorn/prevent-abbreviations': 'off', + + 'lines-between-class-members': [ + 'warn', + 'always', + { + exceptAfterSingleLine: true, + }, + ], - rules: { - "no-restricted-exports": "off", + 'require-await': 'off', + '@typescript-eslint/require-await': 'off', + 'no-unused-expressions': 'off', + '@typescript-eslint/no-unused-expressions': 'warn', + '@typescript-eslint/no-duplicate-imports': 'off', }, -}, { - files: ["**/*.d.ts"], + }, + { + files: ['src/pages/**/*', 'src/types/**/*'], rules: { - "@typescript-eslint/ban-types": ["warn", { - extendDefaults: true, - - types: { - object: false, - }, - }], - - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-unused-vars": "off", - "import/no-duplicates": "off", - "no-useless-constructor": "off", - "react/prefer-stateless-function": "off", + 'no-restricted-exports': 'off', }, -}, { - files: ["!src/**/*"], + }, + { + files: ['**/*.d.ts'], rules: { - "@typescript-eslint/no-unsafe-argument": "off", - "@typescript-eslint/no-unsafe-assignment": "off", - "@typescript-eslint/no-unsafe-call": "off", - "@typescript-eslint/no-unsafe-member-access": "off", - "@typescript-eslint/no-unsafe-return": "off", - "@typescript-eslint/no-var-requires": "off", - "@typescript-eslint/restrict-template-expressions": "off", - "global-require": "off", - "import/extensions": "off", - "import/no-anonymous-default-export": "off", - "import/no-import-module-exports": "off", - "security/detect-child-process": "off", - "sonarjs/cognitive-complexity": ["warn", 50], - "unicorn/prefer-module": "off", + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-unused-vars': 'off', + 'import/no-duplicates': 'off', + 'no-useless-constructor': 'off', + 'react/prefer-stateless-function': 'off', }, -}, { - files: ["config/jest/mocks/**/*.js"], + }, + { + files: ['!src/**/*'], rules: { - "no-constructor-return": "off", - "react/display-name": "off", + '@typescript-eslint/no-unsafe-argument': 'off', + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-unsafe-return': 'off', + '@typescript-eslint/no-var-requires': 'off', + '@typescript-eslint/restrict-template-expressions': 'off', + 'global-require': 'off', + 'import/extensions': 'off', + 'import/no-anonymous-default-export': 'off', + 'import/no-import-module-exports': 'off', + 'security/detect-child-process': 'off', + 'sonarjs/cognitive-complexity': ['warn', 50], + 'unicorn/prefer-module': 'off', }, -}, { - files: [ - "**/*.test.*", - "**/__test__/**", - "**/__tests__/**", - "**/test/**", - "**/tests/**", - ], + }, + { + files: ['**/*.test.*', '**/__test__/**', '**/__tests__/**', '**/test/**', '**/tests/**'], rules: { - "@typescript-eslint/no-unsafe-assignment": "off", - "@typescript-eslint/no-unsafe-call": "off", - "@typescript-eslint/no-unsafe-member-access": "off", - "@typescript-eslint/no-unsafe-return": "off", - "@typescript-eslint/restrict-template-expressions": "off", - "sonarjs/no-duplicate-string": "off", - "sonarjs/no-identical-functions": "off", + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-unsafe-return': 'off', + '@typescript-eslint/restrict-template-expressions': 'off', + 'sonarjs/no-duplicate-string': 'off', + 'sonarjs/no-identical-functions': 'off', }, -}]; \ No newline at end of file + }, +] diff --git a/web/lib/findModuleRoot.js b/web/lib/findModuleRoot.js index 062552a3f4..960c9b7dea 100644 --- a/web/lib/findModuleRoot.js +++ b/web/lib/findModuleRoot.js @@ -1,8 +1,8 @@ -import fs from 'fs-extra' import path from 'path' import { fileURLToPath } from 'url' +import fs from 'fs-extra' -/* eslint-disable no-loops/no-loops,no-param-reassign,no-plusplus */ +/* eslint-disable no-loops/no-loops,no-param-reassign */ export function findModuleRoot(maxDepth = 10) { let moduleRoot = fileURLToPath(new URL('.', import.meta.url)) while (--maxDepth) { diff --git a/web/src/components/Common/__tests__/parseAminoacidMutation.test.ts b/web/src/components/Common/__tests__/parseAminoacidMutation.test.ts index fe7b72afd7..1f0208ab40 100644 --- a/web/src/components/Common/__tests__/parseAminoacidMutation.test.ts +++ b/web/src/components/Common/__tests__/parseAminoacidMutation.test.ts @@ -1,5 +1,5 @@ -import { parseAminoacidMutation } from 'src/components/Common/parseAminoacidMutation' import { describe, it, expect } from 'vitest' +import { parseAminoacidMutation } from 'src/components/Common/parseAminoacidMutation' describe('parseAminoacidMutation', () => { it('should parse gene, ref, position, right', () => { diff --git a/web/src/components/Common/__tests__/parseNucleotideMutation.test.ts b/web/src/components/Common/__tests__/parseNucleotideMutation.test.ts index 97bee1e721..31710cee73 100644 --- a/web/src/components/Common/__tests__/parseNucleotideMutation.test.ts +++ b/web/src/components/Common/__tests__/parseNucleotideMutation.test.ts @@ -1,5 +1,5 @@ -import { parseNucleotideMutation } from 'src/components/Common/parseNucleotideMutation' import { describe, it, expect } from 'vitest' +import { parseNucleotideMutation } from 'src/components/Common/parseNucleotideMutation' describe('parseNucleotideMutation', () => { it('should parse left, position, right', () => { diff --git a/web/src/components/Common/__tests__/parseVariant.test.ts b/web/src/components/Common/__tests__/parseVariant.test.ts index c5cbb76053..42209ca3eb 100644 --- a/web/src/components/Common/__tests__/parseVariant.test.ts +++ b/web/src/components/Common/__tests__/parseVariant.test.ts @@ -1,5 +1,5 @@ -import { parseVariant } from 'src/components/Common/parseVariant' import { describe, it, expect } from 'vitest' +import { parseVariant } from 'src/components/Common/parseVariant' describe('parseVariant', () => { it('should accept "20A.EU2"', async () => { diff --git a/web/src/types/styled.d.ts b/web/src/types/styled.d.ts index ab00fd5a2c..a2af7adb67 100644 --- a/web/src/types/styled.d.ts +++ b/web/src/types/styled.d.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-empty-interface */ import { Theme } from 'src/theme' declare module 'styled-components' {