Skip to content

Fix duplicate warnings for ATC220 and ATC221 - #13

Merged
davidkallesen merged 1 commit into
mainfrom
feature/Fix-double-for-ATC220-and-ATC221
Apr 1, 2026
Merged

davidkallesen merged 1 commit into
mainfrom
feature/Fix-double-for-ATC220-and-ATC221

Conversation

@davidkallesen

@davidkallesen davidkallesen commented Apr 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When both ATC220 and ATC221 are enabled (both default to enabled), a single using directive like using System; produces two warnings — one from each rule. This PR makes the rules complementary by having ATC220 automatically exclude namespaces that ATC221 handles, so each using directive triggers at most one warning.

A new .editorconfig option dotnet_diagnostic.ATC220.exclude_common_namespaces (default: true) controls this behavior. ATC220 reads ATC221's namespace_prefixes to determine which namespaces to skip, keeping the two rules in sync even with custom prefix configurations.

Changes

✨ Features

  • Add exclude_common_namespaces option to ATC220 (default: true) that defers System/Microsoft/Atc namespaces to ATC221
  • ATC220 reads ATC221's namespace_prefixes configuration to stay in sync with custom prefixes
  • Add GetExcludeCommonNamespaces helper to AnalyzerConfigOptionsExtensions

♻️ Refactoring

  • Update sample apps to remove unnecessary #pragma warning disable directives now that rules don't overlap
  • Update existing ATC220 tests to explicitly set exclude_common_namespaces = false where testing core "flag everything" behavior
  • Add new tests for default exclusion behavior and opt-out scenario

📝 Documentation

  • Replace "recommended to enable only one" guidance with "Working Together" section in ATC220.md and ATC221.md
  • Document the new exclude_common_namespaces configuration option with behavior matrix
  • Update CLAUDE.md with automatic mutual exclusivity details

Notes

  • Setting exclude_common_namespaces = false restores the original ATC220 behavior (flags all namespaces)
  • If ATC221 is disabled and you want ATC220 to cover everything, set exclude_common_namespaces = false in .editorconfig

… warnings with ATC221

  - Add exclude_common_namespaces option to ATC220 (default: true)
  - ATC220 reads ATC221's namespace_prefixes to skip common namespaces
  - Update tests to cover both default exclusion and explicit opt-out
  - Update sample apps to reflect new complementary behavior
  - Update ATC220/ATC221 docs and CLAUDE.md with configuration details
@davidkallesen
davidkallesen force-pushed the feature/Fix-double-for-ATC220-and-ATC221 branch from 8034a3f to 788934e Compare April 1, 2026 12:21
@davidkallesen
davidkallesen merged commit a59d070 into main Apr 1, 2026
4 checks passed
@davidkallesen
davidkallesen deleted the feature/Fix-double-for-ATC220-and-ATC221 branch April 1, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant