Skip to content

Commit

Permalink
lint: address more issues
Browse files Browse the repository at this point in the history
  • Loading branch information
BenJeau committed Jun 15, 2024
1 parent 24388e0 commit 85b84e0
Show file tree
Hide file tree
Showing 29 changed files with 114 additions and 99 deletions.
4 changes: 2 additions & 2 deletions backend/cli/src/persistence.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
env::current_dir,
fs::{create_dir, File},
fs::{create_dir_all, File},
io::Write,
path::PathBuf,
};
Expand All @@ -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 }
}
Expand Down
2 changes: 1 addition & 1 deletion backend/database/src/validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions backend/server/src/routes/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ impl Modify for SecurityAddon {
);
openapi.components = Some(components);

let scopes: [&str; 0] = [];
let scopes: Vec<String> = 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")
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/ignoreLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function ignoreListSlugQueryOptions(slug: string) {
return queryOptions({
queryKey: ["ignoreLists", "slugs", slug],
queryFn: async ({ signal }) =>
fetcher.get<string>(`/ignoreLists/slugs/${slug}`, {
await fetcher.get<string>(`/ignoreLists/slugs/${slug}`, {
signal,
}),
});
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/api/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function providerSlugQueryOptions(slug: string) {
return queryOptions({
queryKey: ["providers", "slugs", slug],
queryFn: async ({ signal }) =>
fetcher.get<string>(`/providers/slugs/${slug}`, {
await fetcher.get<string>(`/providers/slugs/${slug}`, {
signal,
}),
});
Expand All @@ -42,7 +42,7 @@ export function providerQueryOptions<T extends undefined | string>(
return queryOptions({
queryKey: ["providers", providerId],
queryFn: async ({ signal }) => {
if (providerId == undefined) {
if (!providerId) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function sourceSlugQueryOptions(slug: string) {
return queryOptions({
queryKey: ["sources", "slugs", slug],
queryFn: async ({ signal }) =>
fetcher.get<string>(`/sources/slugs/${slug}`, {
await fetcher.get<string>(`/sources/slugs/${slug}`, {
signal,
}),
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function userQueryOptions<T extends undefined | string>(userId: T) {
return queryOptions({
queryKey: ["users", userId],
queryFn: async ({ signal }) => {
if (userId == undefined) {
if (!userId) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/api-tokens-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ const ApiTokensTable: React.FC<Props> = ({ apiTokens }) => {
<TableHead>
<Trans id="expires.at" />
</TableHead>
<TableHead style={{ width: 110 }}></TableHead>
<TableHead style={{ width: 110 }} />
</TableRow>
</TableHeader>
<TableBody className="text-xs">
Expand Down
44 changes: 25 additions & 19 deletions frontend/src/components/empty.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cn } from "@/lib/utils";
import { TransId } from "@/i18n";
import { TransId, useTranslation } from "@/i18n";
import { Trans } from "@/components";

interface Props {
Expand All @@ -18,24 +18,30 @@ const Empty: React.FC<Props> = ({
imageWidth = 500,
extra,
className,
}) => (
<div
className={cn(
"flex flex-1 flex-col items-center justify-center gap-2 self-center justify-self-center p-4",
className,
)}
>
{image && <img src={image} width={imageWidth} />}
<div className="flex flex-col items-center text-center">
<h2 className="text-lg font-semibold">
<Trans id={title} />
</h2>
<p className="text-sm">
<Trans id={description} />
</p>
}) => {
const { t } = useTranslation();

return (
<div
className={cn(
"flex flex-1 flex-col items-center justify-center gap-2 self-center justify-self-center p-4",
className,
)}
>
{image && (
<img src={image} alt={t("empty.image.alt")} width={imageWidth} />
)}
<div className="flex flex-col items-center text-center">
<h2 className="text-lg font-semibold">
<Trans id={title} />
</h2>
<p className="text-sm">
<Trans id={description} />
</p>
</div>
{extra}
</div>
{extra}
</div>
);
);
};

export default Empty;
1 change: 1 addition & 0 deletions frontend/src/components/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const ErrorComponent: React.FC<Props> = ({ info, error }) => {
<div className="hidden h-[20rem] w-[20rem] flex-col gap-6 lg:flex xl:h-[30rem] xl:w-[30rem]">
<img
src={Image}
alt={t("this.is.fine.image.alt")}
className="h-fit w-fit rounded-xl border border-black object-cover text-white shadow-xl dark:border-border"
/>

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/forms/list-edit-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ const ListEditCreate: React.FC<Props> = ({
<TableHead>
<Trans id="kind" />
</TableHead>
<TableHead style={{ width: 50 }}></TableHead>
<TableHead style={{ width: 50 }} />
</TableRow>
</TableHeader>
<TableBody>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/forms/provider-edit-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ const ProviderEditCreate: React.FC<Props> = ({
<div className="flex gap-2">
<img
src={field.value ?? undefined}
alt={t("favicon")}
alt={t("provider.favicon.alt")}
style={{ imageRendering: "pixelated" }}
className={cn(
"h-8 w-8 rounded border shadow",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/forms/source-edit-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ const SourceEditCreate: React.FC<Props> = ({
<div className="flex gap-2">
<img
src={field.value ?? undefined}
alt="favicon"
alt={t("source.favicon.alt")}
style={{ imageRendering: "pixelated" }}
className={cn(
"h-8 w-8 rounded border shadow",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/layouts/authenticated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const Layout: React.FC = () => {
},
]}
/>
{userHasAnyRoles(user!, ["request_create", "request_view"]) && (
{userHasAnyRoles(user, ["request_create", "request_view"]) && (
<div className={cn("mx-4", isCollapsed && "mx-2")}>
<Separator />
</div>
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/layouts/authentication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<React.PropsWithChildren> = ({
children,
}) => {
const bg = useMemo(() => getRandomBackground(), []);
const { t } = useTranslation();

return (
<div className="relative grid h-[800px] flex-col items-center justify-center lg:max-w-none lg:grid-cols-5 lg:ps-4">
Expand All @@ -16,11 +18,13 @@ export const Authentication: React.FC<React.PropsWithChildren> = ({
<img
id="lowres-login-img"
src={bg.small}
alt={t("login.image.blurry.alt")}
className="absolute h-full flex-1 object-cover blur-xl"
/>
<img
id="login-img"
src={bg.big}
alt={t("login.image.alt")}
className="absolute h-full flex-1 object-cover opacity-0 blur-xl transition duration-1000 ease-out"
style={{ transitionProperty: "filter" }}
onLoad={() => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const Nav: React.FC<NavProps> = ({ 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) {
Expand All @@ -74,7 +74,7 @@ const Nav: React.FC<NavProps> = ({ links, isCollapsed }) => {
<nav className="grid gap-1 px-2 group-[[data-collapsed=true]]:justify-center group-[[data-collapsed=true]]:px-2">
{links
.filter(
(link) => !("roles" in link) || userHasRoles(user!, link.roles),
(link) => !("roles" in link) || userHasRoles(user, link.roles),
)
.map((link, index) =>
isCollapsed ? (
Expand Down
65 changes: 21 additions & 44 deletions frontend/src/components/raw-content.tsx
Original file line number Diff line number Diff line change
@@ -1,54 +1,31 @@
import { useMemo } from "react";

import CopyButton from "@/components/copy-button";
import { cn } from "@/lib/utils";

const RawContent: React.FC<{
content?: string;
iframe?: boolean;
dangerouslyShowContent?: boolean;
className?: string;
}> = ({ content, iframe, dangerouslyShowContent, className }) => {
const cleanedContent = useMemo(() => {
return dangerouslyShowContent
? content
: content
?.replaceAll(/http/gi, "hxxp")
.replaceAll(/src="\/\//gi, 'src="hxxp://');
}, [content, dangerouslyShowContent]);

return (
<div
className={cn(
"dark:border-800 dark:bg-950 relative flex h-full w-full flex-1 overflow-hidden rounded border bg-muted shadow-md ring-white",
className,
)}
>
<div className="flex h-full max-h-[400px] min-h-[1.5rem] flex-1 text-xs dark:bg-black/50">
{iframe && (
<iframe
sandbox=""
srcDoc={cleanedContent}
className="h-[400px] w-full flex-1 dark:bg-white"
/>
)}
{!iframe && (
<div
style={{
fontFamily:
'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
}}
className="flex h-full max-h-[400px] w-full flex-1 overflow-y-scroll whitespace-pre-wrap break-all p-3"
>
{cleanedContent}
</div>
)}
<div className="absolute bottom-2 right-2">
<CopyButton text={content} />
</div>
}> = ({ content, className }) => (
<div
className={cn(
"dark:border-800 dark:bg-950 relative flex h-full w-full flex-1 overflow-hidden rounded border bg-muted shadow-md ring-white",
className,
)}
>
<div className="flex h-full max-h-[400px] min-h-[1.5rem] flex-1 text-xs dark:bg-black/50">
<div
style={{
fontFamily:
'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
}}
className="flex h-full max-h-[400px] w-full flex-1 overflow-y-scroll whitespace-pre-wrap break-all p-3"
>
{content}
</div>
<div className="absolute bottom-2 right-2">
<CopyButton text={content} />
</div>
</div>
);
};
</div>
);

export default RawContent;
14 changes: 10 additions & 4 deletions frontend/src/components/request-data-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,16 @@ const RequestDataView: React.FC<Props> = ({ isFetching, data }) => {

return [
sourceWithoutErrors.sort((a, b) => {
const aDataLength =
a.data == undefined ? 0 : Array.isArray(a.data) ? a.data.length : 1;
const bDataLength =
b.data == undefined ? 0 : Array.isArray(b.data) ? b.data.length : 1;
const aDataLength = !a.data
? 0
: Array.isArray(a.data)
? a.data.length
: 1;
const bDataLength = !b.data
? 0
: Array.isArray(b.data)
? b.data.length
: 1;

if (aDataLength > bDataLength) {
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { Badge } from "@/components/ui/badge";
import { ComponentSearchResultProps } from "@/components/generic-panel-search";
import config from "@/lib/config";
import { Trans } from "@/components";
import { useTranslation } from "@/i18n";

const ProviderSearchResult: React.FC<ComponentSearchResultProps<Provider>> = ({
data: { slug, name, description, enabled, numSources, url, favicon },
}) => {
const [imgHasError, setImgHasError] = useState(false);
const { t } = useTranslation();

return (
<Link
Expand All @@ -30,6 +32,7 @@ const ProviderSearchResult: React.FC<ComponentSearchResultProps<Provider>> = ({
src={
favicon ?? `${config.rest_server_base_url}/favicon?url=${url}`
}
alt={t("provider.favicon.alt")}
style={{ imageRendering: "pixelated" }}
className={cn(
"h-6 w-6 rounded border shadow",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import { ComponentSearchResultProps } from "@/components/generic-panel-search";
import config from "@/lib/config";
import { sourceKindIconMapping } from "@/lib/data";
import { Trans } from "@/components";
import { useTranslation } from "@/i18n";

const SourceSearchResult: React.FC<ComponentSearchResultProps<Source>> = ({
data: { slug, name, description, enabled, providerId, url, favicon, kind },
}) => {
const [imgHasError, setImgHasError] = useState(true);
const { t } = useTranslation();

const SourceKindIcon = sourceKindIconMapping[kind];

Expand All @@ -33,6 +35,7 @@ const SourceSearchResult: React.FC<ComponentSearchResultProps<Source>> = ({
src={
favicon ?? `${config.rest_server_base_url}/favicon?url=${url}`
}
alt={t("source.favicon.alt")}
style={{ imageRendering: "pixelated" }}
className={cn(
"hidden h-8 w-8 rounded border shadow",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/secrets-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const SecretsTable: React.FC<Props> = ({ secrets }) => {
>
<Trans id="sources" />
</TableHead>
<TableHead style={{ width: 80 }}></TableHead>
<TableHead style={{ width: 80 }} />
</TableRow>
</TableHeader>
<TableBody className="text-xs">
Expand Down
Loading

0 comments on commit 85b84e0

Please sign in to comment.