Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #7008 Make AnalyzerOptionsExtensions to have public modifier instead of internal #7085

Merged
merged 5 commits into from
Jan 16, 2024

Conversation

eriawan
Copy link
Member

@eriawan eriawan commented Dec 9, 2023

Fixes #7008

Make AnalyzerOptionsExtensions to have public modifier instead of internal

@eriawan
Copy link
Member Author

eriawan commented Dec 9, 2023

@mavasani

After I compiled on my local, I got some errors that says some objects need to be modified to be public:

\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(39,45): error CS0050: Inconsistent accessibility: return type 'SymbolVisibilityGroup' is less accessible than method 'AnalyzerOptionsExtensions
.GetSymbolVisibilityGroupOption(AnalyzerOptions, DiagnosticDescriptor, ISymbol, Compilation, SymbolVisibilityGroup)' [\roslyn-analyzers\src\PerformanceSensitiveAnalyzers\Core\Microsoft.CodeAnalysis.PerformanceSensitiveAna
lyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(39,45): error CS0051: Inconsistent accessibility: parameter type 'SymbolVisibilityGroup' is less accessible than method 'AnalyzerOptionsExtensi
ons.GetSymbolVisibilityGroupOption(AnalyzerOptions, DiagnosticDescriptor, ISymbol, Compilation, SymbolVisibilityGroup)' [\roslyn-analyzers\src\PerformanceSensitiveAnalyzers\Core\Microsoft.CodeAnalysis.PerformanceSensitive
Analyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(75,47): error CS0050: Inconsistent accessibility: return type 'EnumValuesPrefixTrigger' is less accessible than method 'AnalyzerOptionsExtensio
ns.GetEnumValuesPrefixTriggerOption(AnalyzerOptions, DiagnosticDescriptor, ISymbol, Compilation, EnumValuesPrefixTrigger)' [\roslyn-analyzers\src\PerformanceSensitiveAnalyzers\Core\Microsoft.CodeAnalysis.PerformanceSensit
iveAnalyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(75,47): error CS0051: Inconsistent accessibility: parameter type 'EnumValuesPrefixTrigger' is less accessible than method 'AnalyzerOptionsExten
sions.GetEnumValuesPrefixTriggerOption(AnalyzerOptions, DiagnosticDescriptor, ISymbol, Compilation, EnumValuesPrefixTrigger)' [\roslyn-analyzers\src\PerformanceSensitiveAnalyzers\Core\Microsoft.CodeAnalysis.PerformanceSen
sitiveAnalyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(231,56): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<Unit>' is less accessible than method 'AnalyzerOptio
nsExtensions.GetNullCheckValidationMethodsOption(AnalyzerOptions, DiagnosticDescriptor, SyntaxTree, Compilation)' [\roslyn-analyzers\src\PerformanceSensitiveAnalyzers\Core\Microsoft.CodeAnalysis.PerformanceSensitiveAnalyz
ers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(238,56): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<Unit>' is less accessible than method 'AnalyzerOptio
nsExtensions.GetAdditionalStringFormattingMethodsOption(AnalyzerOptions, DiagnosticDescriptor, SyntaxTree, Compilation)' [\roslyn-analyzers\src\PerformanceSensitiveAnalyzers\Core\Microsoft.CodeAnalysis.PerformanceSensitiv
eAnalyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(308,56): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<Unit>' is less accessible than method 'AnalyzerOptio
nsExtensions.GetDisallowedSymbolNamesWithValueOption(AnalyzerOptions, DiagnosticDescriptor, ISymbol, Compilation)' [\roslyn-analyzers\src\PerformanceSensitiveAnalyzers\Core\Microsoft.CodeAnalysis.PerformanceSensitiveAnaly
zers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(322,59): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<string?>' is less accessible than method 'AnalyzerOp
tionsExtensions.GetAdditionalRequiredSuffixesOption(AnalyzerOptions, DiagnosticDescriptor, ISymbol, Compilation)' [\roslyn-analyzers\src\PerformanceSensitiveAnalyzers\Core\Microsoft.CodeAnalysis.PerformanceSensitiveAnalyz
ers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(371,69): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<INamedTypeSymbol?>' is less accessible than method '
AnalyzerOptionsExtensions.GetAdditionalRequiredGenericInterfaces(AnalyzerOptions, DiagnosticDescriptor, ISymbol, Compilation)' [\roslyn-analyzers\src\PerformanceSensitiveAnalyzers\Core\Microsoft.CodeAnalysis.PerformanceSe
nsitiveAnalyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(417,56): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<Unit>' is less accessible than method 'AnalyzerOptio
nsExtensions.GetInheritanceExcludedSymbolNamesOption(AnalyzerOptions, DiagnosticDescriptor, SyntaxTree, Compilation, string)' [\roslyn-analyzers\src\PerformanceSensitiveAnalyzers\Core\Microsoft.CodeAnalysis.PerformanceSen
sitiveAnalyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(425,56): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<Unit>' is less accessible than method 'AnalyzerOptio
nsExtensions.GetAdditionalUseResultsMethodsOption(AnalyzerOptions, DiagnosticDescriptor, SyntaxTree, Compilation)' [\roslyn-analyzers\src\PerformanceSensitiveAnalyzers\Core\Microsoft.CodeAnalysis.PerformanceSensitiveAnaly
zers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(432,56): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<Unit>' is less accessible than method 'AnalyzerOptio
nsExtensions.GetEnumerationMethodsOption(AnalyzerOptions, DiagnosticDescriptor, SyntaxTree, Compilation)' [\roslyn-analyzers\src\PerformanceSensitiveAnalyzers\Core\Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.cspr
oj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(439,56): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<Unit>' is less accessible than method 'AnalyzerOptio
nsExtensions.GetLinqChainMethodsOption(AnalyzerOptions, DiagnosticDescriptor, SyntaxTree, Compilation)' [\roslyn-analyzers\src\PerformanceSensitiveAnalyzers\Core\Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.csproj
]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(569,28): error CS0051: Inconsistent accessibility: parameter type 'SymbolVisibilityGroup' is less accessible than method 'AnalyzerOptionsExtens
ions.MatchesConfiguredVisibility(AnalyzerOptions, DiagnosticDescriptor, ISymbol, Compilation, SymbolVisibilityGroup)' [\roslyn-analyzers\src\PerformanceSensitiveAnalyzers\Core\Microsoft.CodeAnalysis.PerformanceSensitiveAn
alyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(603,28): error CS0051: Inconsistent accessibility: parameter type 'SymbolModifiers' is less accessible than method 'AnalyzerOptionsExtensions.M
atchesConfiguredModifiers(AnalyzerOptions, DiagnosticDescriptor, ISymbol, Compilation, SymbolModifiers)' [\roslyn-analyzers\src\PerformanceSensitiveAnalyzers\Core\Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers.cspro
j]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(39,45): error CS0050: Inconsistent accessibility: return type 'SymbolVisibilityGroup' is less accessible than method 'AnalyzerOptionsExtensions
.GetSymbolVisibilityGroupOption(AnalyzerOptions, DiagnosticDescriptor, ISymbol, Compilation, SymbolVisibilityGroup)' [\roslyn-analyzers\src\Roslyn.Diagnostics.Analyzers\Core\Roslyn.Diagnostics.Analyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(39,45): error CS0051: Inconsistent accessibility: parameter type 'SymbolVisibilityGroup' is less accessible than method 'AnalyzerOptionsExtensi
ons.GetSymbolVisibilityGroupOption(AnalyzerOptions, DiagnosticDescriptor, ISymbol, Compilation, SymbolVisibilityGroup)' [\roslyn-analyzers\src\Roslyn.Diagnostics.Analyzers\Core\Roslyn.Diagnostics.Analyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(75,47): error CS0050: Inconsistent accessibility: return type 'EnumValuesPrefixTrigger' is less accessible than method 'AnalyzerOptionsExtensio
ns.GetEnumValuesPrefixTriggerOption(AnalyzerOptions, DiagnosticDescriptor, ISymbol, Compilation, EnumValuesPrefixTrigger)' [\roslyn-analyzers\src\Roslyn.Diagnostics.Analyzers\Core\Roslyn.Diagnostics.Analyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(75,47): error CS0051: Inconsistent accessibility: parameter type 'EnumValuesPrefixTrigger' is less accessible than method 'AnalyzerOptionsExten
sions.GetEnumValuesPrefixTriggerOption(AnalyzerOptions, DiagnosticDescriptor, ISymbol, Compilation, EnumValuesPrefixTrigger)' [\roslyn-analyzers\src\Roslyn.Diagnostics.Analyzers\Core\Roslyn.Diagnostics.Analyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(231,56): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<Unit>' is less accessible than method 'AnalyzerOptio
nsExtensions.GetNullCheckValidationMethodsOption(AnalyzerOptions, DiagnosticDescriptor, SyntaxTree, Compilation)' [\roslyn-analyzers\src\Roslyn.Diagnostics.Analyzers\Core\Roslyn.Diagnostics.Analyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(238,56): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<Unit>' is less accessible than method 'AnalyzerOptio
nsExtensions.GetAdditionalStringFormattingMethodsOption(AnalyzerOptions, DiagnosticDescriptor, SyntaxTree, Compilation)' [\roslyn-analyzers\src\Roslyn.Diagnostics.Analyzers\Core\Roslyn.Diagnostics.Analyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(308,56): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<Unit>' is less accessible than method 'AnalyzerOptio
nsExtensions.GetDisallowedSymbolNamesWithValueOption(AnalyzerOptions, DiagnosticDescriptor, ISymbol, Compilation)' [\roslyn-analyzers\src\Roslyn.Diagnostics.Analyzers\Core\Roslyn.Diagnostics.Analyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(322,59): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<string?>' is less accessible than method 'AnalyzerOp
tionsExtensions.GetAdditionalRequiredSuffixesOption(AnalyzerOptions, DiagnosticDescriptor, ISymbol, Compilation)' [\roslyn-analyzers\src\Roslyn.Diagnostics.Analyzers\Core\Roslyn.Diagnostics.Analyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(371,69): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<INamedTypeSymbol?>' is less accessible than method '
AnalyzerOptionsExtensions.GetAdditionalRequiredGenericInterfaces(AnalyzerOptions, DiagnosticDescriptor, ISymbol, Compilation)' [\roslyn-analyzers\src\Roslyn.Diagnostics.Analyzers\Core\Roslyn.Diagnostics.Analyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(417,56): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<Unit>' is less accessible than method 'AnalyzerOptio
nsExtensions.GetInheritanceExcludedSymbolNamesOption(AnalyzerOptions, DiagnosticDescriptor, SyntaxTree, Compilation, string)' [\roslyn-analyzers\src\Roslyn.Diagnostics.Analyzers\Core\Roslyn.Diagnostics.Analyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(425,56): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<Unit>' is less accessible than method 'AnalyzerOptio
nsExtensions.GetAdditionalUseResultsMethodsOption(AnalyzerOptions, DiagnosticDescriptor, SyntaxTree, Compilation)' [\roslyn-analyzers\src\Roslyn.Diagnostics.Analyzers\Core\Roslyn.Diagnostics.Analyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(432,56): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<Unit>' is less accessible than method 'AnalyzerOptio
nsExtensions.GetEnumerationMethodsOption(AnalyzerOptions, DiagnosticDescriptor, SyntaxTree, Compilation)' [\roslyn-analyzers\src\Roslyn.Diagnostics.Analyzers\Core\Roslyn.Diagnostics.Analyzers.csproj]
\roslyn-analyzers\src\Utilities\Compiler\Options\AnalyzerOptionsExtensions.cs(439,56): error CS0050: Inconsistent accessibility: return type 'SymbolNamesWithValueOption<Unit>' is less accessible than method 'AnalyzerOptio
nsExtensions.GetLinqChainMethodsOption(AnalyzerOptions, DiagnosticDescriptor, SyntaxTree, Compilation)' [\roslyn-analyzers\src\Roslyn.Diagnostics.Analyzers\Core\Roslyn.Diagnostics.Analyzers.csproj]

