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

SA1516 Elements should be separated by blank line - Razor Class Library - csproj file #3738

Closed
roysurles opened this issue Nov 27, 2023 · 12 comments

Comments

@roysurles
Copy link

"SA1516 Elements should be separated by blank line" shows warnings for csproj file of a "Razor Class Library " project

This does not occur for regular Blazor project or xUnit Test project.

Cannot find a way to suppress this warning for just the csproj file and/or prevent Stylecop from firig this warning against the csproj file in a "Razor Class Library " project

@bjornhellander
Copy link
Contributor

I am having difficulty understanding what it is you want. Could you try to explain more what you experience and what it is you would like to achieve? Maybe post some screenshots and/or a link to a repo to show the problem?

@roysurles
Copy link
Author

Please see screenshots below...

  • Poolcorp.PointOfSale.csproj is a csproj file that is firing the SA1516 rule as Warning
  • this is razor class library project -->
  • This rule does not fire warning in our Blazor csproj file or our xUnit csproj file
  • We have resolved this rule's warning in all places in c# code
  • Is there a way we can suppress SA1516, just for the file: Poolcorp.PointOfSale.csproj

image

@bjornhellander
Copy link
Contributor

These rules/anlyzers should only execute on what the compiler thinks is c# code, so they should never fire inside csproj files. Can you provide a link to a repository where this happens?

@bjornhellander
Copy link
Contributor

One hypothesis could be that Visual Studio uses the project file name in the error list if SA1516 is reported without a location. Don't know why that would happen, though. If you rebuild and look in the output view, what does it look like when the warning is reported? Can you post a part of the output?

@bjornhellander
Copy link
Contributor

Regarding suppressing it, if the diagnostic is reported without a location as I speculated above, then I don't think that you can suppress those warnings without turning off the entire rule in that project. This can be done in an .editorconfig file or a ruleset file, if you would like. But this behaviour is caused by something weird, so it would be good if we could find the root cause instead, so you don't have to turn it off.

@roysurles
Copy link
Author

I cannot send you the repo link due to my employers privacy rules...

I agree that it would be better to fix than suppress.

My mistake, its not a Razor Class Library project, its the Blazor Server project.

I did recreate in a new Blazor Server .Net 7 or 8 project.

  • Add the latest Stylecop Analyzer nuget package
  • Add our ruleset.settings file

Attached is the simple recreated Blazor server app that demo's the issue.

BlazorServerAppNet7.rename to .zip

@bjornhellander
Copy link
Contributor

I made a small change to trigger SA1516 and this is what I got in the build output:

Rebuild started at 8:10 PM...
1>------ Rebuild All started: Project: BlazorServerAppNet7, Configuration: Debug Any CPU ------
1>CSC : warning SA1516: Elements should be separated by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1516.md)
1>C:\Users\bjorn\source\repos\BlazorServerAppNet7\BlazorServerAppNet7\BlazorServerAppNet7\Pages\Error.cshtml.cs(12,1,12,5): warning SA1516: Elements should be separated by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1516.md)
1>CSC : warning SA0001: XML comment analysis is disabled due to project configuration (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA0001.md)
1>BlazorServerAppNet7 -> C:\Users\bjorn\source\repos\BlazorServerAppNet7\BlazorServerAppNet7\BlazorServerAppNet7\bin\Debug\net7.0\BlazorServerAppNet7.dll
1>Done building project "BlazorServerAppNet7.csproj".
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
========== Rebuild completed at 8:10 PM and took 01.156 seconds ==========

The second mention of SA1516 is the one which I caused myself. This one points to a specific file and line. The first one, which was being triggered before my change, has no location in the output.

Will continue by trying to understand why this happens.

@bjornhellander
Copy link
Contributor

bjornhellander commented Nov 27, 2023

If you want to use any newer language construct, you really should use one of the beta versions, since 1.1.118 is from 2019.

@bjornhellander
Copy link
Contributor

Updating to 1.2.0-beta.507 "fixed" it, meaning the warning with the missing location disappears. There has been a number of bug reports on SA1516 related to file scoped namespaces and top-level statements. None exactly like this as far as I can see, but close enough since we seem to have fixed this case as well.

Feel free to close this if upgrading works in your real project as well.

@roysurles
Copy link
Author

Yes, the 1.2.0-beta.507 "fixed" it. I need to check with our architect if he will allow a beta package.

Do you have an ETA of an official release of this latest beta?

Thank you very much!

@bjornhellander
Copy link
Contributor

Unfortunately not. See for example #3500 and #3420 (comment), but the general reasoning is that beta releases should not be a problem since this is only a development dependency.

@sharwell
Copy link
Member

Duplicate of #3242

@sharwell sharwell marked this as a duplicate of #3242 Nov 28, 2023
@sharwell sharwell closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants