Update ESLint dependencies to latest version (#31831)

Signed-off-by: Jon Koops <jonkoops@gmail.com>
This commit is contained in:
Jon Koops 2024-08-06 14:02:18 +02:00 committed by GitHub
parent 6847af0068
commit 38f185dff1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
42 changed files with 899 additions and 536 deletions

View file

@ -1,9 +1,11 @@
// @ts-check
import { fixupPluginRules } from "@eslint/compat";
import { FlatCompat } from "@eslint/eslintrc";
import eslint from "@eslint/js";
import mochaPlugin from "eslint-plugin-mocha";
import playwright from "eslint-plugin-playwright";
import prettierRecommended from "eslint-plugin-prettier/recommended";
import reactHooks from "eslint-plugin-react-hooks";
import reactJsxRuntime from "eslint-plugin-react/configs/jsx-runtime.js";
import reactRecommended from "eslint-plugin-react/configs/recommended.js";
import tseslint from "typescript-eslint";
@ -28,10 +30,12 @@ export default tseslint.config(
...tseslint.configs.stylisticTypeChecked,
reactRecommended,
reactJsxRuntime,
...compat.extends("plugin:react-hooks/recommended"),
prettierRecommended,
...compat.plugins("lodash"),
{
plugins: {
"react-hooks": fixupPluginRules(reactHooks),
},
languageOptions: {
parserOptions: {
project: "./tsconfig.eslint.json",
@ -44,6 +48,7 @@ export default tseslint.config(
},
},
rules: {
...reactHooks.configs.recommended.rules,
// ## Rules overwriting config, disabled for now, but will have to be evaluated. ##
"no-undef": "off",
"no-unused-private-class-members": "off",
@ -72,6 +77,7 @@ export default tseslint.config(
"@typescript-eslint/no-unnecessary-condition": "off",
"@typescript-eslint/no-unnecessary-type-arguments": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/no-unnecessary-type-parameters": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
@ -154,4 +160,16 @@ export default tseslint.config(
...playwright.configs["flat/recommended"],
files: ["js/apps/account-ui/test/**"],
},
{
files: ["js/libs/keycloak-admin-client/test/**"],
rules: {
"@typescript-eslint/no-unused-expressions": "off",
},
},
{
files: ["js/libs/keycloak-admin-client/src/**"],
rules: {
"@typescript-eslint/no-empty-object-type": "off",
},
},
);

View file

@ -27,13 +27,7 @@ export const fetchResources = async (
{ searchParams: shared ? requestParams : undefined, signal },
);
let links: Links;
try {
links = parseLinks(response);
} catch (error) {
links = {};
}
const links = parseLinks(response);
return {
data: checkResponse(await response.json()),

View file

@ -7,15 +7,15 @@ export function parseLinks(response: Response): Links {
const linkHeader = response.headers.get("link");
if (!linkHeader) {
throw new Error("Attempted to parse links, but no header was found.");
return {};
}
const links = linkHeader.split(/,\s*</);
return links.reduce<Links>((acc: Links, link: string) => {
const matcher = link.match(/<?([^>]*)>(.*)/);
const matcher = /<?([^>]*)>(.*)/.exec(link);
if (!matcher) return {};
const linkUrl = matcher[1];
const rel = matcher[2].match(/\s*(.+)\s*=\s*"?([^"]+)"?/);
const rel = /\s*(.+)\s*=\s*"?([^"]+)"?/.exec(matcher[2]);
if (rel) {
const link: Record<string, string> = {};
for (const [key, value] of new URL(linkUrl).searchParams.entries()) {

View file

@ -66,7 +66,7 @@ export const token = (keycloak: Keycloak) =>
async function getAccessToken() {
try {
await keycloak.updateToken(5);
} catch (error) {
} catch {
await keycloak.login();
}

View file

@ -475,7 +475,7 @@ describe.skip("Events tests", () => {
});
it("Check a11y violations on admin events tab", () => {
eventsPage.goToAdminEventsTab;
eventsPage.goToAdminEventsTab();
cy.checkA11y();
});

View file

@ -42,14 +42,23 @@ export default class AdminEventsSettingsTab extends PageObject {
waitForConfig: false,
},
) {
waitForRealm && cy.intercept("/admin/realms/*").as("saveRealm");
waitForConfig &&
if (waitForRealm) {
cy.intercept("/admin/realms/*").as("saveRealm");
}
if (waitForConfig) {
cy.intercept("/admin/realms/*/events/config").as("saveConfig");
}
cy.get(this.#saveBtn).click();
waitForRealm && cy.wait("@saveRealm");
waitForConfig && cy.wait("@saveConfig");
if (waitForRealm) {
cy.wait("@saveRealm");
}
if (waitForConfig) {
cy.wait("@saveConfig");
}
return this;
}

View file

@ -30,7 +30,7 @@ export async function initAdminClient(
async getAccessToken() {
try {
await keycloak.updateToken(5);
} catch (error) {
} catch {
keycloak.login();
}

View file

@ -56,9 +56,9 @@ export const AddMapperDialog = (props: AddMapperDialogProps) => {
const allRows = useMemo(
() =>
localeSort(builtInMappers, mapByKey("name")).map((mapper) => {
const mapperType = protocolMappers.filter(
const mapperType = protocolMappers.find(
(type) => type.id === mapper.protocolMapper,
)[0];
)!;
return {
item: mapper,
id: mapper.name!,

View file

@ -49,7 +49,7 @@ export default function MappingDetails() {
const { realm } = useRealm();
const serverInfo = useServerInfo();
const isGuid = /^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$/;
const isUpdating = !!mapperId.match(isGuid);
const isUpdating = !!isGuid.exec(mapperId);
const isOnClientScope = !!useMatch(MapperRoute.path);
const toDetails = () =>
@ -154,19 +154,23 @@ export default function MappingDetails() {
try {
const mapping = { ...config, ...convertFormValuesToObject(formMapping) };
if (isUpdating) {
isOnClientScope
? await adminClient.clientScopes.updateProtocolMapper(
{ id, mapperId },
{ id: mapperId, ...mapping },
)
: await adminClient.clients.updateProtocolMapper(
if (isOnClientScope) {
await adminClient.clientScopes.updateProtocolMapper(
{ id, mapperId },
{ id: mapperId, ...mapping },
);
} else {
isOnClientScope
? await adminClient.clientScopes.addProtocolMapper({ id }, mapping)
: await adminClient.clients.addProtocolMapper({ id }, mapping);
await adminClient.clients.updateProtocolMapper(
{ id, mapperId },
{ id: mapperId, ...mapping },
);
}
} else {
if (isOnClientScope) {
await adminClient.clientScopes.addProtocolMapper({ id }, mapping);
} else {
await adminClient.clients.addProtocolMapper({ id }, mapping);
}
}
addAlert(t(`mapping${key}Success`), AlertVariant.success);
} catch (error) {

View file

@ -25,7 +25,7 @@ const DateTime = ({ name }: { name: string }) => {
return value;
}
const parts = value.match(DATE_TIME_FORMAT);
const parts = DATE_TIME_FORMAT.exec(value);
const parsedDate = [
date.getFullYear(),
padDateSegment(date.getMonth() + 1),
@ -42,7 +42,7 @@ const DateTime = ({ name }: { name: string }) => {
hour?: number | null,
minute?: number | null,
): string => {
const parts = value.match(DATE_TIME_FORMAT);
const parts = DATE_TIME_FORMAT.exec(value);
if (minute !== undefined && minute !== null) {
return `${parts ? parts[1] : ""} ${hour}:${
minute < 10 ? `0${minute}` : minute

View file

@ -32,7 +32,7 @@ export const InitialAccessTokenList = () => {
const loader = async () => {
try {
return await adminClient.realms.getClientsInitialAccess({ realm });
} catch (error) {
} catch {
return [];
}
};

View file

@ -59,7 +59,7 @@ export const CopyToClipboardButton = ({
try {
await navigator.clipboard.writeText(text);
setCopyState(CopyState.Copied);
} catch (error) {
} catch {
setCopyState(CopyState.Error);
}
};

View file

@ -185,9 +185,9 @@ export const EvaluateScopes = ({ clientId, protocol }: EvaluateScopesProps) => {
({ mapperList, effectiveRoles }) => {
setEffectiveRoles(effectiveRoles);
mapperList.map((mapper) => {
mapper.type = mapperTypes.filter(
mapper.type = mapperTypes.find(
(type) => type.id === mapper.protocolMapper,
)[0];
)!;
});
setProtocolMappers(mapperList);

View file

@ -119,7 +119,7 @@ export const changeScope = async (
const castAdminClient = (adminClient: KeycloakAdminClient) =>
adminClient.clientScopes as unknown as {
[index: string]: Function;
[index: string]: (params: { id: string }) => Promise<void>;
};
export const removeScope = async (

View file

@ -23,28 +23,25 @@ export type ComponentProps = Omit<ConfigPropertyRepresentation, "type"> & {
stringify?: boolean;
};
const ComponentTypes = [
"String",
"Text",
"boolean",
"List",
"Role",
"Script",
"Map",
"Group",
"MultivaluedList",
"ClientList",
"UserProfileAttributeList",
"MultivaluedString",
"File",
"Password",
"Url",
] as const;
export type Components = (typeof ComponentTypes)[number];
type ComponentType =
| "String"
| "Text"
| "boolean"
| "List"
| "Role"
| "Script"
| "Map"
| "Group"
| "MultivaluedList"
| "ClientList"
| "UserProfileAttributeList"
| "MultivaluedString"
| "File"
| "Password"
| "Url";
export const COMPONENTS: {
[index in Components]: FunctionComponent<ComponentProps>;
[index in ComponentType]: FunctionComponent<ComponentProps>;
} = {
String: StringComponent,
Text: TextComponent,
@ -63,5 +60,5 @@ export const COMPONENTS: {
Url: UrlComponent,
} as const;
export const isValidComponentType = (value: string): value is Components =>
export const isValidComponentType = (value: string): value is ComponentType =>
value in COMPONENTS;

View file

@ -13,7 +13,7 @@ export const JsonFileUpload = ({ onChange, ...props }: JsonFileUploadProps) => {
const handleChange = (value: string) => {
try {
onChange(JSON.parse(value));
} catch (error) {
} catch {
onChange({});
console.warn("Invalid json, ignoring value using {}");
}

View file

@ -114,11 +114,14 @@ export function UserDataTableAttributeSearchForm({
]);
reset();
} else {
errors.name?.message &&
if (errors.name?.message) {
addAlert(errors.name.message, AlertVariant.danger);
errors.value?.message &&
}
if (errors.value?.message) {
addAlert(errors.value.message, AlertVariant.danger);
}
}
};
const clearActiveFilters = () => {

View file

@ -191,7 +191,13 @@ export const UserSelect = ({
const option = v?.toString();
if (variant !== "typeaheadMulti") {
const removed = field.value.includes(option);
removed ? field.onChange([]) : field.onChange([option]);
if (removed) {
field.onChange([]);
} else {
field.onChange([option]);
}
setInputValue(
removed
? ""

View file

@ -199,7 +199,13 @@ export const IdentityProviderSelect = ({
const option = v?.toString();
if (variant !== "typeaheadMulti") {
const removed = field.value.includes(option);
removed ? field.onChange([]) : field.onChange([option]);
if (removed) {
field.onChange([]);
} else {
field.onChange([option]);
}
setInputValue(removed ? "" : option || "");
setOpen(false);
} else {

View file

@ -11,7 +11,7 @@ import { DynamicComponents } from "../components/dynamic/DynamicComponents";
import { useRealm } from "../context/realm-context/RealmContext";
import { useFetch } from "../utils/useFetch";
import { useParams } from "../utils/useParams";
import { PAGE_PROVIDER, TAB_PROVIDER } from "./PageList";
import { type PAGE_PROVIDER, TAB_PROVIDER } from "./PageList";
import { toPage } from "./routes";
type PageHandlerProps = {

View file

@ -295,7 +295,7 @@ export default function NewAttributeSettings() {
},
translation.value,
);
} catch (error) {
} catch {
console.error(`Error saving translation for ${translation.locale}`);
}
},

View file

@ -78,8 +78,8 @@ export const PoliciesTab = () => {
const allClientPolicies = globalPolicies?.concat(policies ?? []);
setPolicies(allClientPolicies),
setTablePolicies(allClientPolicies || []),
setPolicies(allClientPolicies);
setTablePolicies(allClientPolicies || []);
setCode(prettyPrintJSON(allClientPolicies));
},
[key],

View file

@ -210,12 +210,12 @@ export const RealmSettingsTabs = () => {
if (response) {
setTableData([response]);
}
} catch (error) {
} catch {
return [];
}
}),
);
} catch (error) {
} catch {
return [];
}
};

View file

@ -148,7 +148,7 @@ export const EffectiveMessageBundles = ({
const sortedMessages = localeSort([...filteredMessages], mapByKey("key"));
return sortedMessages;
} catch (error) {
} catch {
return [];
}
};

View file

@ -137,7 +137,7 @@ export const RealmOverrides = ({
}
return Object.entries(result).slice(first, first + max);
} catch (error) {
} catch {
return [];
}
};
@ -245,7 +245,7 @@ export const RealmOverrides = ({
string,
string
>
)[key],
)[key];
await adminClient.realms.deleteRealmLocalizationTexts({
realm: currentRealm!,
selectedLocale: selectMenuLocale,
@ -322,7 +322,7 @@ export const RealmOverrides = ({
addAlert(t("updateTranslationSuccess"), AlertVariant.success);
setTableRows(newRows);
} catch (error) {
} catch {
addAlert(t("updateTranslationError"), AlertVariant.danger);
}
@ -598,8 +598,11 @@ export const RealmOverrides = ({
setSelectedRowKeys([
(row.cells?.[0] as IRowCell).props.value,
]);
translations.length === 1 &&
if (translations.length === 1) {
setAreAllRowsSelected(true);
}
toggleDeleteDialog();
setKebabOpen(false);
},

View file

@ -101,7 +101,7 @@ export const AttributesGroupTab = ({
});
setTableData([updatedData]);
}
} catch (error) {
} catch {
console.error(`Error removing translations for ${locale}`);
}
}),

View file

@ -92,7 +92,7 @@ export const AttributesTab = ({ setTableData }: AttributesTabProps) => {
});
setTableData([updatedData]);
}
} catch (error) {
} catch {
console.error(`Error removing translations for ${locale}`);
}
}),

View file

@ -168,7 +168,12 @@ export const UserForm = ({
}}
canBrowse={isManager}
onConfirm={(groups) => {
user?.id ? addGroups(groups || []) : addChips(groups || []);
if (user?.id) {
addGroups(groups || []);
} else {
addChips(groups || []);
}
setOpen(false);
}}
onClose={() => setOpen(false)}

View file

@ -175,7 +175,7 @@ export const localeToDisplayName = (locale: string, displayLocale: string) => {
// Once the existing locales have been moved, this code can be removed.
locale === "zh-CN" ? "zh-HANS" : locale === "zh-TW" ? "zh-HANT" : locale,
);
} catch (error) {
} catch {
return locale;
}
};

View file

@ -6,7 +6,7 @@ export type ReplaceString<
Input extends string,
Search extends string,
Replacement extends string,
Options extends ReplaceStringOptions = {},
Options extends ReplaceStringOptions = object,
> = Input extends `${infer Head}${Search}${infer Tail}`
? Options["skipFirst"] extends true
? `${Head}${Search}${ReplaceString<Tail, Search, Replacement>}`

View file

@ -281,10 +281,10 @@ export class Agent {
value === "application/octet-stream",
)
) {
return res.arrayBuffer();
return await res.arrayBuffer();
}
return parseResponse(res);
return await parseResponse(res);
} catch (err) {
if (
err instanceof NetworkError &&

View file

@ -40,11 +40,10 @@ export async function parseResponse(response: Response): Promise<any> {
try {
return JSON.parse(data);
// eslint-disable-next-line no-empty
} catch (error) {}
} catch {
return data;
}
}
function getErrorMessage(data: unknown): string {
if (typeof data !== "object" || data === null) {

View file

@ -451,7 +451,7 @@ describe("Authentication management", () => {
id: config.id!,
});
fail("should not find deleted config");
} catch (error) {
} catch {
// ignore
}
});

View file

@ -35,7 +35,7 @@ describe("Client Scopes", () => {
await kcAdminClient.clientScopes.delDefaultClientScope({
id: currentClientScope.id!,
});
} catch (e) {
} catch {
// ignore
}
@ -44,7 +44,7 @@ describe("Client Scopes", () => {
await kcAdminClient.clientScopes.delDefaultOptionalClientScope({
id: currentClientScope.id!,
});
} catch (e) {
} catch {
// ignore
}
@ -53,7 +53,7 @@ describe("Client Scopes", () => {
await kcAdminClient.clientScopes.delByName({
name: currentClientScopeName,
});
} catch (e) {
} catch {
// ignore
}
});
@ -69,7 +69,7 @@ describe("Client Scopes", () => {
await kcAdminClient.clientScopes.delByName({
name: currentClientScopeName,
});
} catch (e) {
} catch {
// ignore
}
@ -90,7 +90,7 @@ describe("Client Scopes", () => {
await kcAdminClient.clientScopes.delByName({
name: currentClientScopeName,
});
} catch (e) {
} catch {
// ignore
}
@ -273,7 +273,7 @@ describe("Client Scopes", () => {
id: id!,
mapperId: mapperId!,
});
} catch (e) {
} catch {
// ignore
}
});
@ -581,7 +581,7 @@ describe("Client Scopes", () => {
await kcAdminClient.roles.delByName({
name: dummyRoleName,
});
} catch (e) {
} catch {
// ignore
}
});

View file

@ -293,7 +293,7 @@ describe("Clients", () => {
clientScopeId: clientScopeId!,
id: id!,
});
} catch (e) {
} catch {
// ignore
}
@ -302,7 +302,7 @@ describe("Clients", () => {
await kcAdminClient.clientScopes.delByName({
name: dummyClientScope.name!,
});
} catch (e) {
} catch {
// ignore
}
});
@ -387,7 +387,7 @@ describe("Clients", () => {
clientScopeId: clientScopeId!,
id: id!,
});
} catch (e) {
} catch {
// ignore
}
@ -396,7 +396,7 @@ describe("Clients", () => {
await kcAdminClient.clientScopes.delByName({
name: dummyClientScope.name!,
});
} catch (e) {
} catch {
// ignore
}
});
@ -480,7 +480,7 @@ describe("Clients", () => {
id: clientUniqueId!,
mapperId: mapperId!,
});
} catch (e) {
} catch {
// ignore
}
});
@ -649,7 +649,7 @@ describe("Clients", () => {
id: id!,
roleName: dummyRoleName,
});
} catch (e) {
} catch {
// ignore
}
});
@ -804,7 +804,7 @@ describe("Clients", () => {
await kcAdminClient.roles.delByName({
name: dummyRoleName,
});
} catch (e) {
} catch {
// ignore
}
});

View file

@ -342,7 +342,7 @@ describe("Users", () => {
id: currentUser.id!,
groupId: newGroup.id,
});
} catch (e) {
} catch {
fail("Didn't expect an error when deleting a valid group id");
}

View file

@ -44,7 +44,7 @@ export function getInjectedEnvironment<T>(): T {
try {
return JSON.parse(contents);
} catch (error) {
} catch {
throw new Error("Unable to parse environment variables as JSON.");
}
}

View file

@ -6,7 +6,7 @@ import { UserProfileFieldProps } from "./UserProfileFields";
const localeToDisplayName = (locale: string) => {
try {
return new Intl.DisplayNames([locale], { type: "language" }).of(locale);
} catch (error) {
} catch {
return locale;
}
};

View file

@ -25,26 +25,23 @@ export type Options = {
options?: string[];
};
const INPUT_TYPES = [
"text",
"textarea",
"select",
"select-radiobuttons",
"multiselect",
"multiselect-checkboxes",
"html5-email",
"html5-tel",
"html5-url",
"html5-number",
"html5-range",
"html5-datetime-local",
"html5-date",
"html5-month",
"html5-time",
"multi-input",
] as const;
export type InputType = (typeof INPUT_TYPES)[number];
export type InputType =
| "text"
| "textarea"
| "select"
| "select-radiobuttons"
| "multiselect"
| "multiselect-checkboxes"
| "html5-email"
| "html5-tel"
| "html5-url"
| "html5-number"
| "html5-range"
| "html5-datetime-local"
| "html5-date"
| "html5-month"
| "html5-time"
| "multi-input";
export type UserProfileFieldProps = {
t: TFunction;

View file

@ -7,13 +7,14 @@
"prepare": "husky js/.husky"
},
"devDependencies": {
"@eslint/compat": "^1.1.1",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.8.0",
"@types/node": "^22.0.2",
"eslint": "^8.52.0",
"eslint": "^9.8.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-cypress": "^3.4.0",
"eslint-plugin-lodash": "^7.4.0",
"eslint-plugin-lodash": "^8.0.0",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-playwright": "^1.6.2",
"eslint-plugin-prettier": "^5.2.1",
@ -24,7 +25,7 @@
"prettier": "^3.3.3",
"tslib": "^2.6.3",
"typescript": "^5.5.4",
"typescript-eslint": "^7.18.0",
"typescript-eslint": "^8.0.0",
"wireit": "^0.14.5"
},
"pnpm": {

File diff suppressed because it is too large Load diff