format

GitHub

基于 .NET SDK 的 dotnet format 命令,用于格式化或验证代码风格、空白及分析器修复。支持只读检查与变更应用,严格遵循 .editorconfig 配置,确保不破坏现有更改并维持仓库格式规范一致性。

catalog/Tools/Format/skills/format/SKILL.md managedcode/dotnet-skills

触发场景

需要格式化 .NET 代码以符合 .editorconfig 规则 使用 --verify-no-changes 进行 CI 门禁或代码风格合规性检查 诊断 formatter 作用域或加载失败问题

安装

npx skills add managedcode/dotnet-skills --skill format -g -y
更多选项

非标准路径

npx skills add https://github.com/managedcode/dotnet-skills/tree/main/catalog/Tools/Format/skills/format -g -y

不安装直接使用

npx skills use managedcode/dotnet-skills@format

指定 Agent (Claude Code)

npx skills add managedcode/dotnet-skills --skill format -a claude-code -g -y

安装 repo 全部 skill

npx skills add managedcode/dotnet-skills --all -g -y

预览 repo 内 skill

npx skills add managedcode/dotnet-skills --list

SKILL.md

Frontmatter
{
    "name": "format",
    "description": "Format or verify trusted .NET projects with the SDK-provided `dotnet format` command. USE FOR: applying or checking `.editorconfig`-driven whitespace, code-style, or analyzer fixes; adding a `--verify-no-changes` CI gate; diagnosing formatter scope or load failures. DO NOT USE FOR: repositories where another formatter exclusively owns the affected files; analyzer policy with no formatter work; mutating files when the user requested only diagnosis."
}

dotnet format

Use the formatter already shipped with the selected .NET SDK. Preserve the repository's formatter ownership, existing changes, and configured style instead of introducing new preferences.

Workflow

  1. Read the nearest AGENTS.md, global.json, solution/project files, .editorconfig, and current Git status.
  2. Confirm the exact trusted workspace to load. dotnet format may restore, compile, and run analyzers from that workspace.
  3. Determine whether the request is read-only verification or permission to apply fixes. Do not run a mutating command for a review, explanation, or diagnosis request.
  4. Preserve the current diff before formatting. When scope is uncertain, begin with --verify-no-changes or a narrow --include list.
  5. Choose the smallest formatter surface that matches the request:
    • whitespace for indentation, spacing, and line-ending rules;
    • style for built-in .NET code-style diagnostics;
    • analyzers for fixable non-style analyzer diagnostics;
    • the command without a subcommand only when all applicable surfaces are intended.
  6. Treat --include and --exclude values as workspace-relative file or directory paths, not shell globs. Use --diagnostics to narrow style or analyzer fixes by rule ID.
  7. After a mutating run, inspect git diff --stat, representative diffs, line endings, and every changed file. If scope is unexpectedly broad, stop and narrow the command; never discard pre-existing user changes.
  8. Rerun the matching command with --verify-no-changes. When analyzer fixes were applied, also build and run the tests relevant to the changed behavior.

Invariants

  • .editorconfig and existing MSBuild analyzer configuration are the source of truth. Do not add an arbitrary style template unless the user asks for one.
  • Use --no-restore only after dependencies have already been restored successfully.
  • Generated files stay excluded unless the repository explicitly owns and formats them.
  • A successful formatter process does not prove that every diagnostic has an automatic fix. Review its output or JSON report and use build/analyzer results as the final evidence.
  • Keep formatter responsibilities explicit when CSharpier, ReSharper cleanup, generated-code tools, or other formatters coexist.

References

版本历史

  • 6cd8621 当前 2026-09-03 08:02

    重构技能结构,移除旧版 Ralph Loop 和 Bootstrap 逻辑,增强对 .editorconfig 和工作区范围的精确控制,明确只读与修改模式边界。

  • 7ab7f03 2026-07-25 05:26

同 Skill 集合

