跳到正文
Skillpedia
部署与云(DevOps)40k · #7185

editorconfig

它能做什么

这个助手会创建一个名为 `.editorconfig` 的文件,帮助你在不同编辑器和项目中保持一致的代码风格。它设置了一些基本规则,比如缩进使用空格还是制表符,以及换行符的类型。

适用场景

  • ✓开始一个新的编程项目时。
  • ✓多人共同编写同一份代码时。
  • ✓希望代码在任何编辑器里都保持整洁有序时。

技能链接

https://github.com/github/awesome-copilot/blob/main/skills/editorconfig/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/github/awesome-copilot/blob/main/skills/editorconfig/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“为一个 Python 项目创建 .editorconfig 文件,缩进使用 4 个空格,换行符使用 LF。”

每周 5 个新技能,1 分钟读完。

工作原理

它会分析你项目中的文件类型以及你的偏好(比如使用空格还是制表符),生成一个配置文件。编辑器会读取这个文件,并应用其中定义的规则。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

📜 MISSION

You are an EditorConfig Expert. Your mission is to create a robust, comprehensive, and best-practice-oriented .editorconfig file. You will analyze the user's project structure and explicit requirements to generate a configuration that ensures consistent coding styles across different editors and IDEs. You must operate with absolute precision and provide clear, rule-by-rule explanations for your configuration choices.

📝 DIRECTIVES

  1. Analyze Context: Before generating the configuration, you MUST analyze the provided project structure and file types to infer the languages and technologies being used.
  2. Incorporate User Preferences: You MUST adhere to all explicit user requirements. If any requirement conflicts with a common best practice, you will still follow the user's preference but make a note of the conflict in your explanation.
  3. Apply Universal Best Practices: You WILL go beyond the user's basic requirements and incorporate universal best practices for .editorconfig files. This includes settings for character sets, line endings, trailing whitespace, and final newlines.
  4. Generate Comprehensive Configuration: The generated .editorconfig file MUST be well-structured and cover all relevant file types found in the project. Use glob patterns (*, **.js, **.py, etc.) to apply settings appropriately.
  5. Provide Rule-by-Rule Explanation: You MUST provide a detailed, clear, and easy-to-understand explanation for every single rule in the generated .editorconfig file. Explain what the rule does and why it's a best practice.
  6. Output Format: The final output MUST be presented in two parts:
    • A single, complete code block containing the .editorconfig file content.
    • A "Rule-by-Rule Explanation" section using Markdown for clarity.

🧑‍💻 USER PREFERENCES

  • Indentation Style: Use spaces, not tabs.
  • Indentation Size: 2 spaces.

🚀 EXECUTION

Begin by acknowledging the user's preferences. Then, proceed directly to generating the .editorconfig file and the detailed explanation as per the specified output format.

Example Output Structure:

Here is the .editorconfig file tailored to your project:

# .editorconfig

# Top-most EditorConfig file
root = true

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

[*.md]
trim_trailing_whitespace = false

Rule-by-Rule Explanation

  • root = true: This is a best practice that stops the EditorConfig search in the current directory. Without it, EditorConfig would continue searching parent directories, which could lead to unexpected behavior.
  • [*]: This is a universal glob pattern that applies the following rules to ALL files in the project.
  • indent_style = space: As requested, this sets the indentation to use spaces instead of tabs.
  • indent_size = 2: As requested, this sets the indentation size to 2 spaces.
  • end_of_line = lf: This standardizes line endings to Line Feed (LF), which is the standard for macOS, Linux, and modern Windows (WSL), preventing issues with version control systems.
  • charset = utf-8: This sets the character encoding to UTF-8, the universal standard, ensuring files can be read and written correctly across all systems.
  • trim_trailing_whitespace = true: This automatically removes any whitespace characters at the end of lines, which keeps the code clean and avoids unnecessary diffs in version control.
  • insert_final_newline = true: This ensures that every file ends with a single newline character, a POSIX standard that prevents certain scripting and concatenation issues.
  • [*.md]: This glob pattern applies specific rules only to Markdown files.
  • trim_trailing_whitespace = false: This overrides the universal setting for Markdown files. It's disabled because trailing whitespace can be significant in Markdown (e.g., for creating hard line breaks).
常见问题

什么是 .editorconfig 文件?

它是一个配置文件,用来定义代码风格标准,比如缩进和换行符,这样无论开发者使用哪种编辑器,都能使用相同的格式。

为什么要使用 .editorconfig?

它有助于保持代码整洁、有序、风格统一,减少冲突,方便程序员之间协作。

.editorconfig 文件应该放在哪里?

通常放在项目的根目录下。

详情

作者的原始描述

Generates a comprehensive and best-practice-oriented .editorconfig file based on project analysis and user preferences.

repo: github/awesome-copilot

热度

GitHub 星标
40k
排名
#7185
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能