Implement CT0003 rule for opinionated object initialization #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements the CT0003 analyzer rule that prevents the use of empty parentheses in object initialization when using object initializers, promoting cleaner and more consistent code style.
Rule Behavior
The new CT0003 rule flags object creation expressions that use empty parentheses followed by object initializers as a warning, encouraging developers to omit unnecessary parentheses.
❌ Flagged (triggers CT0003):
✅ Allowed:
Implementation Details
ObjectInitializationAnalyzerdetectsObjectCreationExpressionSyntaxnodes with empty argument lists and object initializersTesting
Added comprehensive test coverage with 7 test cases covering:
List<T>(should trigger when applicable)All existing tests continue to pass (26/26), ensuring no regressions in CT0001 and CT0002 rules.
Documentation
Updated README.md to include documentation for all three rules (CT0001, CT0002, CT0003) with clear examples of allowed and disallowed patterns.
Fixes #5.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.