Skip to content

Commit 1aff55f

Browse files
authored
Mention globalconfig in the docs, and tweak the detection for consistency (#224)
* Add globalconfig for Rider (it doesn't seem to work otherwise) * Make bool check consistent with other checks * Tweak README
1 parent a8f3003 commit 1aff55f

4 files changed

Lines changed: 17 additions & 12 deletions

File tree

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,14 @@ You can override the name of the extension class by setting `ExtensionClassName`
283283

284284
_NetEscapades.EnumGenerators_ includes optional analyzers that encourage the use of the generated extension methods instead of the built-in `System.Enum` methods. These analyzers can help improve performance by suggesting the faster, generated, alternatives like `ToStringFast()`, `HasFlagFast()`, and `TryParse()`.
285285

286-
### Enabling the analyzers
286+
Alternatively, [add a `.globalconfig` file](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/configuration-files#global-analyzerconfig) to your project with the following content:
287287

288-
The usage analyzers are disabled by default. To enable them, set the `EnumGenerator_EnableUsageAnalyzers` MSBuild property to `true` in your project:
289-
290-
```xml
291-
<PropertyGroup>
292-
<EnumGenerator_EnableUsageAnalyzers>true</EnumGenerator_EnableUsageAnalyzers>
293-
</PropertyGroup>
288+
```ini
289+
is_global = true
290+
build_property.EnumGenerator_EnableUsageAnalyzers = true
294291
```
295292

296-
After adding this configuration, the analyzers in your project should be enabled with the default severity of `Warning`.
293+
After using one of these configuration options, the analyzers in your project should be enabled with the default severity of `Warning`.
297294

298295
### Configuring analyzer severity (optional)
299296

src/NetEscapades.EnumGenerators/Diagnostics/UsageAnalyzers/UsageAnalyzerConfig.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public static class UsageAnalyzerConfig
99
public const string EnableKey = "build_property.EnumGenerator_EnableUsageAnalyzers";
1010

1111
internal static bool IsEnabled(AnalyzerOptions context)
12-
=> context.AnalyzerConfigOptionsProvider.GlobalOptions.TryGetValue(EnableKey, out var value) &&
13-
bool.TryParse(value, out var isEnabled)
14-
&& isEnabled;
12+
=> context.AnalyzerConfigOptionsProvider.GlobalOptions.TryGetValue(EnableKey, out var value)
13+
&& string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
1514
}

src/NetEscapades.EnumGenerators/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,14 @@ The usage analyzers are disabled by default. To enable them, set the `EnumGenera
314314
</PropertyGroup>
315315
```
316316

317-
After adding this configuration, the analyzers in your project should be enabled with the default severity of `Warning`.
317+
Alternatively, [add a `.globalconfig` file](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/configuration-files#global-analyzerconfig) to your project with the following content:
318+
319+
```ini
320+
is_global = true
321+
build_property.EnumGenerator_EnableUsageAnalyzers = true
322+
```
323+
324+
After using one of these configuration options, the analyzers in your project should be enabled with the default severity of `Warning`.
318325

319326
### Configuring analyzer severity (optional)
320327

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
is_global = true
2+
build_property.EnumGenerator_EnableUsageAnalyzers = true

0 commit comments

Comments
 (0)