Skip to content

Commit

Permalink
Merge pull request #1050 from MTES-MCT/eslint
Browse files Browse the repository at this point in the history
chore: upgrade to ESLint v8 and fix linting issues
  • Loading branch information
loicguillois authored Dec 24, 2024
2 parents 205ad89 + bcff2cf commit 78653fa
Show file tree
Hide file tree
Showing 28 changed files with 288 additions and 192 deletions.
20 changes: 0 additions & 20 deletions .eslintignore

This file was deleted.

56 changes: 0 additions & 56 deletions .eslintrc.json

This file was deleted.

86 changes: 86 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import _import from "eslint-plugin-import";
import { fixupPluginRules, fixupConfigRules } from "@eslint/compat";
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
});

export default [{
ignores: [
"**/build/",
"**/dist/",
"frontend/src/components/_dsfr/",
"frontend/jest.polyfills.js",
"**/node_modules/",
"**/public/",
"**/tools/",
"**/README.md",
"**/bin",
"**/Procfile",
"**/jest.config.js",
"**/.eslintrc.json",
"**/package.json",
"**/package-lock.json",
"**/yarn.lock",
"**/cron.json",
"**/*.css",
"**/*.hbs",
"server/jest.config.ts",
"frontend/jest.config.ts",
],
}, ...compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"), {
plugins: {
"@typescript-eslint": typescriptEslint,
import: fixupPluginRules(_import),
},

languageOptions: {
globals: {
...globals.node,
},

parser: tsParser,
ecmaVersion: 2023,
sourceType: "module",
},

rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-var-requires": "off",
"import/no-commonjs": "error",
eqeqeq: ["error", "always"],
semi: ["error", "always"],
},
}, ...fixupConfigRules(compat.extends(
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
)).map(config => ({
...config,
files: ["frontend/src/**/*.ts?(x)"],
})), {
files: ["frontend/src/**/*.ts?(x)"],

settings: {
react: {
version: "detect",
},
},

rules: {
"no-irregular-whitespace": ["error", {
skipJSXText: true,
}],
},
}];
1 change: 1 addition & 0 deletions frontend/src/components/Auth/RequireAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Navigate, useLocation } from 'react-router-dom';
import { useUser } from '../../hooks/useUser';
import { useFetchInterceptor } from '../../hooks/useFetchInterceptor';

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface RequireAuthProps {}

function RequireAuth(props: PropsWithChildren<RequireAuthProps>) {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Auth/RequireGuest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PropsWithChildren } from 'react';
import { useUser } from '../../hooks/useUser';
import { Navigate } from 'react-router-dom';

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface RequireGuestProps {}

