Skip to content

Commit

Permalink
Oppgraderer til eslint 9 (#6428)
Browse files Browse the repository at this point in the history
* Oppgraderer til eslint 9.

Disse pakker/plugins blir fjerna som ein del av dette, fordi dei ikkje er kompatible med versjon 9, eller ikkje ser ut til å ha nytteverdi for oss:

@typescript-eslint/eslint-plugin, @typescript-eslint/parser: Erstatta med typescript-eslint plugin.

eslint-config-airbnb: Siste oppdatering var tre år sidan, og blir ikkje oppdatert med det første.

eslint-plugin-import, eslint-import-resolver-typescript: Støtter ikkje versjon 9, og uvisst kor nyttig denne er for oss. Trur andre delar av build gjere nok sjekk på imports.

eslint-plugin-jest-dom: Denne ser ikkje ut til å ha vore aktivert i gammal konfigurasjon. Fekk masse feil når den vart aktivert med recommended innstillinger, og fekk ikkje framprovosert feil i gammal konfigurasjon.

eslint-plugin-storybook: Ikkje oppdatert til versjon 9, og ser ikkje ut til å ha vore aktivert i gammal konfigurasjon. Klarte ikkje framprovosere feil der ut frå anbefalt sjekk.

Endre også tsconfig.json innstilling til react-jsx. Med dette slepp ein å importere React i alle filer som bruker jsx. Og unngår dermed eslint feil om unused-var frå importen av React.

Den nye eslint.config.mjs prøver å forenkle i forhold til gammal konfigurasjon, den aktiverer i utgangspunktet recommended settings frå grunnkonfigurasjon og alle plugins, og så tilpasser den litt der det trengs for å unngå for mykje feil i eksisterande kodebase.

Kan så skru denne meir strict etterkvart viss vi ser mulighet for det, feks for filer under packages/v2.

* Diverse minimale endringer for kompatibilitet med eslint 9.

Kun endringer i kommentarer og typescript/postcss konfigurasjon. Ingen endring i runtime javascript.

* yarn.lock oppdatert etter fjerning av dayjs.
  • Loading branch information
josstn authored Aug 7, 2024
1 parent c7a7cab commit fe67981
Show file tree
Hide file tree
Showing 129 changed files with 440 additions and 1,014 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

1 change: 0 additions & 1 deletion .eslintrc.cjs

This file was deleted.

74 changes: 74 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// @ts-check

import eslint from '@eslint/js';
import configPrettier from 'eslint-config-prettier';
import globals from "globals";
import tseslint from 'typescript-eslint';
import pluginReact from 'eslint-plugin-react'
import pluginJsxA11y from 'eslint-plugin-jsx-a11y';
import pluginVitest from 'eslint-plugin-vitest';
// Viss vi ønsker eslint-plugin-jest-dom aktivert: import pluginJestDom from 'eslint-plugin-jest-dom';
// ^- Rapporterer ein del feil, så virker ikkje å ha vore aktivert før.


const OFF = 0;
const WARN = 1;
const ERROR = 2;

const config = tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
configPrettier,
pluginReact.configs.flat['jsx-runtime'],
pluginJsxA11y.flatConfigs.recommended,
pluginVitest.configs.recommended,
// Viss vi ønsker jest-dom plugin aktivert: pluginJestDom.configs["flat/recommended"],
{
languageOptions: {
globals: {
...globals.browser,
},
},
linterOptions: {
// Vurder å enable denne seinare
reportUnusedDisableDirectives: false
},
rules: {
'@typescript-eslint/no-explicit-any': OFF,
'@typescript-eslint/no-unused-vars': [
"error",
{
varsIgnorePattern: "React" // TODO Fjern denne og samtidig alle ubrukte React imports. Unødvendig etter overgang til react-jsx i tsconfig
}
],
'jsx-a11y/no-autofocus': OFF, // Skrudd av ved migrering til jsx-a11y recommended config. Vurder å fikse seinare.
'jsx-a11y/anchor-is-valid': OFF,
}
},
{
files: ["**/*.cjs"],
rules: {
'@typescript-eslint/no-var-requires': OFF,
},
languageOptions: {
globals: {
require: true,
module: true,
}
}
},
{
files: ["packages/v2/**.*.ts", "packages/v2/**.*.tsx"],
rules: {
'@typescript-eslint/no-explicit-any': ERROR
}
},
{
files: ["**/KroniskSykObjektTilMikrofrontend.ts"],
rules: {
'no-constant-binary-expression': OFF // TODO Fiks denne, sannsynlegvis bug
}
}
)

export default config
138 changes: 0 additions & 138 deletions eslint/eslintrc.common.cjs

This file was deleted.

21 changes: 0 additions & 21 deletions eslint/eslintrc.dev.cjs

This file was deleted.

19 changes: 0 additions & 19 deletions eslint/eslintrc.prod.cjs

This file was deleted.

