Skip to content

Change @SafeDIConfiguration to #SafeDIConfiguration freestanding macro#227

Merged
dfed merged 9 commits intomainfrom
dfed--freestanding-macro
Apr 7, 2026
Merged

Change @SafeDIConfiguration to #SafeDIConfiguration freestanding macro#227
dfed merged 9 commits intomainfrom
dfed--freestanding-macro

Conversation

@dfed
Copy link
Copy Markdown
Owner

@dfed dfed commented Apr 7, 2026

Summary

  • Replace @SafeDIConfiguration (attached peer macro decorating an enum) with #SafeDIConfiguration(...) (freestanding declaration macro with defaulted parameters)
  • Improves library evolution: adding new configuration parameters is non-source-breaking since all parameters have defaults
  • Improves ergonomics: #SafeDIConfiguration() replaces a multi-line enum declaration
  • Must appear at the top level of a Swift file (not nested inside a type)

Test plan

  • All 763 existing tests pass
  • SwiftFormat lint passes
  • New macro tests cover: no arguments, all arguments, empty arrays, nil/custom mockConditionalCompilation, multiple values, single argument
  • Error tests cover: non-literal values, string interpolation for all argument types
  • FileVisitor tests cover: configuration extraction, no-arguments, empty arrays, non-literal values, alongside @INSTANTIABLE, nested inside type (ignored)
  • SafeDIConfigurationVisitor tests cover: correct values, defaults, nil, non-literal fallback, unlabeled arguments
  • RootScanner text-based scanner tests updated for #SafeDIConfiguration(...) argument extraction
  • SafeDITool integration tests with configuration (mock conditional compilation, additional directories, additional imports)
  • Documentation updated (Manual.md, README.md, CLAUDE.md)

🤖 Generated with Claude Code

Replace the attached peer macro `@SafeDIConfiguration` (which decorated an
enum with required properties) with a freestanding declaration macro
`#SafeDIConfiguration(...)` that takes parameters with default values.

This improves library evolution (adding new parameters is non-breaking) and
ergonomics (no enum boilerplate needed). The simplest valid invocation is
now just `#SafeDIConfiguration()`.

Key changes:
- Public API: `@freestanding(declaration)` macro with defaulted parameters
- Macro impl: `DeclarationMacro` validates literal arguments
- SafeDIConfigurationVisitor: now an enum with static extraction method
- FileVisitor: handles both MacroExpansionDeclSyntax and MacroExpansionExprSyntax
- RootScanner: text-based scanning updated for `#` prefix and argument list
- Delete FixableSafeDIConfigurationError (fix-its no longer needed)
- Update migration plugin, examples, all tests, and documentation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (28d2cd0) to head (4fd44af).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              main      #227    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           40        39     -1     
  Lines         6143      6015   -128     
==========================================
- Hits          6143      6015   -128     
Files with missing lines Coverage Δ
...ensions/AttributeListSyntaxElementExtensions.swift 100.00% <ø> (ø)
...ore/Extensions/AttributeListSyntaxExtensions.swift 100.00% <ø> (ø)
Sources/SafeDICore/Models/SafeDIToolManifest.swift 100.00% <ø> (ø)
Sources/SafeDICore/Visitors/FileVisitor.swift 100.00% <100.00%> (ø)
...feDICore/Visitors/SafeDIConfigurationVisitor.swift 100.00% <100.00%> (ø)
...SafeDIMacros/Macros/SafeDIConfigurationMacro.swift 100.00% <100.00%> (ø)
Sources/SafeDIRootScannerCore/RootScanner.swift 100.00% <100.00%> (ø)
Sources/SafeDITool/SafeDITool.swift 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Add macro tests for unlabeled and unknown argument errors
- Add visitor tests for unknown labels and interpolated string literals
- Remove dead MacroExpansionDeclSyntax path in FileVisitor (parser always
  produces MacroExpansionExprSyntax for freestanding macros)
- Remove unreachable loop in RootScanner that skipped between label and colon
- All changed files now at 100% line coverage

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dfed and others added 7 commits April 7, 2026 07:53
Use if/else if/else expression instead of sequential bare if statements
with early returns, matching the project's code style rules.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dfed dfed self-assigned this Apr 7, 2026
@dfed dfed marked this pull request as ready for review April 7, 2026 16:48
@dfed dfed merged commit 1ef8be8 into main Apr 7, 2026
19 checks passed
@dfed dfed deleted the dfed--freestanding-macro branch April 7, 2026 17:10
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