Should I make SymbolVisibilityGroup, EnumValuesPrefixTrigger SymbolNamesWithValueOption<TValue> and the remaining impacted class/enums such as SymbolModifiers as public too?

@mavasani
Copy link
Contributor

Should I make SymbolVisibilityGroup, EnumValuesPrefixTrigger SymbolNamesWithValueOption and the remaining impacted class/enums such as SymbolModifiers as public too?

That sounds reasonable to me.

@eriawan
Copy link
Member Author

eriawan commented Dec 11, 2023

Should I make SymbolVisibilityGroup, EnumValuesPrefixTrigger SymbolNamesWithValueOption and the remaining impacted class/enums such as SymbolModifiers as public too?

That sounds reasonable to me.

Thanks! I will submit next commit with those types marked as public then 🙂

@eriawan
Copy link
Member Author

eriawan commented Dec 13, 2023

Done setting classes to public.

@mavasani do I have to update the PublicAPI.Unshipped.txt as well?

@eriawan eriawan force-pushed the make-AnalyzerOptionsExtensions-public branch from b134b13 to 65d287d Compare December 30, 2023 21:26
@mavasani
Copy link
Contributor

mavasani commented Jan 2, 2024

Done setting classes to public.

@mavasani do I have to update the PublicAPI.Unshipped.txt as well?

