AgentSkillsCN

Global Coding Style

运用自动化工具(ESLint、Prettier、Ruff)执行一致的编码风格与格式化标准,辅以清晰的命名规范、自上而下的代码组织方式,以及恰当的函数与组件规模。在编写任何语言的代码、为文件与变量命名、在文件内部规划代码结构、整理导入语句、配置Linter与Formatter,或设置提交前钩子时,可使用此技能。适用于处理TypeScript/JavaScript文件、Python文件、.NET/C#文件、配置文件(tsconfig.json、.prettierrc、.eslintrc),或任何需要统一格式与命名的代码。此技能确保通过Prettier/Ruff实现自动化格式化(让工具自动处理),通过ESLint与分析器强化代码规范,始终启用TypeScript严格模式,遵循清晰的命名规范(React组件采用PascalCase.tsx,工具函数采用camelCase.ts,接口以I前缀命名IPascalCase,无前缀的类型采用PascalCase,函数/常量/数据库字段/API端点/JSON键采用camelCase,私有变量不加下划线前缀),以自上而下的可读代码结构(导入 → 类型 → 组件 → 状态 → 钩子 → 派生值 → 处理器 → 效果 → 提前返回 → JSX),将函数规模控制在可管理范围内(通过滚动测试,超过300行时应拆分),始终对Props进行解构,践行DRY原则(当重复次数达到3次以上时提取共用代码),合理组织导入语句(外部 → 内部绝对路径 → 相对路径 → CSS/资产),除非明确需要,否则不保留向后兼容的代码。

SKILL.md
--- frontmatter
name: Global Coding Style
description: Apply consistent coding style and formatting standards using automated tools (ESLint, Prettier, Ruff) with clear naming conventions, top-down code organization, and appropriate function/component sizing. Use this skill when writing any code in any language, naming files and variables, structuring code within files, organizing imports, configuring linters and formatters, or setting up pre-commit hooks. Apply when working on TypeScript/JavaScript files, Python files, .NET/C# files, configuration files (tsconfig.json, .prettierrc, .eslintrc), or any code that needs consistent formatting and naming. This skill ensures automated formatting with Prettier/Ruff (let tools handle it), ESLint/analyzer enforcement, TypeScript strict mode always enabled, proper naming conventions (PascalCase.tsx for React components, camelCase.ts for utilities, IPascalCase for interfaces with I prefix, PascalCase for types without prefix, camelCase for functions/constants/database fields/API endpoints/JSON keys, no underscore prefix for private variables), top-down readable code structure (imports → types → component → state → hooks → derived values → handlers → effects → early returns → JSX), manageable function sizes (scroll test, split at >300 lines), always destructured props, DRY principles (extract at 3+ repetitions), organized imports (external → internal absolute → relative → CSS/assets), and no backward compatibility code unless explicitly required.

Global Coding Style

When to use this skill:

  • When writing any new code in TypeScript, JavaScript, Python, or .NET
  • When naming files, functions, variables, classes, or interfaces
  • When organizing code structure within files (imports, types, logic)
  • When setting up or configuring linters (ESLint, Ruff, StyleCop)
  • When configuring formatters (Prettier, Black, Ruff)
  • When organizing import statements (external → internal → relative → assets)
  • When deciding between PascalCase, camelCase, or other naming styles
  • When splitting large functions or components into smaller ones (scroll test)
  • When removing dead code or commented-out code (delete, don't comment out)
  • When setting up pre-commit hooks with Husky + lint-staged or pre-commit framework
  • When reviewing code for consistency and readability
  • When working on any code file across all languages and frameworks
  • When enabling TypeScript strict mode in tsconfig.json
  • When choosing indentation (2 spaces for TS/JS, 4 spaces for Python/.NET)

This Skill provides Claude Code with specific guidance on how to adhere to coding standards as they relate to how it should handle global coding style.

Instructions

For details, refer to the information provided in this file: global coding style