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

Prepend $(NoWarn) to list analyzer rule generates a false positive. #74087

Closed
mtaylorfsmb opened this issue Jun 20, 2024 · 3 comments
Closed
Labels
Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@mtaylorfsmb
Copy link

Not sure if the issue goes here or over with the analyzers because I can find no references anywhere to the ID or where project file analyzers reside.

The issue is that if you have a project file that appends warnings to the $(NoWarn) value then an analyzer rule kicks in telling you to prepend $(NoWarn) to list and the fix appends to the value although you're already doing that.

Version Used: 8.0

Steps to Reproduce:

  1. Create a simple C# project.
  2. In the project file add the following property <NoWarn>$(NoWarn),CA2201</NoWarn>.
  3. The IDE will generate an analyzer recommendation saying you should prepend the values to $(NoWarn) which is already being done.

Diagnostic Id:
Prepend $(NoWarn) to list

Expected Behavior:
This should not generate a false positive because the value(s) are being added to the list.

Actual Behavior:
Analyzer generates a warning.

The problem, I believe, is with the comma separates. Most of the documentation shows separating the values with a comma. However in the couple of cases where the docs show appending to $(NoWarn) they are separated by semicolons. There doesn't seem to be any clarification on which one is correct. The analyzer doesn't appear to support using commas. Since this syntax is valid (I believe) the analyzer should support using either comma or semicolon separators. If commas are not allowed then all the examples that show commas being used should be updated to clarify that semicolons are needed instead.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 20, 2024
@jjonescz
Copy link
Member

Should you use a semicolon instead of a comma? I.e., <NoWarn>$(NoWarn);CA2201</NoWarn>.

@Cosifne
Copy link
Member

Cosifne commented Jul 2, 2024

Closed as this looks like a syntax error in csproj file

@Cosifne Cosifne closed this as completed Jul 2, 2024
@mtaylorfsmb
Copy link
Author

@Cosifne How is this a syntax error in the csproj file? Both semicolon and commas are valid in a project file. Refer to the docs to confirm this or else the docs are wrong and need to be updated. The analyzer is the only place that this seems to be a problem with as the warnings seem to go away using either punctuator during a build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

3 participants