function RequireGuest(props: PropsWithChildren<RequireGuestProps>) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Draft/PreviewButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function PreviewButton(props: Readonly<Props>) {
setIsSuccess(true);
}
}
} catch (error) {
} catch {
setIsError(true);
} finally {
setIsLoading(false);
Expand Down
11 changes: 1 addition & 10 deletions frontend/src/components/Image/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@ import { fr } from '@codegouvfr/react-dsfr';
import styled from '@emotion/styled';
import classNames from 'classnames';

const responsiveValues = [
'1x1',
'2x3',
'3x2',
'3x4',
'4x3',
'16x9',
'32x9'
] as const;
type Responsive = (typeof responsiveValues)[number];
type Responsive = '1x1' | '2x3' | '3x2' | '3x4' | '4x3' | '16x9' | '32x9';

interface Props {
alt: string;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/_app/AppInfo/AppInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PropsWithChildren } from 'react';
import styles from './app-info.module.scss';
import { fr } from '@codegouvfr/react-dsfr';

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface Props {}

function AppInfo(props: PropsWithChildren<Props>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const FillLocalId = forwardRef((props: StepProps, ref) => {
]);
dispatch(changeCreator({ localId }));
return 'review-housing';
} catch (error) {
} catch {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ describe('Modal stepper', () => {
const steps: Step[] = [
{
title: 'Title 1',
Component: forwardRef(() => <p>Step 1</p>),
Component: forwardRef(function Step1() { return <p>Step 1</p>; }),
},
{
title: 'Title 2',
Component: forwardRef(() => <p>Step 2</p>),
Component: forwardRef(function Step2() { return <p>Step 2</p>; }),
},
];

Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/modals/ModalStepper/ModalStepper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ function ModalStepper(props: Props) {
onClick: async () => {
const next = (await ref.current?.onNext?.()) ?? true;
if (next) {
stepper.isOver() ? modal.close() : stepper.next();
if (stepper.isOver()) {
modal.close();
} else {
stepper.next();
}
}
},
},
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/hooks/useClipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ export function useClipboard(opts?: ClipboardOptions) {
const [copied, setCopied] = useState(false);

async function copy(data: ClipboardItems | string) {
typeof data === 'string'
? await navigator.clipboard.writeText(data)
: await navigator.clipboard.write(data);
if (typeof data === 'string') {
await navigator.clipboard.writeText(data);
} else {
await navigator.clipboard.write(data);
}

setCopied(true);
delay(() => setCopied(false), options.timeout);
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/hooks/useUnsavedChanges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ function useUnsavedChanges(props: Readonly<Props>) {

useEffect(() => {
if (blocker.state === 'blocked') {
window.confirm(message) ? blocker.proceed() : blocker.reset();
if (window.confirm(message)) {
blocker.proceed();
} else {
blocker.reset();
}
}
}, [blocker, message]);
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/models/Draft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { SenderPayload } from './Sender';
import { DeepNonNullable } from 'ts-essentials';

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface Draft extends DraftDTO {}

export interface DraftCreationPayload
Expand Down
1 change: 1 addition & 0 deletions frontend/src/models/GroupFilters.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface GroupFilters {}
1 change: 1 addition & 0 deletions frontend/src/models/HousingFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { LocalityKindLabels, LocalityKinds } from './Locality';
import EnergyConsumptionOption from '../components/_app/AppMultiSelect/EnergyConsumptionOption';
import { VacancyYear } from './VacancyYear';

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface HousingFilters extends HousingFiltersDTO {}

export const allOccupancyOptions: SelectOption<Occupancy>[] = [
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/views/Housing/test/HousingView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ describe('Housing view', () => {

const vacancyStartYear = await screen
.findByText(/^Dans cette situation depuis/)
// eslint-disable-next-line testing-library/no-node-access
.then((label) => label.nextElementSibling);
expect(vacancyStartYear).toHaveTextContent('Inconnu');
});
Expand All @@ -86,7 +85,6 @@ describe('Housing view', () => {

const vacancyStartYear = await screen
.findByText(/^Dans cette situation depuis/)
// eslint-disable-next-line testing-library/no-node-access
.then((label) => label.nextElementSibling);
expect(vacancyStartYear).toHaveTextContent('Moins d’un an');
});
Expand All @@ -100,7 +98,6 @@ describe('Housing view', () => {

const source = await screen
.findByText(/^Source/)
// eslint-disable-next-line testing-library/no-node-access
.then((label) => label.nextElementSibling);
expect(source).toHaveTextContent('Fichiers fonciers (2023)');
});
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
"author": "",
"license": "MIT",
"devDependencies": {
"@eslint/compat": "^1.2.4",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.17.0",
"@types/node": "^20.16.10",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.30.0",
Expand All @@ -36,6 +39,7 @@
"eslint-plugin-react": "^7.37.0",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-testing-library": "^6.3.0",
"globals": "^15.14.0",
"husky": "^9.1.6",
"is-ci": "^3.0.1",
"jest": "^29.7.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/draft/src/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function createTransformer(opts: TransformerOptions) {
const binaryString = atob(content);
const len = binaryString.length;
const bytes = new Uint8Array(len);

for (let i = 0; i < len; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/controllers/fileRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function download(logo: string): Promise<FileUploadDTO> {
url: logo,
type: response.ContentType ?? 'base64'
};
} catch (error) {
} catch {
throw new FileMissingError();
}
}
Loading

0 comments on commit 78653fa

Please sign in to comment.