Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oppsett for eslint 9 #1547

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions .eslintrc

This file was deleted.

4 changes: 0 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ updates:
- dependency-name: "*"
update-types: [ "version-update:semver-patch" ]
groups:
typescript-eslint:
patterns:
- "@typescript-eslint/eslint-plugin"
- "@typescript-eslint/parser"
react:
patterns:
- "react"
Expand Down
33 changes: 33 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import reactHooks from 'eslint-plugin-react-hooks';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import react from 'eslint-plugin-react';
import jsxA11y from 'eslint-plugin-jsx-a11y';


export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
react.configs.flat.recommended,
jsxA11y.flatConfigs.recommended,
eslintPluginPrettierRecommended,
{
languageOptions: {
parserOptions: { ecmaFeatures: { jsx: true } },
},
},
{
plugins: { 'react-hooks': reactHooks },
rules: {
...reactHooks.configs.recommended.rules,
'react/no-unescaped-entities': 'off',
'@typescript-eslint/no-unused-expressions': 'off'
},
settings: {
react: {
version: "detect",
},
},
},
);
17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"storybook": "storybook dev -p 8000",
"build-storybook": "storybook build",
"deploy-storybook": "storybook-to-ghpages",
"lint": "eslint './packages/**/*.{ts,tsx}'",
"lint:fix": "eslint './packages/**/*.{ts,tsx}' --fix",
"lint": "eslint './packages/**/*.{ts,tsx}' --ignore-pattern '**/dist/*'",
"lint:fix": "eslint './packages/**/*.{ts,tsx}' --ignore-pattern '**/dist/*' --fix",
"publish:ci": "lerna publish --yes",
"publish:canary": "lerna publish --canary",
"publish:canary:ci": "lerna publish --canary --yes"
Expand Down Expand Up @@ -47,22 +47,18 @@
"@storybook/react-webpack5": "^8.1.10",
"@storybook/storybook-deployer": "^2.8.16",
"@types/node": "^20.14.8",
"@typescript-eslint/eslint-plugin": "^7.16.0",
"@typescript-eslint/parser": "^7.16.0",
"babel-loader": "^9.1.3",
"classnames": "^2.5.1",
"commitizen": "^4.3.0",
"copyfiles": "^2.4.1",
"css-loader": "^7.1.2",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.57.0",
"eslint-config-airbnb": "^19.0.4",
"eslint": "^9.8.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsx-a11y": "^6.9.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.34.3",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "^5.1.0-rc-06d0b89e-20240801",
"lerna": "^8.1.3",
"less": "^4.2.0",
"less-loader": "^12.2.0",
Expand All @@ -77,6 +73,7 @@
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "^5.5.2",
"typescript-eslint": "^8.0.1",
"webpack": "^5.93.0"
},
"workspaces": [
Expand Down
1 change: 1 addition & 0 deletions packages/familie-backend/src/auth/azure/azure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const hentClient = (): Promise<Client> => {
};

const strategy = (client: Client) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const verify = (tokenSet: TokenSet, done: (err: any, _: any) => void) => {
logDebug(`verify. expired=${tokenSet.expired()}`);
if (tokenSet.expired()) {
Expand Down
3 changes: 3 additions & 0 deletions packages/familie-backend/src/auth/azure/passport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ import { Client, UserinfoResponse } from 'openid-client';
import { logInfo } from '@navikt/familie-logging';
import azure from './azure';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default async (passport: any): Promise<Client> => {
logInfo('Konfigurerer passport');
const azureAuthClient: Client = await azure.hentClient();
const azureOidcStrategy = azure.strategy(azureAuthClient);

passport.serializeUser(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(user: UserinfoResponse, done: (err: any, user?: UserinfoResponse) => void) =>
done(undefined, user),
);
passport.deserializeUser(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(user: UserinfoResponse, done: (err: any, user?: UserinfoResponse) => void) =>
done(undefined, user),
);
Expand Down
2 changes: 2 additions & 0 deletions packages/familie-backend/src/auth/bruker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const setBrukerprofilPåSesjonRute = (authClient: Client) => {
};

const setBrukerprofilPåSesjon = (authClient: Client, req: Request, next: NextFunction) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
return new Promise((_, _reject) => {
const api = {
clientId: 'https://graph.microsoft.com',
Expand All @@ -71,6 +72,7 @@ const setBrukerprofilPåSesjon = (authClient: Client, req: Request, next: NextFu
getOnBehalfOfAccessToken(authClient, req, api)
.then(accessToken => hentBrukerData(accessToken, req))
.then(res => res.json())
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.then((data: any) => {
if (!req.session) {
throw new Error('Mangler sesjon på kall');
Expand Down
15 changes: 8 additions & 7 deletions packages/familie-backend/src/auth/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { logError, logInfo, logSecure } from '@navikt/familie-logging';
import { ISessionKonfigurasjon } from '../typer';

import RedisStore from 'connect-redis';
import {hentErforbindelsenTilRedisTilgjengelig, settErforbindelsenTilRedisTilgjengelig} from "../utils";


import {
hentErforbindelsenTilRedisTilgjengelig,
settErforbindelsenTilRedisTilgjengelig,
} from '../utils';

const redisClientForAiven = (sessionKonfigurasjon: ISessionKonfigurasjon) => {
const pingHvertFjerdeMinutt = 1000 * 60 * 4; // Connection blir ugyldig etter fem minutter, pinger derfor hvert fjerde minutt
Expand All @@ -20,14 +21,14 @@ const redisClientForAiven = (sessionKonfigurasjon: ISessionKonfigurasjon) => {
username: sessionKonfigurasjon.redisBrukernavn,
password: sessionKonfigurasjon.redisPassord,
socket: {
reconnectStrategy : (attempts) => {
reconnectStrategy: attempts => {
if (attempts >= 100 && hentErforbindelsenTilRedisTilgjengelig()) {
settErforbindelsenTilRedisTilgjengelig(false);
}

// Reconnect after
return Math.min(attempts * 100, 1000);
}
},
},
pingInterval: pingHvertFjerdeMinutt,
});
Expand Down Expand Up @@ -75,8 +76,8 @@ export default (
/**
* Logge hendelser i redisclient for å debugge merkelige sockettimeouts
*/
redisClient.on('error', (err) => {
logError(`Redis Error: ${err}`)
redisClient.on('error', err => {
logError(`Redis Error: ${err}`);
settErforbindelsenTilRedisTilgjengelig(false);
});
redisClient.on('connect', () => logInfo('Redis connected'));
Expand Down
5 changes: 2 additions & 3 deletions packages/familie-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import konfigurerRouter from './router';
import { ISessionKonfigurasjon } from './typer';
import { Client } from 'openid-client';
import { logError } from '@navikt/familie-logging';
import {hentErforbindelsenTilRedisTilgjengelig} from "./utils";
import { hentErforbindelsenTilRedisTilgjengelig } from './utils';

export * from './auth/authenticate';
export * from './auth/tokenUtils';
Expand All @@ -36,8 +36,7 @@ export default async (

headers.setup(app);

app.get('/isAlive', (_req: Request, res: Response) => {

app.get('/isAlive', (_req: Request, res: Response) => {
if (hentErforbindelsenTilRedisTilgjengelig()) {
res.status(200).end();
} else {
Expand Down
1 change: 1 addition & 0 deletions packages/familie-backend/src/typer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface User {
enhet: string;
identifier: string;
navIdent: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
groups: any;
}

Expand Down
10 changes: 4 additions & 6 deletions packages/familie-backend/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { Request } from 'express';
import { LOG_LEVEL, logDebug, logError, logInfo, logWarn } from '@navikt/familie-logging';


let erForbindelsenTilRedisTilgjengelig = true;

export const settErforbindelsenTilRedisTilgjengelig = (verdi: boolean) => {
erForbindelsenTilRedisTilgjengelig = verdi;
}
erForbindelsenTilRedisTilgjengelig = verdi;
};

export const hentErforbindelsenTilRedisTilgjengelig = ():boolean => {
export const hentErforbindelsenTilRedisTilgjengelig = (): boolean => {
return erForbindelsenTilRedisTilgjengelig;
}

};

export const envVar = (navn: string, påkrevd = true, defaultValue?: string): string => {
const envVariable = process.env[navn];
Expand Down
4 changes: 4 additions & 0 deletions packages/familie-endringslogg/src/endringslogg-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const EndringsloggContainer = (props: EndringsloggContainerProps) => {
setEndringsloggApen(setOpenTo);
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handleClickOutside = (event: any) => {
if (
loggNode.current?.contains(event.target) ||
Expand All @@ -51,6 +52,7 @@ export const EndringsloggContainer = (props: EndringsloggContainerProps) => {
}
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const escHandler = (event: any) => {
if (event.keyCode === 27 && endringsloggApen) {
requestSetOpenStatus(false);
Expand All @@ -60,6 +62,7 @@ export const EndringsloggContainer = (props: EndringsloggContainerProps) => {
}
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const click = (event: any) => {
event.stopPropagation();
requestSetOpenStatus(!endringsloggApen);
Expand Down Expand Up @@ -98,6 +101,7 @@ interface EndringsloggIconButtonProps {
buttonRef: RefObject<HTMLButtonElement>;
open: boolean;
newNotifications: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onClick: (e?: any) => void;
name: string;
stil?: StilType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect } from 'react';

export const useEventListener = (eventName: string, handleEvent: (event?: any) => void) => {
export const useEventListener = (eventName: string, handleEvent: (event?: unknown) => void) => {
useEffect(() => {
document.addEventListener(eventName, handleEvent, false);
return () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/familie-endringslogg/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const Endringslogg: React.FC<EndringsloggProps> = (props: EndringsloggPro
).then(response =>
response
.json()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.then((jsonResponse: any) => {
const entries = mapRemoteToState(jsonResponse);
setEndringsloggEntries(entries);
Expand All @@ -72,6 +73,7 @@ export const Endringslogg: React.FC<EndringsloggProps> = (props: EndringsloggPro
);
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props, loadData, endringsloggEntries]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const TourModal = (props: TourModalProps) => {
});
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [stepIndex]);

const lukkModal = () => {
Expand Down
8 changes: 6 additions & 2 deletions packages/familie-endringslogg/src/transition-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ interface TransitionProps extends CollapseContainerProps {
* Overrider props ettersom transition-group ikke er oppgradert til React 18.
* Disse to linjene kan fjernes når dette skjer
*/
const TransitionGroupWithChildren = TransitionGroup as unknown as React.FC<PropsWithChildren<TransitionGroupProps>>
const CSSTransitionWithChildren = CSSTransition as unknown as React.FC<PropsWithChildren<CSSTransitionProps>>
const TransitionGroupWithChildren = TransitionGroup as unknown as React.FC<
PropsWithChildren<TransitionGroupProps>
>;
const CSSTransitionWithChildren = CSSTransition as unknown as React.FC<
PropsWithChildren<CSSTransitionProps>
>;

const TransitionContainer = (props: TransitionProps) => (
<TransitionGroupWithChildren component={null}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type BlockContentType = any;
export type ModalType = {
header?: string;
Expand Down Expand Up @@ -36,6 +37,7 @@ export const setAllEntriesSeen = (endringsloggEntries: EndringsloggEntryWithSeen
return { ...el, seen: true };
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const mapRemoteToState = (remotestorage: any[]): EndringsloggEntryWithSeenStatus[] =>
remotestorage
.map(endring => {
Expand Down
3 changes: 2 additions & 1 deletion packages/familie-endringslogg/src/utils/frontend-logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const logEvent = (logTag: string, fields?: {}, tags?: {}): void => {
export const logEvent = (logTag: string, fields?: object, tags?: object): void => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const frontendlogger = (window as any).frontendlogger;

if (process.env.REACT_APP_MOCK) {
Expand Down
Loading