-
-
Notifications
You must be signed in to change notification settings - Fork 887
Use stylecop in Test project #1090
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
Use stylecop in Test project #1090
Conversation
…ests # Conflicts: # tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegParseStreamOnly.cs # tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg_ImageSpecific.cs # tests/ImageSharp.Benchmarks/Samplers/Crop.cs # tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs # tests/ImageSharp.Tests/TestUtilities/ImageComparison/PixelDifference.cs # tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs
|
I expect painful conflicts with #1089. |
How were the rules added? Any additional rules should be added to and the submodule updated. Regarding the addition of rules.
|
antonfirsov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I expected much worse from StyleCop here, but most code changes seem to be positive. With several exceptions of course.
| struct C | ||
| private struct C | ||
| { | ||
| public uint tmp3, tmp6, tmp9, tmp12, tmp15, tmp18, tmp21, tmp24; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the strict enforcement of the multi-line rule in low level code 😕 Definitely does not help readability here (irrelevant pieces taking more space).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I don't like grouped declarations. It's too easy to set the variable to the wrong type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its back to a single line: d59ca98
|
|
||
| [Theory] | ||
| [WithTestPatternImages(200, 200, PixelTypes.Rgba32 | PixelTypes.Bgra32)] | ||
| [WithTestPatternImage(200, 200, PixelTypes.Rgba32 | PixelTypes.Bgra32)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plural form might make sense here, since the attribute is feeding an image for each requested pixel type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed with: f897ab6
| c1 = _mm_load_ps(s, 32); | ||
| Vector4 t3 = (c0 + c1); | ||
| Vector4 t4 = (c0 - c1); | ||
| Vector4 c0 = Mm_load_ps(s, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, stylecop, you failed terribly again!
This code has been kept deliberately similar to the original. and _mm_load_ps refers to the corresponding C++ intrinsic to emphasize compatibility with that implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stylecop hasn't failed here. The rule is good, this is an edge case.
The fix was based on a lack of critical information.
I would add the exception inline with a justification describing why this is important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, just trying to be dramatic 😄
The point is that we need to be careful with the automatic application of the rules. If something needs to be suppressed too often, then re-evaluate the rule. Fortunately this doesn't seem to be the case with the current set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, the rules are not fixed and as soon as one causes significant issue we should definitely exclude it.
All I'm looking for by adding rules is a little bit more structure to our tests. A lot of different people have submitted significant parts of code now and it's become, for me, at least difficult to follow at times.
The less draconian the ruleset the better. Let's just be careful to not throw the baby out with the bathwater.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have reverted it back, to be more like the original code again: 94dc54b
| [Params( | ||
| TestImages.Jpeg.BenchmarkSuite.Lake_Small444YCbCr, | ||
| TestImages.Jpeg.BenchmarkSuite.BadRstProgressive518_Large444YCbCr, | ||
| /* The scaled result for the large image "ExifGetString750Transform_Huge420YCbCr" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The /* */ comments are harder to work with in most C# IDE-s. Was the change necessary because of the rule? If yes, then I'm afraid that enforcing it may affect our test-code productivity. Or even worse: not placing comments where they should be present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd have added the spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two conflicting rules here:
- SA1515 Single-line comment should be preceded by blank line
- SA1115 The parameter should begin on the line after the previous parameter.
I have changed it back now as it was before with an exception for SA1115, see commit: d59ca98
| @@ -25,29 +27,32 @@ public interface ITestImageProvider | |||
| /// <summary> | |||
| /// Provides <see cref="Image{TPixel}" /> instances for parametric unit tests. | |||
| /// </summary> | |||
| /// <typeparam name="TPixel">The pixel format of the image</typeparam> | |||
| /// <typeparam name="TPixel">The pixel format of the image.</typeparam> | |||
| public abstract partial class TestImageProvider<TPixel> : ITestImageProvider | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file name is misleading now, we should either always move classes to a separate files, or change the rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this instance, yes I'd probably move. The relaxing of the rule is designed to allow things like combining enums and classes in the same file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have moved the interface to a separate file
@JimBobSquarePants what do you mean by completeness? |
|
@antonfirsov Constructor docs are traditionally. Initializes a new instance of the <see cref="MyType" /> class/struct.IMO the params are the important part. |
In some cases yes. But mostly it becomes I wish that canonical text was not a thing with constructors :) It takes a whole sentence before the important stuff begins. This is wasted time for both doc writers and readers. |
brianpopow
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How were the rules added? Any additional rules should be added to
I missed that it is a submodule, i just edited SixLabors.Tests.ruleset 😕
Regarding the addition of rules.
- I want to keep copyright header in every file - We can do that globally via ctrl + .
- If a constructor has documentation it should be complete. If you think it's not required simply delete all the constructor documentation and any warnings will go away. Bad docs are worse than no docs.
- Regions can absolutely do one. I hate them 🤢
I have removed the regions, see commit: 6c40593
For SA1642, the constructor documentation: I think its not much helpful if there is just a standard text for the constructor, its better if there is some meaningful info or nothing at all.
For SA1611, Constructor is missing parameter documentation: Im here on anton's side of the argument. Often its just as he said an meaningless "The value" comment. Besides that there are more than 4k warnings were i cannot add meaningful comment, because i have not written the tests.
I will change the submodule with the rules, once we agree on the rules to apply.
| TestImages.Jpeg.BenchmarkSuite.ExifGetString750Transform_Huge420YCbCr, | ||
| */ | ||
|
|
||
| #pragma warning disable SA1115 // Parameter should follow comma |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we not just disable these kind of rules instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SA1115 is now disabled
…ests # Conflicts: # tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs # tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs # tests/ImageSharp.Tests/Memory/Alocators/ArrayPoolMemoryAllocatorTests.cs # tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs # tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs
…eSharp.Tests.ProfilingSandbox
|
I have some trouble with the ProfilingSanbox project. There are some errors and alot of wanings im not sure how to resolve. The errors look like this: And the warnings: @JimBobSquarePants have you seen those errors here before? Any ideas how to resolve them would be very welcome. |
src/Directory.Build.props
Outdated
| <InternalsVisibleTo Include="ImageSharp.Benchmarks" /> | ||
| <InternalsVisibleTo Include="SixLabors.ImageSharp.Sandbox46" /> | ||
| <InternalsVisibleTo Include="SixLabors.ImageSharp.Tests" /> | ||
| <InternalsVisibleTo Include="ImageSharp.Tests.ProfilingSandbox" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this your breaking change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have added this because i was getting more than 2k errors of Error CS0122 '...' is inaccessible due to its protection level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's because you're including all the files from the test project in the sandbox.
We don't do that anymore. The sandbox project simply references the test one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's because you're including all the files from the test project in the sandbox.
We don't do that anymore. The sandbox project simply references the test one.
great, thank you! I was not aware of that. I have the removed the tests from the profiling sandbox, now it work works. See: commit: 0bce7af
… to ImageSharp.Tests.ProfilingSandbox" This reverts commit 9f181a3.
Codecov Report
@@ Coverage Diff @@
## master #1090 +/- ##
=======================================
Coverage 81.53% 81.53%
=======================================
Files 704 704
Lines 29384 29384
Branches 3290 3290
=======================================
Hits 23957 23957
Misses 4734 4734
Partials 693 693
Continue to review full report at Codecov.
|
Prerequisites
Description
This PR will introduce stylecop rules to the TestProject. The rules are less strict than in the main project. Those are the rules:
Note to @JimBobSquarePants: I have added SA1642, SA1124, SA1611