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

Prevent use of language-specific symbols in language-agnostic layers #4564

Merged
merged 13 commits into from
Dec 17, 2020

Conversation

Evangelink
Copy link
Member

Fix #4323

@Evangelink Evangelink requested a review from a team as a code owner December 11, 2020 18:08
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="$(MicrosoftCodeAnalysisVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="$(MicrosoftCodeAnalysisVersion)" />
Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't find how to have a conditional include here that would say include the C# workspace nuget if the project name (or assembly name) contains CSharp, include VB for vb and fallback to the common.

@sharwell any idea?

Copy link
Member

@sharwell sharwell Dec 14, 2020

Choose a reason for hiding this comment

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

IMO the projitems should never have ProjectReference, but other people feel differently about this. There certainly isn't "one right way".

Copy link
Member

Choose a reason for hiding this comment

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

I think the most common expectation would be Workspaces.Utilities references language-agnostic only, and Workspaces.Utilities.CSharp references the C# assemblies (i.e. split the shared projects the same way normal assemblies are split).

Copy link
Member Author

Choose a reason for hiding this comment

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

I also prefer not to have references in shared projects and to be honest with new project system I have stopped using shared project, I simply add manual reference to the files/folder I want to share. But I also understand how it makes it easier to share this common dependency.

Regarding Workspaces.Utilities.CSharp we currently don't have it and don't have C# specific code. I was thinking about a Choose just to help with avoiding the reference on each project.

If you all agree then I suggest to keep what I have done in this PR, otherwise I am open to suggestion :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I have no preference here - I am fine with whatever is easier for you @Evangelink :-)

@Evangelink Evangelink requested a review from mavasani December 14, 2020 09:16
@@ -78,7 +77,7 @@ public Location GetLocation()
/// Gets the display string of <see cref="InsecureSymbol"/> or <see cref="InsecureAttribute"/>.
/// </summary>
/// <returns>Display string of <see cref="InsecureSymbol"/> or <see cref="InsecureAttribute"/>.</returns>
public string GetDisplayString()
public string GetDisplayString(Func<TypedConstant, string> typedConstantToString)
Copy link
Member Author

Choose a reason for hiding this comment

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

@dotpaul I went for a bit "hacky" solution but trying to have this class abstract was causing too many changes and it was hard to by-pass the static GetOrCreate method.

@Evangelink
Copy link
Member Author

Hum I guess that this needs to be changed to target 2.9.x, isn't it? cc @mavasani

@codecov
Copy link

codecov bot commented Dec 17, 2020

Codecov Report

Merging #4564 (4479c8d) into master (6730a14) will decrease coverage by 0.01%.
The diff coverage is 33.65%.

@@            Coverage Diff             @@
##           master    #4564      +/-   ##
==========================================
- Coverage   95.87%   95.85%   -0.02%     
==========================================
  Files        1182     1193      +11     
  Lines      268934   268953      +19     
  Branches    16232    16222      -10     
==========================================
- Hits       257838   257812      -26     
- Misses       9015     9072      +57     
+ Partials     2081     2069      -12     

@Evangelink
Copy link
Member Author

Not sure what is going-on here, I can't repro locally.


Rule ID | Category | Severity | Notes
--------|----------|----------|-------
CA2014 | Reliability | Warning | CSharpDoNotUseStackallocInLoopsAnalyzer, [Documentation](https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2014)
Copy link
Contributor

@mavasani mavasani Dec 17, 2020

Choose a reason for hiding this comment

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

If you define a base type DoNotUseStackallocInLoopsAnalyzer in the language-agnostic layer and have the descriptor in this base type instead of the C# specific type, then you will not need any changes to any of the Analyzer releases file. This will also ensure that all analyzer releases and released analyzers are in a single file in the core project. Would you be able to make this change?

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.

Overall LGTM. I'd like to avoid any changes to AnalyzerReleases as part of the PR by avoiding moving descriptors to language specific layer. I can approve and merge once that is done.

Thanks for the work @Evangelink!

@mavasani
Copy link
Contributor

Tagging @jmarolf again - seems like random tests in DiagnosticDescriptorCreationAnalyzerTests are failing on Ubuntu Debug queue on various PRs, but not in any others. We probably should mark this test type with WindlowsOnly fact and file a tracking issue for it.

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 @Evangelink!

@mavasani mavasani merged commit 1264907 into dotnet:master Dec 17, 2020
@Evangelink Evangelink deleted the prevent-cs-vb-in-agnostic-layer branch December 17, 2020 22:11
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.

Ban language-specific symbols in language-agnostic layers
4 participants