Skip to content

MA0099: add opt-in configuration options for report location and zero-member filtering#1215

Merged
meziantou merged 1 commit into
mainfrom
meziantou-fix-ma0099-no-zero-enum-value
Jul 4, 2026
Merged

MA0099: add opt-in configuration options for report location and zero-member filtering#1215
meziantou merged 1 commit into
mainfrom
meziantou-fix-ma0099-no-zero-enum-value

Conversation

@meziantou

Copy link
Copy Markdown
Owner

Closes #1210

Changes

Added two opt-in editorconfig options for MA0099 (DoNotUseZeroToInitializeAnEnumValue):

MA0099.exclude_enum_without_zero_member (bool, default false)

When set to true, the diagnostic is suppressed when the target enum has no named member with value 0 — i.e., there is no named value the user could use instead.

[*.cs]
MA0099.exclude_enum_without_zero_member = true

MA0099.report_on (string, default all)

When set to argument, the diagnostic is only reported when the zero literal appears as a method or constructor argument. This is the location where accidental overload selection is the primary risk.

[*.cs]
MA0099.report_on = argument

Both options can be used independently or together. Default behavior is unchanged.

…-member filtering

- Add MA0099.exclude_enum_without_zero_member (bool, default false): when true,
  skip the diagnostic when the target enum has no named member with value 0
- Add MA0099.report_on (string, default 'all'): when set to 'argument', only
  report the diagnostic when the zero literal appears as a method/constructor
  argument (where accidental overload selection is the primary risk)
- Add tests for both new options
- Update docs/Rules/MA0099.md to document the new configuration options

Closes #1210

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@meziantou
meziantou merged commit bb26f89 into main Jul 4, 2026
13 checks passed
@meziantou
meziantou deleted the meziantou-fix-ma0099-no-zero-enum-value branch July 4, 2026 20:31
This was referenced Jul 4, 2026
This was referenced Jul 14, 2026
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.

MA0099 shouldn't fire if the enum doesn't have a 0 value available for use.

1 participant