Skip to content

Commit

Permalink
function to arrow function
Browse files Browse the repository at this point in the history
  • Loading branch information
richardgill committed Apr 1, 2024
1 parent c54da46 commit 5499231
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 56 deletions.
4 changes: 2 additions & 2 deletions apps/docs/db/seed.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { db, WaitingList } from "astro:db";

// https://astro.build/db/seed
export default async function seed() {
export default async () => {
await db
.insert(WaitingList)
.values([
{ email: "[email protected]" },
{ email: "[email protected]" },
]);
}
};
6 changes: 4 additions & 2 deletions apps/docs/src/components/faq-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const faqData = [
},
];

export default function FaqSection() {
const FaqSection = () => {
return (
<Accordion type="single" collapsible className="w-full">
{faqData.map((faqItem) => (
Expand All @@ -49,4 +49,6 @@ export default function FaqSection() {
))}
</Accordion>
);
}
};

export default FaqSection;
8 changes: 4 additions & 4 deletions apps/docs/src/components/forms/waitlist-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ const formSchema = z.object({
}),
});

export function WaitlistForm() {
export const WaitlistForm = () => {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: {
email: "",
},
});

async function onSubmit(values: z.infer<typeof formSchema>) {
const onSubmit = async (values: z.infer<typeof formSchema>) => {
const response = await fetch("/api/waitlist", {
method: "POST",
headers: {
Expand All @@ -51,7 +51,7 @@ export function WaitlistForm() {
description: "Please try again!",
});
}
}
};

return (
<Form {...form}>
Expand All @@ -78,4 +78,4 @@ export function WaitlistForm() {
</form>
</Form>
);
}
};
11 changes: 3 additions & 8 deletions apps/docs/src/components/layout/sheet-mobile-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ interface SheetMobileProps {
sidebarNavItems?: SidebarNavItem[];
}

