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

StyleCop Analyzer not generating an xml anymore #126

Closed
miikeat opened this issue Jun 10, 2021 · 9 comments · Fixed by #127
Closed

StyleCop Analyzer not generating an xml anymore #126

miikeat opened this issue Jun 10, 2021 · 9 comments · Fixed by #127

Comments

@miikeat
Copy link

miikeat commented Jun 10, 2021

The new Version of StyleCop is not generating an xml file anymore as mentioned here: DotNetAnalyzers/StyleCopAnalyzers#1178

Therefore the current StyleCop Parser does not find the report. Is there a way to get it to work again? Or is a new Parser required for this?

@tomasbjerre
Copy link
Owner

Can you create a custom logger to solve this? Like they talk about here:
DotNetAnalyzers/StyleCopAnalyzers#1090 (comment)

And they say it is described here:
https://docs.microsoft.com/sv-se/previous-versions/visualstudio/visual-studio-2015/msbuild/build-loggers?view=vs-2015&redirectedfrom=MSDN

I am not using that tool, but perhaps a custom logger can create a report in any of the supported formats of this tool.

@miikeat
Copy link
Author

miikeat commented Jun 14, 2021

I was about to try that, but msbuild has a -fileLogger parameter that writes the whole output of msbuild also to a file.
https://docs.microsoft.com/en-us/visualstudio/msbuild/obtaining-build-logs-with-msbuild?view=vs-2019

I'm going to try that tomorrow, but I'm not sure how the Parser is going to handle all the stuff before and after the relevant stuff. Also the file is not XML now... so I guess a new or different parser will then be required...
I'll post my findings tomorrow.

@miikeat
Copy link
Author

miikeat commented Jun 14, 2021

The relevant output looks like this btw:

  C:\Test\CON-Tests\SC-CON-FR01.cs(529,40): warning SA1003: Operator '=>' should be followed by whitespace. [C:\Test\Test.csproj]
  C:\Test\MIO-Tests\SC-MIO-FT03.cs(368,29): warning SA1117: The parameters should all be placed on the same line or each parameter should be placed on its own line. [C:\Test\Test.csproj]
  C:\Test\MIO-Tests\SC-MIO-FT03.cs(366,7): warning SA1614: Element parameter documentation should have text [C:\Test\Test.csproj]
  C:\Test\BAS-Tests\SC-BAS-FT06.cs(122,48): warning SA1503: Braces should not be omitted [C:\Test\Test.csproj]
  C:\Test\MIO-Tests\SC-MIO-FT03.cs(367,16): warning SA1606: Element documentation should have summary text [C:\Test\Test.csproj]
  C:\Test\MIO-Tests\SC-MIO-FT03.cs(370,3): warning SA1505: An opening brace should not be followed by a blank line. [C:\Test\Test.csproj]
  C:\Test\MIO-Tests\SC-MIO-FT03.cs(367,20): warning SA1116: The parameters should begin on the line after the declaration, whenever the parameter span across multiple lines [C:\Test\Test.csproj]
  C:\Test\COM-Tests\SC-COM-FT03.cs(298,51): warning SA1503: Braces should not be omitted [C:\Test\Test.csproj]
  C:\Test\COM-Tests\SC-COM-FT03.cs(333,22): warning SA1108: Block statements should not contain embedded comments [C:\Test\Test.csproj]
  C:\Test\MIO-Tests\SC-MIO-FT01.cs(356,1): warning SA1137: Elements should have the same indentation [C:\Test\Test.csproj]
  C:\Test\MIO-Tests\SC-MIO-FT01.cs(357,1): warning SA1137: Elements should have the same indentation [C:\Test\Test.csproj]
  C:\Test\COM-Tests\SC-COM-FT03.cs(270,71): warning SA1108: Block statements should not contain embedded comments [C:\Test\Test.csproj]
  C:\Test\COM-Tests\SC-COM-FT03.cs(293,38): warning SA1108: Block statements should not contain embedded comments [C:\Test\Test.csproj]
  C:\Test\COM-Tests\SC-COM-FT17.cs(381,36): warning SA1500: Braces for multi-line statements should not share line [C:\Test\Test.csproj]
  C:\Test\MIO-Tests\SC-MIO-FT01.cs(437,1): warning SA1137: Elements should have the same indentation [C:\Test\Test.csproj]
  C:\Test\MIO-Tests\SC-MIO-FT01.cs(438,1): warning SA1137: Elements should have the same indentation [C:\Test\Test.csproj]
  C:\Test\COM-Tests\SC-COM-FT17.cs(437,36): warning SA1500: Braces for multi-line statements should not share line [C:\Test\Test.csproj]

@tomasbjerre
Copy link
Owner

Should be no problem implementing a paraer for that.

Can probably be done similar to CLangParser:
https://github.com/tomasbjerre/violations-lib/blob/master/src/main/java/se/bjurr/violations/lib/parsers/CLangParser.java

@miikeat
Copy link
Author

miikeat commented Jun 15, 2021

Nice, in that case i just copy that parser, replace the regex with something like that: https://regex101.com/r/t2ZFbH/1
and send you a pullrequest.
Do you have some kind of Contribution guide?

@tomasbjerre
Copy link
Owner

Add it as a new parser. I dont know if StyleCop2 or MSBuild might be fitting names. Is this the same format for all MSBuild output? Or the format is only for Stylecop?

Add it here, and the docs will be automatically updated:
https://github.com/tomasbjerre/violations-lib/blob/master/src/main/java/se/bjurr/violations/lib/reports/Reporter.java

You can see some reporters have some small explanation. You should add that fileLogger parameter in that text.

Also add test case, like:
https://github.com/tomasbjerre/violations-lib/blob/master/src/test/java/se/bjurr/violations/lib/CLangTest.java

@miikeat
Copy link
Author

miikeat commented Jun 15, 2021

Yeah I thought so too that MSBuildLogParser might be a better name as it hast the same format as regular msbuild warnings too. At least from what i've seen so far.

Alright... i'll try my best =)

@miikeat
Copy link
Author

miikeat commented Jun 15, 2021

is it an issue when the same warnings are twice in the output file?

@tomasbjerre
Copy link
Owner

They are added to a Set. So duplicates will automatically be removed.

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 a pull request may close this issue.

2 participants