From 9b0ccf8a824fc1f42e333464d62acf764e6760a1 Mon Sep 17 00:00:00 2001 From: Bastien DUMONT <bdumont@grandlyon.com> Date: Thu, 4 May 2023 13:49:28 +0000 Subject: [PATCH] chore: add additional eslint rules for typescript --- .eslintrc.js | 35 ++++++++++++++----- src/components/Charts/Bar.tsx | 6 ++-- .../Connection/ConnectionResult.tsx | 2 +- src/components/Connection/FormOAuth.tsx | 2 +- .../Connection/GRDFConnect/GrdfInit.tsx | 2 +- src/components/Ecogesture/EcogestureView.tsx | 3 +- .../EcogestureFormEquipment.tsx | 6 ++-- .../EcogestureFormSingleChoice.tsx | 4 +-- .../Export/exportDoneModal.spec.tsx | 2 +- src/components/FormGlobal/FormNavigation.tsx | 4 +-- src/components/Header/CozyBar.tsx | 6 ++-- .../ProfileTypeFormDateSelection.tsx | 4 +-- .../ProfileTypeFormMultiChoice.tsx | 4 +-- .../ProfileType/ProfileTypeFormNumber.tsx | 4 +-- .../ProfileTypeFormNumberSelection.tsx | 4 +-- .../ProfileTypeFormSingleChoice.tsx | 4 +-- src/migrations/migration.data.ts | 2 +- src/targets/services/service.ts | 2 +- 18 files changed, 58 insertions(+), 38 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index ecbdf8bed..88b5bcd2d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,14 +1,37 @@ module.exports = { - parser: '@typescript-eslint/parser', // Specifies the ESLint parser extends: [ 'eslint:recommended', 'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react 'plugin:react-hooks/recommended', - 'plugin:@typescript-eslint/eslint-recommended', // Uses the recommended rules from @typescript-eslint/eslint-plugin 'prettier', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier 'plugin:prettier/recommended', // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. ], - plugins: ['@typescript-eslint'], + overrides: [ + { + extends: [ + 'plugin:@typescript-eslint/recommended', + 'plugin:@typescript-eslint/eslint-recommended', // Uses the recommended rules from @typescript-eslint/eslint-plugin + // This enables a lot of type checking + // 'plugin:@typescript-eslint/recommended-requiring-type-checking', // Uses the recommended rules from @typescript-eslint/eslint-plugin + ], + files: ['**/*.{ts,tsx}'], + parserOptions: { + tsconfigRootDir: __dirname, + project: ['./tsconfig.json'], + }, + rules: { + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/no-unused-vars': 'warn', + '@typescript-eslint/no-explicit-any': 'warn', + '@typescript-eslint/prefer-optional-chain': 'warn', + '@typescript-eslint/prefer-as-const': 'error', + '@typescript-eslint/await-thenable': 'error', + '@typescript-eslint/no-var-requires': 'off', + }, + }, + ], + plugins: ['@typescript-eslint', 'react', 'react-hooks'], + parser: '@typescript-eslint/parser', // Specifies the ESLint parser parserOptions: { ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features sourceType: 'module', // Allows for the use of imports @@ -18,21 +41,17 @@ module.exports = { }, rules: { // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs - '@typescript-eslint/explicit-function-return-type': 'off', // Note: you must disable the base rule as it can report incorrect errors 'no-unused-vars': 'off', - '@typescript-eslint/no-unused-vars': 'warn', - 'no-case-declarations': 'warn', camelcase: 'warn', 'react/prop-types': 'warn', 'no-console': 'off', - '@typescript-eslint/no-explicit-any': 'warn', - '@typescript-eslint/prefer-optional-chain': 'warn', 'no-param-reassign': 'warn', 'spaced-comment': ['error', 'always', { block: { exceptions: ['*'] } }], 'react/self-closing-comp': 'warn', }, + root: true, settings: { react: { version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use diff --git a/src/components/Charts/Bar.tsx b/src/components/Charts/Bar.tsx index cff62d808..498d72b12 100644 --- a/src/components/Charts/Bar.tsx +++ b/src/components/Charts/Bar.tsx @@ -189,7 +189,7 @@ const Bar = ({ className="barContainer" > <rect - onClick={!weekdays ? handleClick : () => {}} + onClick={!weekdays ? handleClick : () => undefined} x="0" y="0" width={showCompare ? getBandWidth() * 2 : getBandWidth()} @@ -252,7 +252,7 @@ const Bar = ({ : 'url(#diagonalHatch)' } // className={isDuel ? 'bar-duel' : barClass} - onClick={!weekdays ? handleClick : () => {}} + onClick={!weekdays ? handleClick : () => undefined} onAnimationEnd={onAnimationEnd} /> </g> @@ -283,7 +283,7 @@ const Bar = ({ )} fill="url(#gradient)" className={isDuel ? 'bar-duel' : barClass} - onClick={!weekdays ? handleClick : () => {}} + onClick={!weekdays ? handleClick : () => undefined} onAnimationEnd={onAnimationEnd} /> </g> diff --git a/src/components/Connection/ConnectionResult.tsx b/src/components/Connection/ConnectionResult.tsx index 9d24e0a09..31201f2f7 100644 --- a/src/components/Connection/ConnectionResult.tsx +++ b/src/components/Connection/ConnectionResult.tsx @@ -31,7 +31,7 @@ import './connectionResult.scss' interface ConnectionResultProps { fluidStatus: FluidStatus - handleAccountDeletion: Function + handleAccountDeletion: () => Promise<void> fluidType: FluidType } diff --git a/src/components/Connection/FormOAuth.tsx b/src/components/Connection/FormOAuth.tsx index a732fd960..af38519e3 100644 --- a/src/components/Connection/FormOAuth.tsx +++ b/src/components/Connection/FormOAuth.tsx @@ -12,7 +12,7 @@ import { setShouldRefreshConsent } from 'store/global/global.actions' interface FormOAuthProps { konnector: Konnector | null - onSuccess: Function + onSuccess: (accountId: string) => Promise<void> fluidStatus: FluidStatus } diff --git a/src/components/Connection/GRDFConnect/GrdfInit.tsx b/src/components/Connection/GRDFConnect/GrdfInit.tsx index 3e580a9f4..4200ad870 100644 --- a/src/components/Connection/GRDFConnect/GrdfInit.tsx +++ b/src/components/Connection/GRDFConnect/GrdfInit.tsx @@ -15,7 +15,7 @@ import GrdfForm from './GrdfForm' interface GrdfInitProps { fluidStatus: FluidStatus - onSuccess: Function + onSuccess: () => Promise<void> } const GrdfInit: React.FC<GrdfInitProps> = ({ diff --git a/src/components/Ecogesture/EcogestureView.tsx b/src/components/Ecogesture/EcogestureView.tsx index 626ddc463..7b5342b7d 100644 --- a/src/components/Ecogesture/EcogestureView.tsx +++ b/src/components/Ecogesture/EcogestureView.tsx @@ -110,8 +110,9 @@ const EcogestureView: React.FC = () => { }, []) const handleChange = useCallback( - (event: React.ChangeEvent<{}>, newValue: any) => { + (event: React.ChangeEvent<object>, newValue: number) => { event.preventDefault() + console.log(event) const params = new URLSearchParams() params.append('tab', newValue.toString()) navigate({ search: params.toString() }) diff --git a/src/components/EcogestureForm/EcogestureFormEquipment.tsx b/src/components/EcogestureForm/EcogestureFormEquipment.tsx index 83a2009ca..323d4969e 100644 --- a/src/components/EcogestureForm/EcogestureFormEquipment.tsx +++ b/src/components/EcogestureForm/EcogestureFormEquipment.tsx @@ -14,13 +14,13 @@ import { newProfileEcogestureEntry, updateProfileEcogesture, } from 'store/profileEcogesture/profileEcogesture.actions' -import './ecogestureFormEquipment.scss' import EquipmentIcon from './EquipmentIcon' +import './ecogestureFormEquipment.scss' interface EcogestureFormEquipmentProps { profileEcogesture: ProfileEcogesture - setPreviousStep: Function - setNextStep?: Function + setPreviousStep: (_profileEcogesture: ProfileEcogesture) => void + setNextStep?: (_profileEcogesture: ProfileEcogesture) => void step: ProfileTypeStepForm | EcogestureStepForm } diff --git a/src/components/EcogestureForm/EcogestureFormSingleChoice.tsx b/src/components/EcogestureForm/EcogestureFormSingleChoice.tsx index dbf9b2fe1..be00ef2af 100644 --- a/src/components/EcogestureForm/EcogestureFormSingleChoice.tsx +++ b/src/components/EcogestureForm/EcogestureFormSingleChoice.tsx @@ -17,8 +17,8 @@ interface EcogestureFormSingleChoiceProps { viewedStep: EcogestureStepForm profileEcogesture: ProfileEcogesture answerType: ProfileEcogestureAnswer - setNextStep: Function - setPreviousStep: Function + setNextStep: (_profileEcogesture: ProfileEcogesture) => void + setPreviousStep: (_profileEcogesture: ProfileEcogesture) => void } const EcogestureFormSingleChoice: React.FC<EcogestureFormSingleChoiceProps> = ({ diff --git a/src/components/Export/exportDoneModal.spec.tsx b/src/components/Export/exportDoneModal.spec.tsx index ea6d5625d..b8d12e0a2 100644 --- a/src/components/Export/exportDoneModal.spec.tsx +++ b/src/components/Export/exportDoneModal.spec.tsx @@ -37,7 +37,7 @@ describe('exportDoneModal component', () => { expect(toJson(wrapper)).toMatchSnapshot() }) - it('should display error message', () => {}) + it('should display error message', () => undefined) it('should close modal ', () => { const wrapper = mount( diff --git a/src/components/FormGlobal/FormNavigation.tsx b/src/components/FormGlobal/FormNavigation.tsx index dc4fd447d..00bdd37a0 100644 --- a/src/components/FormGlobal/FormNavigation.tsx +++ b/src/components/FormGlobal/FormNavigation.tsx @@ -10,8 +10,8 @@ import { useNavigate } from 'react-router-dom' interface FormNavigationProps { step: ProfileTypeStepForm | EcogestureStepForm | SgeStep - handlePrevious: Function - handleNext: Function + handlePrevious: () => void + handleNext: () => void disableNextButton: boolean disablePrevButton?: boolean isEcogesture?: boolean diff --git a/src/components/Header/CozyBar.tsx b/src/components/Header/CozyBar.tsx index a05b4b974..add88e786 100644 --- a/src/components/Header/CozyBar.tsx +++ b/src/components/Header/CozyBar.tsx @@ -11,9 +11,9 @@ import { openFeedbackModal } from 'store/modal/modal.slice' declare const cozy: { bar: { - BarLeft: Function - BarCenter: Function - BarRight: Function + BarLeft: React.FC + BarCenter: React.FC + BarRight: React.FC } } diff --git a/src/components/ProfileType/ProfileTypeFormDateSelection.tsx b/src/components/ProfileType/ProfileTypeFormDateSelection.tsx index fecc5e5d6..025d29932 100644 --- a/src/components/ProfileType/ProfileTypeFormDateSelection.tsx +++ b/src/components/ProfileType/ProfileTypeFormDateSelection.tsx @@ -17,8 +17,8 @@ interface ProfileTypeFormDateSelectionProps { viewedStep: ProfileTypeStepForm profileType: ProfileType answerType: ProfileTypeAnswer - setNextStep: Function - setPreviousStep: Function + setNextStep: (_profileType?: ProfileType) => void + setPreviousStep: (_profileType: ProfileType) => void isProfileTypeComplete: boolean } diff --git a/src/components/ProfileType/ProfileTypeFormMultiChoice.tsx b/src/components/ProfileType/ProfileTypeFormMultiChoice.tsx index ecfac832d..f1210185c 100644 --- a/src/components/ProfileType/ProfileTypeFormMultiChoice.tsx +++ b/src/components/ProfileType/ProfileTypeFormMultiChoice.tsx @@ -20,8 +20,8 @@ interface ProfileTypeFormMultiChoiceProps { viewedStep: ProfileTypeStepForm profileType: ProfileType answerType: ProfileTypeAnswer - setNextStep: Function - setPreviousStep: Function + setNextStep: (_profileType?: ProfileType) => void + setPreviousStep: (_profileType: ProfileType) => void isProfileTypeComplete: boolean } diff --git a/src/components/ProfileType/ProfileTypeFormNumber.tsx b/src/components/ProfileType/ProfileTypeFormNumber.tsx index 21ee84d9d..66e36f2bb 100644 --- a/src/components/ProfileType/ProfileTypeFormNumber.tsx +++ b/src/components/ProfileType/ProfileTypeFormNumber.tsx @@ -15,8 +15,8 @@ interface ProfileTypeFormNumberProps { viewedStep: ProfileTypeStepForm profileType: ProfileType answerType: ProfileTypeAnswer - setNextStep: Function - setPreviousStep: Function + setNextStep: (_profileType?: ProfileType) => void + setPreviousStep: (_profileType: ProfileType) => void isProfileTypeComplete: boolean } diff --git a/src/components/ProfileType/ProfileTypeFormNumberSelection.tsx b/src/components/ProfileType/ProfileTypeFormNumberSelection.tsx index 2e3dff0c8..6a5b5dfd0 100644 --- a/src/components/ProfileType/ProfileTypeFormNumberSelection.tsx +++ b/src/components/ProfileType/ProfileTypeFormNumberSelection.tsx @@ -15,8 +15,8 @@ interface ProfileTypeFormNumberSelectionProps { viewedStep: ProfileTypeStepForm profileType: ProfileType answerType: ProfileTypeAnswer - setNextStep: Function - setPreviousStep: Function + setNextStep: (_profileType?: ProfileType) => void + setPreviousStep: (_profileType: ProfileType) => void isProfileTypeComplete: boolean } diff --git a/src/components/ProfileType/ProfileTypeFormSingleChoice.tsx b/src/components/ProfileType/ProfileTypeFormSingleChoice.tsx index a436afe81..a4fc88272 100644 --- a/src/components/ProfileType/ProfileTypeFormSingleChoice.tsx +++ b/src/components/ProfileType/ProfileTypeFormSingleChoice.tsx @@ -16,8 +16,8 @@ interface ProfileTypeFormSingleChoiceProps { viewedStep: ProfileTypeStepForm profileType: ProfileType answerType: ProfileTypeAnswer - setNextStep: Function - setPreviousStep: Function + setNextStep: (_profileType?: ProfileType) => void + setPreviousStep: (_profileType: ProfileType) => void isProfileTypeComplete: boolean } diff --git a/src/migrations/migration.data.ts b/src/migrations/migration.data.ts index 1eb80f0c7..ada83c237 100644 --- a/src/migrations/migration.data.ts +++ b/src/migrations/migration.data.ts @@ -544,7 +544,7 @@ export const migrations: Migration[] = [ }, redirectLink: '/consumption/electricity', docTypes: '', - run: async (): Promise<any> => {}, + run: async (): Promise<any> => undefined, isEmpty: true, }, { diff --git a/src/targets/services/service.ts b/src/targets/services/service.ts index b9cad1f0e..006947691 100644 --- a/src/targets/services/service.ts +++ b/src/targets/services/service.ts @@ -10,7 +10,7 @@ const assertEnvVar = (varName: string) => { } } -export const runService = (service: Function) => { +export const runService = (service: ({ client }: any) => Promise<void>) => { assertEnvVar('COZY_URL') assertEnvVar('COZY_CREDENTIALS') -- GitLab