Agent Skill
2/7/2026

editorconfig-enforcement

寫入或修改程式碼時,自動遵守專案的 .editorconfig 設定。若專案無 .editorconfig,則依照本 skill 附帶的範例 .editorconfig 來排版。在每次編輯、建立檔案前自動套用。

S
shiyou0130011
0GitHub Stars
1Views
npx skills add shiyou0130011/Skill-of-editorconfig

SKILL.md

Nameeditorconfig-enforcement
Description寫入或修改程式碼時,自動遵守專案的 .editorconfig 設定。若專案無 .editorconfig,則依照本 skill 附帶的範例 .editorconfig 來排版。在每次編輯、建立檔案前自動套用。

name: editorconfig-enforcement description: 寫入或修改程式碼時,自動遵守專案的 .editorconfig 設定。若專案無 .editorconfig,則依照本 skill 附帶的範例 .editorconfig 來排版。在每次編輯、建立檔案前自動套用。 user-invocable: false disable-model-invocation: false allowed-tools: Bash,Read,Glob,Edit,Write

EditorConfig 排版規則

在寫入或修改任何程式碼檔案時,必須遵守以下排版規則。

規則優先順序

  1. 專案 .editorconfig — 若專案根目錄(或任何父目錄)存在 .editorconfig,一律以其設定為準
  2. 範例 .editorconfig — 若專案未提供 .editorconfig,則依照本 skill 同目錄下的 .editorconfig.example 作為排版依據

步驟

在每次編輯或建立檔案之前:

  1. 從專案根目錄往上搜尋 .editorconfig 檔案
  2. 若找到,解析其中對應檔案類型的設定(indent_style、indent_size、tab_width、end_of_line、charset、trim_trailing_whitespace、insert_final_newline 等),並嚴格遵守
  3. 若未找到 .editorconfig,讀取本 skill 目錄下的 .editorconfig.example,並依照其中對應檔案類型的設定來排版

範例 .editorconfig 重點摘要

本 skill 附帶的 .editorconfig.example 包含以下預設:

全域預設

  • 縮排方式:tab
  • tab 寬度:4
  • 換行符號:lf
  • 編碼:utf-8
  • 移除行尾空白:是
  • 檔案結尾加換行:是

語言專屬覆寫(僅限語法本身強制的規則)

檔案類型縮排方式縮排寬度原因
*.gotabgofmt 強制
Makefile / *.mktab語法要求
*.pyspace4PEP 8 規範
*.rsspace4rustfmt 預設
*.tomlspace2慣例
*.{yml,yaml}space2YAML 規範不允許 tab

特殊處理

檔案類型規則原因
*.{md,mdx}不移除行尾空白Markdown 行尾兩空白代表換行
*.{diff,patch}不移除行尾空白、不加結尾換行避免破壞 diff 內容

重要提醒

  • 修改既有檔案時:優先保持該檔案現有的縮排風格一致性。如果檔案已全部使用 spaces,繼續使用 spaces;已全部使用 tabs,繼續使用 tabs。不要在同一個檔案中混用
  • 新建檔案時:依照上述優先順序決定排版方式
  • 專案 .editorconfig 的設定永遠優先:即使範例 .editorconfig 有不同設定,只要專案有自己的 .editorconfig,一律以專案為準
  • 不要在程式碼中加入排版相關的註解說明
Skills Info
Original Name:editorconfig-enforcementAuthor:shiyou0130011