Yes, please use the code fix to add the entries to PublicAPI.Unshipped.txt

@eriawan
Copy link
Member Author

eriawan commented Jan 3, 2024

Done committing updated PublicAPI.Unshipped.txt file.
Ok, there's a merge conflict, I'm going to resolve this first.

@eriawan eriawan force-pushed the make-AnalyzerOptionsExtensions-public branch from 81126e6 to 1df41d4 Compare January 3, 2024 19:52
@eriawan
Copy link
Member Author

eriawan commented Jan 3, 2024

Done resolving merge conflict. Now it's ready to review, @mavasani
🙂

@eriawan eriawan marked this pull request as ready for review January 3, 2024 19:54
@eriawan eriawan requested a review from a team as a code owner January 3, 2024 19:54
@eriawan
Copy link
Member Author

eriawan commented Jan 3, 2024

@mavasani
Hang on, it seems there are compilation errors after resolving merge conflict, These errors are caused by conflicting names of class in the Microsoft.CodeAnalysis.NetAnalyzers and Test.Utilities.

For example: (as shown in the Azure Pipelines https://dev.azure.com/dnceng-public/public/_build/results?buildId=513774&view=logs&j=f0f0520d-467b-5d1d-a95d-4e3a2581fe8a&t=c140c00f-6c0a-5356-d099-4e047a5525ed&l=163)

D:\a\_work\1\s\src\Utilities.UnitTests\Options\SymbolNamesWithValueOptionTests.cs(22,54): error CS0433: The type 'Unit' exists in both 'Microsoft.CodeAnalysis.NetAnalyzers, Version=42.42.42.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'Test.Utilities, Version=42.42.42.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35' [D:\a\_work\1\s\src\Utilities.UnitTests\Analyzer.Utilities.UnitTests.csproj]

Ok, I'm going to try to resolve this error, I'll update you again when it's done.

@eriawan
Copy link
Member Author

eriawan commented Jan 3, 2024

@mavasani

I need some help on how to resolve the compile error on this project of Analyzer.Utilities.Unittests project, because the class name and the namespace on both Microsoft.CodeAnalysis.NetAnalyzers and Test.Utilities references are exactly the same, as they are actually pointing to the same source file.

Looking at the references of Analyzer.Utilities.Unittests project, it has references to other projects that has the same shared project references:

image

image

IMHO, this is one of the possible reason that cause the build error of having "error CS0433" since both projects has the same ref to the same shared projects, the "Analyzer.Utilities". Feel free to correct me, though.

Is there any guidance I should do to fix this errors?

@eriawan
Copy link
Member Author

eriawan commented Jan 6, 2024

@mavasani

Pardon, please review and let me know how to proceed further, as I'm currently having the problem of errors in #7085 (comment)

Thanks in advance!

@eriawan
Copy link
Member Author

eriawan commented Jan 9, 2024

@mavasani

Just to remind, could you help me to solve the compile problem I've described in #7085 (comment) ?

Or should I update the Test.Utilities.csproj to remove the line of Import Project Analyzer.Utilities.projitems and add project reference to Microsoft.CodeAnalysis.NetAnalyzers instead?

Please confirm.

@mavasani
Copy link
Contributor

mavasani commented Jan 9, 2024

@eriawan We need these types to be public only when included in the AnalyzerUtilities project. One way to work around this issue is to define them in source with preprocessor directives:

#if ANALYZER_UTILITIES
public class Unit
#else
internal class Unit
#endif
{
   ... class definition
}

And define the preprocessor directive ANALYZER_UTILITIES in AnalyzerUtilities.csproj

@eriawan
Copy link
Member Author

eriawan commented Jan 11, 2024

@eriawan We need these types to be public only when included in the AnalyzerUtilities project. One way to work around this issue is to define them in source with preprocessor directives:

#if ANALYZER_UTILITIES
public class Unit
#else
internal class Unit
#endif
{
   ... class definition
}

And define the preprocessor directive ANALYZER_UTILITIES in AnalyzerUtilities.csproj

@mavasani
Thanks for the suggestion! Sorry for late reply.

I'm going to do this today 🙂

@eriawan eriawan force-pushed the make-AnalyzerOptionsExtensions-public branch from 5366322 to 4487c21 Compare January 11, 2024 22:19
…csproj and update AnalyzerOptionsExtensions, SymbolNamesWithValueOption, Unit with #if for !TEST_UTILITIES and TEST_UTILITIES as #else
Copy link

codecov bot commented Jan 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8d8ac7d) 96.44% compared to head (85c5802) 96.43%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7085      +/-   ##
==========================================
- Coverage   96.44%   96.43%   -0.01%     
==========================================
  Files        1413     1413              
  Lines      337719   337719              
  Branches    11177    11177              
==========================================
- Hits       325700   325694       -6     
- Misses       9200     9206       +6     
  Partials     2819     2819              

@eriawan
Copy link
Member Author

eriawan commented Jan 13, 2024

@mavasani

Done updating TestUtilities.csproj to add constant/symbol and also update some classes to have#if symbols to separate public and internal modifiers.
Looking at the CI of the build, all is green 🟢 ✔️

Please review, thanks in advance!

Copy link
Contributor

@mavasani mavasani left a comment

Choose a reason for hiding this comment

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

Thanks!

@mavasani mavasani merged commit a4f3bc6 into dotnet:main Jan 16, 2024
11 checks passed
@eriawan eriawan deleted the make-AnalyzerOptionsExtensions-public branch January 16, 2024 14:14
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.

Make AnalyzerOptionsExtensions public
2 participants