export function SheetMobileNav({
export const SheetMobileNav = ({
mainNavItems,
sidebarNavItems,
}: SheetMobileProps) {
}: SheetMobileProps) => {
const [open, setOpen] = React.useState(false);

const mergedMainNavItems = mainNavItems?.filter(
Expand All @@ -24,11 +24,6 @@ export function SheetMobileNav({
self.findIndex((t) => t.href === item.href && t.title === item.title),
);

// [
// ...marketingConfig.mainNav,
// ...docsConfig.mainNav,
// ]

return (
<Sheet open={open} onOpenChange={setOpen}>
<SheetTrigger asChild>
Expand Down Expand Up @@ -108,4 +103,4 @@ export function SheetMobileNav({
</SheetContent>
</Sheet>
);
}
};
4 changes: 2 additions & 2 deletions apps/docs/src/components/theme-toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const MoonIcon = () => (
</>
);

export function ThemeToggle() {
export const ThemeToggle = () => {
const [theme, setTheme] = useState(() => {
if (import.meta.env.SSR) {
return undefined;
Expand Down Expand Up @@ -115,4 +115,4 @@ export function ThemeToggle() {
) : (
<div />
);
}
};
12 changes: 6 additions & 6 deletions apps/docs/src/components/toc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { cn } from "@/lib/utils";
interface TocProps {
toc: TableOfContents;
}
export function DashboardTableOfContents({ toc }: TocProps) {
export const DashboardTableOfContents = ({ toc }: TocProps) => {
const itemIds = toc.items
? toc.items
.flatMap((item) => [item.url, item?.items?.map((item) => item.url)])
Expand All @@ -26,9 +26,9 @@ export function DashboardTableOfContents({ toc }: TocProps) {
<Tree tree={toc} activeItem={activeHeading} />
</div>
);
}
};

function useActiveItem(itemIds: (string | undefined)[]) {
const useActiveItem = (itemIds: (string | undefined)[]) => {
const [activeId, setActiveId] = React.useState<string>("");

React.useEffect(() => {
Expand Down Expand Up @@ -69,15 +69,15 @@ function useActiveItem(itemIds: (string | undefined)[]) {
}, [itemIds]);

return activeId;
}
};

interface TreeProps {
tree: TableOfContents;
level?: number;
activeItem?: string | null;
}

function Tree({ tree, level = 1, activeItem }: TreeProps) {
const Tree = ({ tree, level = 1, activeItem }: TreeProps) => {
return tree?.items?.length && level < 3 ? (
<ul className={cn("m-0 list-none", { "pl-4": level !== 1 })}>
{tree.items.map((item, index) => {
Expand All @@ -102,4 +102,4 @@ function Tree({ tree, level = 1, activeItem }: TreeProps) {
})}
</ul>
) : null;
}
};
4 changes: 2 additions & 2 deletions apps/docs/src/components/ui/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}

function Badge({ className, variant, radius, ...props }: BadgeProps) {
const Badge = ({ className, variant, radius, ...props }: BadgeProps) => {
return (
<div
className={cn(badgeVariants({ variant, radius }), className)}
{...props}
/>
);
}
};

export { Badge, badgeVariants };
4 changes: 2 additions & 2 deletions apps/docs/src/hooks/use-mounted.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from "react";

export function useMounted() {
export const useMounted = () => {
const [mounted, setMounted] = React.useState(false);

React.useEffect(() => {
setMounted(true);
}, []);

return mounted;
}
};
16 changes: 8 additions & 8 deletions apps/docs/src/lib/fetchers.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import { getCollection } from "astro:content";

export async function getCategories() {
export const getCategories = async () => {
const posts = await getCollection("blog");
const categories = [
...new Set(posts.map((post) => post.data.category).flat()),
];

return categories;
}
};

export async function getPosts() {
export const getPosts = async () => {
const posts = (await getCollection("blog")).sort(
(a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf(),
);

return posts;
}
};

export async function getPostsByCategory(category: string) {
export const getPostsByCategory = async (category: string) => {
const posts = (await getCollection("blog"))
.filter((post) => post.data.category.includes(category))
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());

return posts;
}
};

export async function getGuides() {
export const getGuides = async () => {
const guides = (await getCollection("guides"))
.filter((guide) => guide.data.published)
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());

return guides;
}
};
14 changes: 7 additions & 7 deletions apps/docs/src/lib/toc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { visit } from "unist-util-visit";

const textTypes = ["text", "emphasis", "strong", "inlineCode"];

function flattenNode(node) {
const flattenNode = (node) => {
const p = [];
visit(node, (node) => {
if (!textTypes.includes(node.type)) return;
p.push(node.value);
});
return p.join(``);
}
};

interface Item {
title: string;
Expand All @@ -26,7 +26,7 @@ interface Items {
items?: Item[];
}

function getItems(node, current): Items {
const getItems = (node, current): Items => {
if (!node) {
return {};
}
Expand Down Expand Up @@ -61,7 +61,7 @@ function getItems(node, current): Items {
}

return {};
}
};

const getToc = () => (node, file) => {
const table = toc(node);
Expand All @@ -70,10 +70,10 @@ const getToc = () => (node, file) => {

export type TableOfContents = Items;

export async function getTableOfContents(
export const getTableOfContents = async (
content: string,
): Promise<TableOfContents> {
): Promise<TableOfContents> => {
const result = await remark().use(getToc).process(content);

return result.data;
}
};
20 changes: 10 additions & 10 deletions apps/docs/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ import { clsx, type ClassValue } from "clsx";
import { format } from "date-fns";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
export const cn = (...inputs: ClassValue[]) => {
return twMerge(clsx(inputs));
}
};

export function wait(ms: number) {
export const wait = (ms: number) => {
return new Promise((resolve) => setTimeout(resolve, ms));
}
};

export function formatDate(date: Date) {
export const formatDate = (date: Date) => {
return format(date, "LLL dd, y");
}
};

export function extractSegmentURL(path: string) {
export const extractSegmentURL = (path: string) => {
if (!path) return "";
if (path === "/") return null;
return path.split("/")[1];
}
};

export function capitalizer(text: string) {
export const capitalizer = (text: string) => {
return text.charAt(0).toUpperCase() + text.slice(1);
}
};
4 changes: 2 additions & 2 deletions apps/docs/src/pages/rss.xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { siteConfig } from "@/config/site";
import rss from "@astrojs/rss";
import { getCollection } from "astro:content";

export async function get(context) {
export const get = async (context) => {
const posts = await getCollection("blog");
return rss({
title: siteConfig.name,
Expand All @@ -13,4 +13,4 @@ export async function get(context) {
link: `/blog/${post.slug}/`,
})),
});
}
};
15 changes: 14 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import js from "@eslint/js";
import typescriptPlugin from "@typescript-eslint/eslint-plugin";
import typescriptParser from "@typescript-eslint/parser";
import eslintPluginAstro from "eslint-plugin-astro";
import preferArrow from "eslint-plugin-prefer-arrow";
import reactRecommended from "eslint-plugin-react/configs/recommended.js";
import globals from "globals";

const astroRecommended = eslintPluginAstro.configs["flat/recommended"];

export default [
Expand Down Expand Up @@ -41,8 +41,21 @@ export default [
{
files: ["apps/docs/**/*.{js,jsx,mjs,cjs,ts,tsx}"],
...js.configs.recommended,
plugins: {
"prefer-arrow": preferArrow,
...js.configs.recommended.plugins,
},
rules: {
"no-unused-vars": ["error", { varsIgnorePattern: "React" }],
"prefer-arrow-callback": "error",
"prefer-arrow/prefer-arrow-functions": [
"error",
{
disallowPrototype: true,
singleReturnOnly: false,
classPropertiesAllowed: false,
},
],
},
},
{
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@typescript-eslint/parser": "^7.4.0",
"eslint": "^8.57.0",
"eslint-plugin-astro": "^0.33.1",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-react": "^7.34.1",
"globals": "^15.0.0",
"husky": "^9.0.11",
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5499231

Please sign in to comment.