All skills
sergiodxa avatar

/frontend-js-best-practices

@2987820

JavaScript performance optimization guidelines. Use when writing, reviewing, or refactoring JavaScript/TypeScript code to ensure optimal performance patterns. Triggers on tasks involving loops, data structures, DOM manipulation, or general JS optimization.

Use this Skill: https://skilld.dev/gh/sergiodxa/agent-skills/frontend-js-best-practices

This session only. Nothing lands on disk.

rulesno-default-exports.md

≈582 tokens on demand. Your agent reads this file only when SKILL.md points to it.

No Default Exports

Use named exports for all modules. Avoid default exports.

Why

  1. Consistent imports - Same name everywhere, easier to search/refactor
  2. Better IDE support - Auto-imports work reliably
  3. Explicit naming - Forces meaningful names at export site
  4. Easier refactoring - Rename symbol, all imports update

Pattern

// Bad: default export
export default function formatCurrency(amount: number) {
  return `$${amount.toFixed(2)}`;
}

// Bad: default export class
export default class UserService {
  // ...
}

// Good: named export
export function formatCurrency(amount: number) {
  return `$${amount.toFixed(2)}`;
}

// Good: named export class
export class UserService {
  // ...
}

Components

// Bad: default export component
export default function UserCard({ user }: Props) {
  return <div>{user.name}</div>;
}

// Good: named export component
export function UserCard({ user }: Props) {
  return <div>{user.name}</div>;
}

Importing

// With named exports - consistent name everywhere
import { UserCard } from "~/components/user-card";
import { formatCurrency } from "~/lib/format";

// With default exports - name can vary (bad)
import UserCard from "~/components/user-card";
import Card from "~/components/user-card"; // Same component, different name!

Exception: Remix Route Components

Remix requires a default export for the route component. Name it Component:

// app/routes/_.users/route.tsx
export async function loader() {
  // ...
}

export async function action() {
  // ...
}

// Exception: Remix requires default export for route component
// Always name it "Component"
export default function Component() {
  let data = useLoaderData<typeof loader>();
  return <div>{/* ... */}</div>;
}

Re-exporting

// Bad: re-export as default
export { UserCard as default } from "./user-card";

// Good: named re-export
export { UserCard } from "./user-card";

// Good: barrel file with named exports
export { UserCard } from "./user-card";
export { UserList } from "./user-list";
export { UserAvatar } from "./user-avatar";

Source: SKILL.md on GitHub

1 warning13d5 checks · Risk SAFE
  • Gen Agent Trust Hub13d

    The skill provides a comprehensive set of JavaScript and TypeScript performance and style guidelines. No security issues were detected.

  • Socket13d

    No alerts

  • Snyk13d

    Risk: LOW · No issues

  • Runlayer7mo

    19/19 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 2987820. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 8 months ago

README badge

README badge for sergiodxa/agent-skills/frontend-js-best-practices