Skip to content

Disable usage analyzers by default, enable via editorconfig#214

Merged
andrewlock merged 11 commits intomainfrom
copilot/disable-usage-analyzers-default
Jan 3, 2026
Merged

Disable usage analyzers by default, enable via editorconfig#214
andrewlock merged 11 commits intomainfrom
copilot/disable-usage-analyzers-default

Conversation

Copy link
Contributor

Copilot AI commented Jan 3, 2026

Usage analyzers now require explicit opt-in via .editorconfig to reduce noise for users who don't use the generated extension methods.

Changes

  • Config key: netescapades.enumgenerators.usage_analyzers.enable = true

    • Default: disabled (analyzers don't run)
    • Applies to: all 8 usage analyzers (ToString, IsDefined, HasFlag, Parse, TryParse, GetValues, GetNames, GetValuesAsUnderlyingType)
    • Does not affect: definition analyzers (DuplicateEnumValue, DuplicateExtensionClass, EnumInGenericType)
  • Implementation: Added UsageAnalyzerConfig.IsEnabled() check at RegisterCompilationStartAction in each usage analyzer

  • Intellisense: Shared DiagnosticDescriptor (NEEGCONFIG001) added to SupportedDiagnostics for editorconfig autocomplete

Usage

Add to .editorconfig:

is_global = true
netescapades.enumgenerators.usage_analyzers.enable = true

Without this setting, usage analyzers are silent. Definition analyzers always run.

Original prompt

This section details on the original issue you should resolve

<issue_title>Disable all usage analyzers by default, and allow enabling via editorconfig</issue_title>
<issue_description>1. We should disable all the "usage" analyzers by default, making them opt-in via editorconfig, using the switch:

netescapades_enumgenerators.usage_analyzers.enable = true
  1. We should then update all the existing usage analyzers to check for this analyzer config option, and to no-op bail-out in the RegisterCompilationStartAction if the key is not present or is not true (parsed as a bool).
  2. We should update all our existing analyzer tests to set this property by default, so that the existing tests pass.
  3. We should add additional tests where this property is not set, or is set to false, to confirm the analyzers are bailing out as expected.
  4. We should add intellisense for the switch by creating a shared DiagnosticDescriptor, and returning it in each of the SupportedDiagnostics for affected analyzers.
  5. The "Definition" analyzers should not be affected by this flag - we want those to always run and be enabled</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits January 3, 2026 12:30
Co-authored-by: andrewlock <18755388+andrewlock@users.noreply.github.com>
…tests

Co-authored-by: andrewlock <18755388+andrewlock@users.noreply.github.com>
Co-authored-by: andrewlock <18755388+andrewlock@users.noreply.github.com>
Co-authored-by: andrewlock <18755388+andrewlock@users.noreply.github.com>
Copilot AI changed the title [WIP] Disable all usage analyzers by default and enable via editorconfig Disable usage analyzers by default, enable via editorconfig Jan 3, 2026
Copilot AI requested a review from andrewlock January 3, 2026 13:01
@github-actions
Copy link

github-actions bot commented Jan 3, 2026

Test Results

    180 files  ±  0      180 suites  ±0   5h 1m 45s ⏱️ - 22m 34s
 21 857 tests + 16   21 853 ✅ + 16   4 💤 ±0  0 ❌ ±0 
389 568 runs  +288  389 496 ✅ +288  72 💤 ±0  0 ❌ ±0 

Results for commit 8b4a25a. ± Comparison against base commit a17549f.

♻️ This comment has been updated with latest results.

@andrewlock andrewlock marked this pull request as ready for review January 3, 2026 20:46
@andrewlock andrewlock requested a review from Copilot January 3, 2026 20:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request implements an opt-in mechanism for usage analyzers in the NetEscapades.EnumGenerators library. By default, all 8 usage analyzers are now disabled and must be explicitly enabled via an .editorconfig setting to reduce noise for users who don't utilize the generated extension methods.

Key Changes

  • Added a new configuration system via UsageAnalyzerConfig class that checks for the netescapades.enumgenerators.usage_analyzers.enable editorconfig key
  • Updated all 8 usage analyzers (ToString, IsDefined, HasFlag, Parse, TryParse, GetValues, GetNames, GetValuesAsUnderlyingType) to check this configuration at startup
  • Refactored test infrastructure by introducing a shared AnalyzerTestsBase class to centralize test helper methods and configuration management

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/NetEscapades.EnumGenerators/Diagnostics/UsageAnalyzers/UsageAnalyzerConfig.cs New configuration class that defines the enable key and provides IsEnabled check method; includes a DiagnosticDescriptor for IntelliSense support
src/NetEscapades.EnumGenerators/Diagnostics/UsageAnalyzers/TryParseAnalyzer.cs Added config check in RegisterCompilationStartAction and ConfigDescriptor to SupportedDiagnostics
src/NetEscapades.EnumGenerators/Diagnostics/UsageAnalyzers/ToStringAnalyzer.cs Added config check in RegisterCompilationStartAction and ConfigDescriptor to SupportedDiagnostics
src/NetEscapades.EnumGenerators/Diagnostics/UsageAnalyzers/ParseAnalyzer.cs Added config check in RegisterCompilationStartAction and ConfigDescriptor to SupportedDiagnostics
src/NetEscapades.EnumGenerators/Diagnostics/UsageAnalyzers/IsDefinedAnalyzer.cs Added config check in RegisterCompilationStartAction and ConfigDescriptor to SupportedDiagnostics
src/NetEscapades.EnumGenerators/Diagnostics/UsageAnalyzers/HasFlagAnalyzer.cs Added config check in RegisterCompilationStartAction and ConfigDescriptor to SupportedDiagnostics
src/NetEscapades.EnumGenerators/Diagnostics/UsageAnalyzers/GetValuesAsUnderlyingTypeAnalyzer.cs Added config check in RegisterCompilationStartAction and ConfigDescriptor to SupportedDiagnostics
src/NetEscapades.EnumGenerators/Diagnostics/UsageAnalyzers/GetValuesAnalyzer.cs Added config check in RegisterCompilationStartAction and ConfigDescriptor to SupportedDiagnostics
src/NetEscapades.EnumGenerators/Diagnostics/UsageAnalyzers/GetNamesAnalyzer.cs Added config check in RegisterCompilationStartAction and ConfigDescriptor to SupportedDiagnostics
tests/NetEscapades.EnumGenerators.Tests/AnalyzerTestsBase.cs New base class for analyzer tests providing helper methods for verification with different assembly configurations and enabling/disabling the usage analyzers
tests/NetEscapades.EnumGenerators.Tests/TryParseAnalyzerTests.cs Refactored to inherit from AnalyzerTestsBase; removed duplicate test helper methods; added tests for Missing and Disabled config states
tests/NetEscapades.EnumGenerators.Tests/ToStringAnalyzerTests.cs Refactored to inherit from AnalyzerTestsBase; removed duplicate test helper methods; added tests for Missing and Disabled config states
tests/NetEscapades.EnumGenerators.Tests/ParseAnalyzerTests.cs Refactored to inherit from AnalyzerTestsBase; removed duplicate test helper methods; added tests for Missing and Disabled config states
tests/NetEscapades.EnumGenerators.Tests/IsDefinedAnalyzerTests.cs Refactored to inherit from AnalyzerTestsBase; removed duplicate test helper methods; added tests for Missing and Disabled config states
tests/NetEscapades.EnumGenerators.Tests/HasFlagAnalyzerTests.cs Refactored to inherit from AnalyzerTestsBase; removed duplicate test helper methods; added tests for Missing and Disabled config states
tests/NetEscapades.EnumGenerators.Tests/GetValuesAsUnderlyingTypeAnalyzerTests.cs Refactored to inherit from AnalyzerTestsBase; removed duplicate test helper methods; added tests for Missing and Disabled config states
tests/NetEscapades.EnumGenerators.Tests/GetValuesAnalyzerTests.cs Refactored to inherit from AnalyzerTestsBase; removed duplicate test helper methods; added tests for Missing and Disabled config states
tests/NetEscapades.EnumGenerators.Tests/GetNamesAnalyzerTests.cs Refactored to inherit from AnalyzerTestsBase; removed duplicate test helper methods; added tests for Missing and Disabled config states
tests/NetEscapades.EnumGenerators.IntegrationTests/.globalconfig New global config file enabling usage analyzers for integration tests
tests/NetEscapades.EnumGenerators.IntegrationTests/AnalyzerTests.cs Added nullable annotation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Owner

@andrewlock andrewlock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required fixing a bunch of things myself, but looked good enough, after making a bunch of improvements (mostly extracting common code)

@andrewlock andrewlock merged commit 67e6c5f into main Jan 3, 2026
5 checks passed
@andrewlock andrewlock deleted the copilot/disable-usage-analyzers-default branch January 3, 2026 22:50
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.

Disable all usage analyzers by default, and allow enabling via editorconfig

3 participants