From 85b84e006747bea5b875a536005213a4b7b09e9c Mon Sep 17 00:00:00 2001 From: Benoit Jeaurond Date: Fri, 14 Jun 2024 20:46:37 -0400 Subject: [PATCH] lint: address more issues --- backend/cli/src/persistence.rs | 4 +- backend/database/src/validators.rs | 2 +- backend/server/src/routes/openapi.rs | 6 +- frontend/src/api/ignoreLists.ts | 2 +- frontend/src/api/providers.ts | 4 +- frontend/src/api/sources.ts | 2 +- frontend/src/api/users.ts | 2 +- frontend/src/components/api-tokens-table.tsx | 2 +- frontend/src/components/empty.tsx | 44 +++++++------ frontend/src/components/error.tsx | 1 + .../src/components/forms/list-edit-create.tsx | 2 +- .../components/forms/provider-edit-create.tsx | 2 +- .../components/forms/source-edit-create.tsx | 2 +- .../src/components/layouts/authenticated.tsx | 2 +- .../src/components/layouts/authentication.tsx | 4 ++ frontend/src/components/nav.tsx | 4 +- frontend/src/components/raw-content.tsx | 65 ++++++------------- frontend/src/components/request-data-view.tsx | 14 ++-- .../search-results/provider-search-result.tsx | 3 + .../search-results/source-search-result.tsx | 3 + frontend/src/components/secrets-table.tsx | 2 +- frontend/src/components/sources/index.tsx | 11 ++-- frontend/src/i18n/en_CA.json | 6 ++ frontend/src/i18n/fr_CA.json | 6 ++ frontend/src/i18n/tools/unusedKeys.ts | 1 + frontend/src/lib/auth.ts | 12 ++-- frontend/src/routes/docs.tsx | 1 + frontend/src/routes/history/route.tsx | 2 +- frontend/src/routes/sources/$slug.tsx | 2 +- 29 files changed, 114 insertions(+), 99 deletions(-) diff --git a/backend/cli/src/persistence.rs b/backend/cli/src/persistence.rs index ea16296..a274e88 100644 --- a/backend/cli/src/persistence.rs +++ b/backend/cli/src/persistence.rs @@ -1,6 +1,6 @@ use std::{ env::current_dir, - fs::{create_dir, File}, + fs::{create_dir_all, File}, io::Write, path::PathBuf, }; @@ -16,7 +16,7 @@ impl SourceFileWriter { let mut directory = current_dir().unwrap(); directory.push(Local::now().naive_local().to_string()); - create_dir(&directory).unwrap(); + create_dir_all(&directory).unwrap(); Self { directory } } diff --git a/backend/database/src/validators.rs b/backend/database/src/validators.rs index 489d144..a90fe50 100644 --- a/backend/database/src/validators.rs +++ b/backend/database/src/validators.rs @@ -15,7 +15,7 @@ fn validate_hash(data: &str, expected_hash: Hash) -> bool { #[instrument] fn validate_domain(data: &str) -> bool { - data.split('.').count() > 1 && data.split('.').all(|section| !section.is_empty()) + data.contains('.') && data.split('.').all(|section| !section.is_empty()) } impl Indicator { diff --git a/backend/server/src/routes/openapi.rs b/backend/server/src/routes/openapi.rs index 6c6ca7a..204cda8 100644 --- a/backend/server/src/routes/openapi.rs +++ b/backend/server/src/routes/openapi.rs @@ -245,10 +245,10 @@ impl Modify for SecurityAddon { ); openapi.components = Some(components); - let scopes: [&str; 0] = []; + let scopes: Vec = Vec::with_capacity(0); let data = vec![ - SecurityRequirement::new("api_key", scopes), - SecurityRequirement::new("basic_auth", scopes), + SecurityRequirement::new("api_key", &scopes), + SecurityRequirement::new("basic_auth", &scopes), ]; let unauthorized_response: RefOr<_> = ResponseBuilder::new() .description("Need to provide valid authentication") diff --git a/frontend/src/api/ignoreLists.ts b/frontend/src/api/ignoreLists.ts index a2aadd7..63ae7e4 100644 --- a/frontend/src/api/ignoreLists.ts +++ b/frontend/src/api/ignoreLists.ts @@ -32,7 +32,7 @@ export function ignoreListSlugQueryOptions(slug: string) { return queryOptions({ queryKey: ["ignoreLists", "slugs", slug], queryFn: async ({ signal }) => - fetcher.get(`/ignoreLists/slugs/${slug}`, { + await fetcher.get(`/ignoreLists/slugs/${slug}`, { signal, }), }); diff --git a/frontend/src/api/providers.ts b/frontend/src/api/providers.ts index f2f1ff9..a706c32 100644 --- a/frontend/src/api/providers.ts +++ b/frontend/src/api/providers.ts @@ -30,7 +30,7 @@ export function providerSlugQueryOptions(slug: string) { return queryOptions({ queryKey: ["providers", "slugs", slug], queryFn: async ({ signal }) => - fetcher.get(`/providers/slugs/${slug}`, { + await fetcher.get(`/providers/slugs/${slug}`, { signal, }), }); @@ -42,7 +42,7 @@ export function providerQueryOptions( return queryOptions({ queryKey: ["providers", providerId], queryFn: async ({ signal }) => { - if (providerId == undefined) { + if (!providerId) { return null; } diff --git a/frontend/src/api/sources.ts b/frontend/src/api/sources.ts index 5c0d7eb..36f865f 100644 --- a/frontend/src/api/sources.ts +++ b/frontend/src/api/sources.ts @@ -32,7 +32,7 @@ export function sourceSlugQueryOptions(slug: string) { return queryOptions({ queryKey: ["sources", "slugs", slug], queryFn: async ({ signal }) => - fetcher.get(`/sources/slugs/${slug}`, { + await fetcher.get(`/sources/slugs/${slug}`, { signal, }), }); diff --git a/frontend/src/api/users.ts b/frontend/src/api/users.ts index 01700f2..20247fe 100644 --- a/frontend/src/api/users.ts +++ b/frontend/src/api/users.ts @@ -25,7 +25,7 @@ export function userQueryOptions(userId: T) { return queryOptions({ queryKey: ["users", userId], queryFn: async ({ signal }) => { - if (userId == undefined) { + if (!userId) { return null; } diff --git a/frontend/src/components/api-tokens-table.tsx b/frontend/src/components/api-tokens-table.tsx index 4260a06..6caed9e 100644 --- a/frontend/src/components/api-tokens-table.tsx +++ b/frontend/src/components/api-tokens-table.tsx @@ -216,7 +216,7 @@ const ApiTokensTable: React.FC = ({ apiTokens }) => { - + diff --git a/frontend/src/components/empty.tsx b/frontend/src/components/empty.tsx index 6177870..c01160a 100644 --- a/frontend/src/components/empty.tsx +++ b/frontend/src/components/empty.tsx @@ -1,5 +1,5 @@ import { cn } from "@/lib/utils"; -import { TransId } from "@/i18n"; +import { TransId, useTranslation } from "@/i18n"; import { Trans } from "@/components"; interface Props { @@ -18,24 +18,30 @@ const Empty: React.FC = ({ imageWidth = 500, extra, className, -}) => ( -
- {image && } -
-

- -

-

- -

+}) => { + const { t } = useTranslation(); + + return ( +
+ {image && ( + {t("empty.image.alt")} + )} +
+

+ +

+

+ +

+
+ {extra}
- {extra} -
-); + ); +}; export default Empty; diff --git a/frontend/src/components/error.tsx b/frontend/src/components/error.tsx index 9b27c14..d829099 100644 --- a/frontend/src/components/error.tsx +++ b/frontend/src/components/error.tsx @@ -41,6 +41,7 @@ const ErrorComponent: React.FC = ({ info, error }) => {
{t("this.is.fine.image.alt")} diff --git a/frontend/src/components/forms/list-edit-create.tsx b/frontend/src/components/forms/list-edit-create.tsx index 8f4dce2..089d989 100644 --- a/frontend/src/components/forms/list-edit-create.tsx +++ b/frontend/src/components/forms/list-edit-create.tsx @@ -480,7 +480,7 @@ const ListEditCreate: React.FC = ({ - + diff --git a/frontend/src/components/forms/provider-edit-create.tsx b/frontend/src/components/forms/provider-edit-create.tsx index ea48a7e..2b00eb4 100644 --- a/frontend/src/components/forms/provider-edit-create.tsx +++ b/frontend/src/components/forms/provider-edit-create.tsx @@ -367,7 +367,7 @@ const ProviderEditCreate: React.FC = ({
{t("favicon")} = ({
favicon { }, ]} /> - {userHasAnyRoles(user!, ["request_create", "request_view"]) && ( + {userHasAnyRoles(user, ["request_create", "request_view"]) && (
diff --git a/frontend/src/components/layouts/authentication.tsx b/frontend/src/components/layouts/authentication.tsx index 9ddea63..98a8ebd 100644 --- a/frontend/src/components/layouts/authentication.tsx +++ b/frontend/src/components/layouts/authentication.tsx @@ -3,11 +3,13 @@ import { TrainFrontTunnel } from "lucide-react"; import { Layouts, Trans } from "@/components"; import { getRandomBackground } from "@/assets"; +import { useTranslation } from "@/i18n"; export const Authentication: React.FC = ({ children, }) => { const bg = useMemo(() => getRandomBackground(), []); + const { t } = useTranslation(); return (
@@ -16,11 +18,13 @@ export const Authentication: React.FC = ({ {t("login.image.blurry.alt")} {t("login.image.alt")} { diff --git a/frontend/src/components/nav.tsx b/frontend/src/components/nav.tsx index 071a0e5..bcf0336 100644 --- a/frontend/src/components/nav.tsx +++ b/frontend/src/components/nav.tsx @@ -59,7 +59,7 @@ const Nav: React.FC = ({ links, isCollapsed }) => { const user = useAtomValue(userAtom); const canViewAnyLinks = links.some( - (link) => !("roles" in link) || userHasRoles(user!, link.roles), + (link) => !("roles" in link) || userHasRoles(user, link.roles), ); if (!canViewAnyLinks) { @@ -74,7 +74,7 @@ const Nav: React.FC = ({ links, isCollapsed }) => {