AgentSkillsCN

code-style

针对组件、函数以及解构模式的代码风格规范。在编写或审查组件属性、函数签名,或调整代码结构时,建议启用相关规范。

SKILL.md
--- frontmatter
name: code-style
description: Code style conventions for components, functions, and destructuring patterns. Activate when writing or reviewing component props, function signatures, or code structure.

Code Style

On top of ensuring you comply with the Ultracite/Biome linting rules, here are some additional preferred rules.

Components

For component props, always accept a single props variable in the function signature and destructure it afterwards.

tsx
type NavbarProps = {
  links: string[];
};

function Navbar(props: NavbarProps) {
  const { links } = props;
}

Functions

Prefer functions over anonymous functions.

For function parameters, prefer a single object parameter with named keys. The function should only take the single parameter in the function signature and destructure it afterwards.

ts
type GetUserOptions = {
  userId: string;
};

function getUser(opts: GetUserOptions) {
  const { userId } = opts;
  return userId;
}

Existing Typed Functions

The exception to the destructuring rules is when you are working with an already typed function that is being passed as a parameter. For example it's okay to do the following.

ts
export const Route = createFileRoute("/_with-user/app/")({
  component: RouteComponent,
  loader({ context }) {
    const { user } = context;

    return {
      user,
    };
  },
});

loader is already typed with the object so you can just pull out the primary keys from the parameter. All sub-keys should still be destructured.