From 18e0a930be7f36569c316dec9aa40757932ea8fa Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Wed, 18 Aug 2021 11:29:42 +0200 Subject: [PATCH] Prefer Array#includes() over Array#indexOf() (#1013) --- .eslintrc.js | 7 ++++++- src/clients/ClientsSection.tsx | 2 +- src/components/bread-crumb/GroupBreadCrumbs.tsx | 2 +- src/components/keycloak-tabs/KeycloakTabs.tsx | 2 +- src/identity-providers/add/DetailSettings.tsx | 2 +- src/user-federation/ldap/mappers/LdapMapperList.tsx | 2 +- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 22c4670492..f7cdd0c04e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,6 +1,9 @@ /** @type {import("eslint").Linter.Config } */ module.exports = { root: true, + parserOptions: { + project: './tsconfig.json', + }, env: { node: true, }, @@ -17,7 +20,9 @@ module.exports = { }, }, rules: { - // Always prefer using an optional chain expression, as it's more concise and easier to read. + // Prefer using `includes()` to check if values exist over `indexOf() === -1`, as it's a more appropriate API for this. + "@typescript-eslint/prefer-includes": "error", + // Prefer using an optional chain expression, as it's more concise and easier to read. "@typescript-eslint/prefer-optional-chain": "error", "no-unused-vars": "off", "@typescript-eslint/no-unused-vars": "error", diff --git a/src/clients/ClientsSection.tsx b/src/clients/ClientsSection.tsx index e0fcfbe365..9dd8f7d866 100644 --- a/src/clients/ClientsSection.tsx +++ b/src/clients/ClientsSection.tsx @@ -171,7 +171,7 @@ export const ClientsSection = () => { if (client.rootUrl) { if ( !client.rootUrl.startsWith("http") || - client.rootUrl.indexOf("$") !== -1 + client.rootUrl.includes("$") ) { client.rootUrl = client.rootUrl diff --git a/src/components/bread-crumb/GroupBreadCrumbs.tsx b/src/components/bread-crumb/GroupBreadCrumbs.tsx index 37d191e7d7..1791439942 100644 --- a/src/components/bread-crumb/GroupBreadCrumbs.tsx +++ b/src/components/bread-crumb/GroupBreadCrumbs.tsx @@ -16,7 +16,7 @@ export const GroupBreadCrumbs = () => { useEffect(() => { return history.listen(({ pathname }) => { - if (pathname.indexOf("/groups") === -1 || pathname.endsWith("/groups")) { + if (!pathname.includes("/groups") || pathname.endsWith("/groups")) { clear(); } }); diff --git a/src/components/keycloak-tabs/KeycloakTabs.tsx b/src/components/keycloak-tabs/KeycloakTabs.tsx index a8200c0a95..f60e8ba995 100644 --- a/src/components/keycloak-tabs/KeycloakTabs.tsx +++ b/src/components/keycloak-tabs/KeycloakTabs.tsx @@ -15,7 +15,7 @@ const createUrl = ( let url = path; for (const key in params) { const value = params[key]; - if (url.indexOf(key) !== -1) { + if (url.includes(key)) { url = url.replace(new RegExp(`:${key}\\??`), value || ""); } } diff --git a/src/identity-providers/add/DetailSettings.tsx b/src/identity-providers/add/DetailSettings.tsx index 9d29e68106..5b916a0804 100644 --- a/src/identity-providers/add/DetailSettings.tsx +++ b/src/identity-providers/add/DetailSettings.tsx @@ -133,7 +133,7 @@ export const DetailSettings = () => { }); const sections = [t("generalSettings"), t("advancedSettings")]; - const isOIDC = id.indexOf("oidc") !== -1; + const isOIDC = id.includes("oidc"); if (isOIDC) { sections.splice(1, 0, t("oidcSettings")); diff --git a/src/user-federation/ldap/mappers/LdapMapperList.tsx b/src/user-federation/ldap/mappers/LdapMapperList.tsx index 762e959214..f1d580b905 100644 --- a/src/user-federation/ldap/mappers/LdapMapperList.tsx +++ b/src/user-federation/ldap/mappers/LdapMapperList.tsx @@ -69,7 +69,7 @@ export const LdapMapperList = () => { }); const getUrl = (url: string) => { - if (url.indexOf("/mappers") === -1) { + if (!url.includes("/mappers")) { return `${url}/mappers`; } return `${url}`;