Skip to content

Commit

Permalink
MA0104 only considers public types by default
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou committed Nov 13, 2023
1 parent 1276cbb commit c336ad4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/Rules/MA0104.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ public class String // MA0104
}
````

You can configure the types / namespaces to consider in the `editorconfig` file
You can configure the types / namespaces to consider in the `.editorconfig` file

````
MA0104.namespaces_regex = ^System($|\.)
MA0104.use_preview_types = true # use types from preview versions of .NET
````

By default the rule only applies to public types. Add the following line to the `.editorconfig` file to consider all types:

````
MA0104.only_consider_public_symbols = false
````
6 changes: 6 additions & 0 deletions src/Meziantou.Analyzer/Rules/DotNotUseNameFromBCLAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context)
if (symbol.ContainingType != null)
return; // Do not consider nested types

if (!symbol.IsVisibleOutsideOfAssembly())
{
if (context.Options.GetConfigurationValue(symbol, RuleIdentifiers.DotNotUseNameFromBCL + ".only_consider_public_symbols", defaultValue: true))
return;
}

var usePreviewTypes = context.Options.GetConfigurationValue(symbol, RuleIdentifiers.DotNotUseNameFromBCL + ".use_preview_types", defaultValue: false);
var types = usePreviewTypes ? s_typesPreview : s_types;
if (types!.TryGetValue(symbol.MetadataName, out var namespaces))
Expand Down

0 comments on commit c336ad4

Please sign in to comment.