AgentSkillsCN

_code-style

遵循命名规范、函数设计与注释指南,确保代码风格的一致性。在编写或审查代码时适用此原则。

SKILL.md
--- frontmatter
name: _code-style
description: Naming conventions, function design, and comment guidelines for code style consistency. Apply when writing or reviewing code.

Code Style

Naming Conventions

  • Variables/Functions: camelCase (fetchUser, isValid)
  • Classes/Components/Types: PascalCase (UserProfile, SearchInput)
  • Constants: SCREAMING_SNAKE_CASE (MAX_RETRY_COUNT, API_BASE_URL)
  • Files: Match the primary export
  • Booleans: Use is, has, should, can prefixes (isLoading, hasError)
  • Event handlers: handle prefix for handlers, on prefix for props

Functions

  • Single responsibility — do one thing well
  • Limit parameters to 3; use an options object for more
  • Prefer pure functions; isolate side effects
  • Use early returns to reduce nesting

Comments

  • Explain "why", not "what" — the code shows what, comments explain intent
  • Delete commented-out code; version control exists
  • Use JSDoc for public APIs and complex functions