15 changes: 5 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test:coverage": "vitest --coverage --selectProjects test",
"test-storybook": "test-storybook --url http://127.0.0.1:9001 --testTimeout=30_000",
"ts-check": "tsc --pretty && tsc --pretty --project packages/v2/tsconfig.json",
"lint": "eslint --cache packages --ext .ts,.tsx,.js,.jsx",
"lint": "eslint --cache packages",
"lint:fix": "eslint --fix --cache packages --ext .ts,.tsx,.js,.jsx",
"css:lint": "stylelint \"packages/**/*.css\"",
"css:modules:typegen": "tcm ./packages/v2/gui --camelCase dashes --allowArbitraryExtensions ",
Expand Down Expand Up @@ -89,22 +89,16 @@
"@types/react-collapse": "5.0.4",
"@types/react-router-dom": "5.3.3",
"@types/redux-form": "8.3.11",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@vitejs/plugin-react": "^4.3.1",
"autoprefixer": "^10.4.20",
"axios-mock-adapter": "1.22.0",
"cross-env": "7.0.3",
"eslint": "8.57.0",
"eslint-config-airbnb": "19.0.4",
"eslint": "9.7.0",
"eslint-config-prettier": "9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jest-dom": "5.4.0",
"eslint-plugin-jsx-a11y": "6.9.0",
"eslint-plugin-react": "7.35.0",
"eslint-plugin-storybook": "0.8.0",
"eslint-plugin-vitest": "~0.4.1",
"eslint-plugin-vitest": "~0.5.4",
"globals": "^15.8.0",
"husky": "9.1.4",
"jsdom": "24.1.1",
"lint-staged": "15.2.8",
Expand All @@ -120,6 +114,7 @@
"tailwindcss": "^3.4.7",
"typed-css-modules": "^0.9.1",
"typescript": "5.5.4",
"typescript-eslint": "^7.17.0",
"vite": "^5.3.5",
"vite-plugin-html": "^3.2.2",
"vitest": "2.0.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable vitest/no-commented-out-tests */
import React from 'react';

import aksjonspunktCodes from '@fpsak-frontend/kodeverk/src/aksjonspunktCodes';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-relative-packages */
import aksjonspunktCodes from '@fpsak-frontend/kodeverk/src/aksjonspunktCodes';
import aksjonspunktStatus from '@fpsak-frontend/kodeverk/src/aksjonspunktStatus';
import { action } from '@storybook/addon-actions';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ LeggTilArbeidsforholdFelter.validate = (
const { fomDato, tomDato } = values;
if (fomDato && tomDato && moment(fomDato).isAfter(moment(tomDato))) {
return {
// @ts-ignore
// @ts-expect-error Migrert frå ts-ignore, uvisst kvifor denne trengs
tomDato: sluttdatoErrorMsg(formatDate(fomDato)),
// @ts-ignore
// @ts-expect-error Migrert frå ts-ignore, uvisst kvifor denne trengs
fomDato: startdatoErrorMsg(formatDate(tomDato)),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
component: FaktaRammevedtakIndex,
};

// @ts-ignore
// @ts-expect-error Migrert frå ts-ignore
const behandling: Behandling = {
id: 1,
versjon: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const mapStateToPropsFactory = (_initialState, initialOwnProps: Overføringsrade
};

export default connect(mapStateToPropsFactory)(
// @ts-ignore
// @ts-expect-error Migrert frå ts-ignore, uvisst kvifor denne trengs
behandlingForm({
enableReinitialize: true,
})(OverføringsraderFormImpl),
Expand Down
1 change: 0 additions & 1 deletion packages/fakta-etablert-tilsyn/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
// eslint-disable-next-line import/prefer-default-export
export { default as EtablertTilsyn } from './src/ui/MainComponent';
1 change: 0 additions & 1 deletion packages/fakta-etablert-tilsyn/mock/api-mock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/prefer-default-export */
import { http, HttpResponse } from 'msw';
import { mockUrlPrepend } from './constants';
import mockedSykdom from './mocked-data/mockedSykdom';
Expand Down
2 changes: 0 additions & 2 deletions packages/fakta-etablert-tilsyn/src/mock/browser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/prefer-default-export */
/* eslint-disable import/no-extraneous-dependencies */
import { setupWorker } from 'msw/browser';
import { handlers } from '../../mock/api-mock';

Expand Down
1 change: 0 additions & 1 deletion packages/fakta-etablert-tilsyn/src/util/formats.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/prefer-default-export */
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';

Expand Down
1 change: 0 additions & 1 deletion packages/fakta-etablert-tilsyn/src/util/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/prefer-default-export */
import { useEffect, useRef } from 'react';

export const usePrevious = value => {
Expand Down
2 changes: 0 additions & 2 deletions packages/fakta-etablert-tilsyn/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig } from 'vite';
// eslint-disable-next-line import/no-extraneous-dependencies
import react from '@vitejs/plugin-react';
import { nodePolyfills } from 'vite-plugin-node-polyfills';

Expand Down
1 change: 0 additions & 1 deletion packages/fakta-felles/src/components/FaktaSubmitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ const mapStateToProps = (state: any, ownProps: PureOwnProps): MappedOwnProps =>
hasEmptyRequiredFields: ownProps.doNotCheckForRequiredFields
? false
: formNames.some(formName =>
// @ts-ignore Fiks denne (reselect)
hasBehandlingFormErrorsOfType(formName, behandlingId, behandlingVersjon, isRequiredMessage())(state),
),
};
Expand Down
1 change: 0 additions & 1 deletion packages/fakta-inntektsmelding/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
// eslint-disable-next-line import/prefer-default-export
export { default as Inntektsmelding } from './src/ui/MainComponent';
1 change: 0 additions & 1 deletion packages/fakta-inntektsmelding/mock/api-mock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/prefer-default-export */
import { http, HttpResponse } from 'msw';
import mockedKompletthetsdata from './mockedKompletthetsdata';

Expand Down
2 changes: 0 additions & 2 deletions packages/fakta-inntektsmelding/src/mock/browser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/prefer-default-export */
/* eslint-disable import/no-extraneous-dependencies */
import { setupWorker } from 'msw/browser';
import { handlers } from '../../mock/api-mock';

Expand Down
Loading

0 comments on commit fe67981

Please sign in to comment.