AgentSkillsCN

Coding Style 技能

JavaScript、TypeScript、PHP、Python、CSS 代码规范

SKILL.md
--- frontmatter
name: Coding Style 技能
description: JavaScript、TypeScript、PHP、Python、CSS 程式碼規範

📝 Coding Style 技能

規範索引

語言規範說明
JavaScript - Airbnb最流行、嚴格
JavaScript - Standard無分號風格
TypeScriptTypeScript 特定規範
PHP - PSR-12PHP 官方標準
PHP - LaravelLaravel 風格
Python - PEP8Python 官方標準
CSS - BEM命名規範

共通原則

命名規範

類型JavaScriptPHPPython
變數camelCase$camelCasesnake_case
函式camelCasecamelCasesnake_case
類別PascalCasePascalCasePascalCase
常數UPPER_SNAKEUPPER_SNAKEUPPER_SNAKE

格式化

項目建議
縮排2 或 4 空格(依語言)
行寬80-120 字元
檔案結尾保留空行
引號統一使用單引號或雙引號

工具設定

ESLint + Prettier (JS/TS)

json
// .eslintrc.json
{
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier"
  ],
  "parser": "@typescript-eslint/parser"
}
json
// .prettierrc
{
  "semi": true,
  "singleQuote": true,
  "tabWidth": 2,
  "trailingComma": "es5"
}

EditorConfig

ini
# .editorconfig
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{php,py}]
indent_size = 4

Git Hooks

json
// package.json
{
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.{js,ts,tsx}": ["eslint --fix", "prettier --write"],
    "*.css": ["stylelint --fix"]
  }
}

選擇精靈

不確定用什麼規範?使用 Coding Style 精靈