catalog/Frameworks/gRPC/skills/grpc/SKILL.md
catalog/Frameworks/Official-Astro/skills/astro-developer/SKILL.md
catalog/Frameworks/Official-DotNet-ASPNetCore/skills/configuring-opentelemetry-dotnet/SKILL.md
catalog/Frameworks/Official-DotNet-ASPNetCore/skills/dotnet-webapi/SKILL.md
catalog/Frameworks/Official-DotNet-ASPNetCore/skills/minimal-api-file-upload/SKILL.md
catalog/Frameworks/Orleans/skills/orleans/SKILL.md
catalog/Frameworks/ThreeJS-WebGPU-TSL/skills/webgpu-threejs-tsl/SKILL.md
catalog/Libraries/ManagedCode-Orleans-SignalR/skills/managedcode-orleans-signalr/SKILL.md
catalog/Libraries/Official-DotNet-Data/skills/optimizing-ef-core-queries/SKILL.md
catalog/Platform/Official-DotNet-Advanced/skills/csharp-scripts/SKILL.md
catalog/Platform/Official-DotNet-Advanced/skills/nuget-trusted-publishing/SKILL.md
catalog/Platform/Official-DotNet-Advanced/skills/vectorization/SKILL.md
catalog/Platform/Official-DotNet-Blazor/skills/create-blazor-project/SKILL.md
catalog/Platform/Official-DotNet-Blazor/skills/fetch-and-send-data/SKILL.md
catalog/Platform/Official-DotNet-Blazor/skills/support-prerendering/SKILL.md
catalog/Platform/Official-DotNet-Blazor/skills/use-js-interop/SKILL.md
catalog/Platform/Official-DotNet-Experimental/skills/exp-mock-usage-analysis/SKILL.md
catalog/Platform/Official-DotNet-Experimental/skills/exp-simd-vectorization/SKILL.md
catalog/Platform/Official-DotNet-Upgrade/skills/dotnet-aot-compat/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/code-testing-extensions/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/crap-score/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/filter-syntax/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/find-untested-sources/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/test-tagging/SKILL.md
catalog/Testing/Playwright/skills/playwright-visual-testing/SKILL.md
catalog/Testing/TUnit/skills/tunit/SKILL.md
catalog/Testing/xUnit/skills/xunit/SKILL.md
catalog/Tools/Code-Analysis/skills/code-analysis/SKILL.md
catalog/Tools/HTMLHint/skills/htmlhint/SKILL.md
catalog/Tools/Official-DotNet-Diagnostics/skills/analyzing-dotnet-performance/SKILL.md
catalog/Tools/Official-DotNet-Diagnostics/skills/clr-activation-debugging/SKILL.md
catalog/Tools/Official-DotNet-Diagnostics/skills/dotnet-trace-collect/SKILL.md
catalog/Tools/Official-DotNet-Diagnostics/skills/dump-collect/SKILL.md
catalog/Tools/Official-DotNet-MSBuild/skills/binlog-failure-analysis/SKILL.md
catalog/Tools/Official-DotNet-MSBuild/skills/copy-to-output-directory/SKILL.md
catalog/Tools/Official-DotNet-MSBuild/skills/msbuild-server/SKILL.md
catalog/Tools/Official-DotNet-MSBuild/skills/resolve-project-references/SKILL.md
catalog/Tools/ReportGenerator/skills/reportgenerator/SKILL.md
catalog/Tools/ReSharper-CLT/skills/resharper-clt/SKILL.md
catalog/Tools/Roslynator/skills/roslynator/SKILL.md
catalog/Tools/Stylelint/skills/stylelint/SKILL.md
external-sources/upstreams/webgpu-claude-skill/skills/webgpu-threejs-tsl/SKILL.md
catalog/Frameworks/ASP.NET-Core/skills/aspnet-core/SKILL.md
catalog/Frameworks/Aspire/skills/aspire/SKILL.md
catalog/Frameworks/Azure-Functions/skills/azure-functions/SKILL.md
catalog/Frameworks/Blazor/skills/blazor/SKILL.md
catalog/Frameworks/Entity-Framework-6/skills/entity-framework6/SKILL.md
catalog/Frameworks/Entity-Framework-Core/skills/entity-framework-core/SKILL.md
catalog/Frameworks/MAUI/skills/maui/SKILL.md

元信息

文件数
0
版本
d26ba3c
Hash
91c36409
收录时间
2026-07-25 05:26

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-09 20:35
浙ICP备14020137号-1 $访客地图$