Skip to content

Conversation

@brianpopow
Copy link
Collaborator

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

This PR will introduce stylecop rules to the TestProject. The rules are less strict than in the main project. Those are the rules:

<!--https://github.com/dotnet/roslyn/issues/18117-->
<Rule Id="AD0001" Action="None" />

<!--Missing XML comment for publicly visible type or member-->
<Rule Id="CS1591" Action="None" />

<!--Call 'ConfigureAwait(false)'-->
<Rule Id="RCS1090" Action="None" />
    
<!--XML comment analysis is disabled due to project configuration-->
<Rule Id="SA0001" Action="None" />

<!--Using directive should appear within a namespace declaration-->
<Rule Id="SA1200" Action="None" />

<!--Elements should be documented.-->
<Rule Id="SA1600" Action="None" />

<!--A field should not follow a method-->
<Rule Id="SA1201" Action="None" />

<!--Elements must be ordered by access-->
<Rule Id="SA1202" Action="None" />

<!--Constants must appear before fields-->
<Rule Id="SA1203" Action="None" />

<!--Static members should appear before non-static members-->
<Rule Id="SA1204" Action="None" />

<!--Field names must not contain underscore-->
<Rule Id="SA1310" Action="None" />

<!--Field should be private-->
<Rule Id="SA1401" Action="None" />

<!--A C# code file contains more than one unique type.-->
<Rule Id="SA1402" Action="None" />

<!--The last statement in a multi-line C# initializer or list is missing a trailing comma.-->
<Rule Id="SA1413" Action="None" />

<!--Partial elements should be documented.-->
<Rule Id="SA1601" Action="None" />

<!--Comments should end with a period. I like this but there's 3000+ errors to fix in ImageSharp-->
<Rule Id="SA1629" Action="None" /> 
    
<!--The XML documentation header for a C# constructor does not contain the appropriate summary text.-->
<Rule Id="SA1642" Action="None" />
    
<!--Do not use regions.-->
<Rule Id="SA1124" Action="None" />
    
<!--Constructor is missing documentation for one or more of its parameters.-->
<Rule Id="SA1611" Action="None" />

<!--A C# code file is missing a standard file header.-->
<Rule Id="SA1633" Action="Warning" />

Note to @JimBobSquarePants: I have added SA1642, SA1124, SA1611

…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
@antonfirsov
Copy link
Member

I expect painful conflicts with #1089.

@JimBobSquarePants
Copy link
Member

Note to @JimBobSquarePants: I have added SA1642, SA1124, SA1611

How were the rules added? Any additional rules should be added to

https://github.com/SixLabors/SharedInfrastructure/blob/master/SixLabors.Tests.ruleset

and the submodule updated.

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 🤢

Copy link
Member

@antonfirsov antonfirsov left a 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;
Copy link
Member

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).

Copy link
Member

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.

Copy link
Collaborator Author

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)]
Copy link
Member

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.

Copy link
Collaborator Author

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);
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Collaborator Author

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"
Copy link
Member

@antonfirsov antonfirsov Jan 23, 2020

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.

Copy link
Member

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.

Copy link
Collaborator Author

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
Copy link
Member

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.

Copy link
Member

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

Copy link
Collaborator Author

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

@antonfirsov
Copy link
Member

antonfirsov commented Jan 23, 2020

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.

@JimBobSquarePants what do you mean by completeness?
For me, obvious <param > docs do not add any value. We can omit them while still documenting life-saving non-trivial information in <summary>.

@JimBobSquarePants
Copy link
Member

@antonfirsov Constructor docs are traditionally.

Initializes a new instance of the <see cref="MyType" /> class/struct.

IMO the params are the important part.

@antonfirsov
Copy link
Member

IMO the params are the important part.

In some cases yes. But mostly it becomes <param name="value">The value.</param>. Sebastian Aaltonen has a good point on why is this wrong. (One of the rare cases when I agree with a game developer actually.)

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.

Copy link
Collaborator Author

@brianpopow brianpopow left a 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
Copy link
Member

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?

Copy link
Collaborator Author

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
@brianpopow
Copy link
Collaborator Author

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:
Error CS0121 The call is ambiguous between the following methods or properties: 'SixLabors.ImageSharp.Tests.TestUtils.IsEquivalentTo<TPixel>(SixLabors.ImageSharp.Image<TPixel>, SixLabors.ImageSharp.Image<TPixel>, bool)' and 'SixLabors.ImageSharp.Tests.TestUtils.IsEquivalentTo<TPixel>(SixLabors.ImageSharp.Image<TPixel>, SixLabors.ImageSharp.Image<TPixel>, bool)' ImageSharp.Tests.ProfilingSandbox (net472), ImageSharp.Tests.ProfilingSandbox (netcoreapp2.1), ImageSharp.Tests.ProfilingSandbox (netcoreapp3.1) E:\vsprojekte\ImageSharp\tests\ImageSharp.Tests\TestUtilities\Tests\TestUtilityExtensionsTests.cs 59

And the warnings:
Warning CS0436 The type 'ApproximateColorSpaceComparer' in 'E:\vsprojekte\ImageSharp\tests\ImageSharp.Tests\Colorspaces\Conversion\ApproximateColorspaceComparer.cs' conflicts with the imported type 'ApproximateColorSpaceComparer' in 'SixLabors.ImageSharp.Tests, Version=0.0.1.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'E:\vsprojekte\ImageSharp\tests\ImageSharp.Tests\Colorspaces\Conversion\ApproximateColorspaceComparer.cs'. ImageSharp.Tests.ProfilingSandbox (net472), ImageSharp.Tests.ProfilingSandbox (netcoreapp2.1), ImageSharp.Tests.ProfilingSandbox (netcoreapp3.1) E:\vsprojekte\ImageSharp\tests\ImageSharp.Tests\Colorspaces\Conversion\RgbAndYCbCrConversionTest.cs 20

@JimBobSquarePants have you seen those errors here before? Any ideas how to resolve them would be very welcome.

<InternalsVisibleTo Include="ImageSharp.Benchmarks" />
<InternalsVisibleTo Include="SixLabors.ImageSharp.Sandbox46" />
<InternalsVisibleTo Include="SixLabors.ImageSharp.Tests" />
<InternalsVisibleTo Include="ImageSharp.Tests.ProfilingSandbox" />
Copy link
Member

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?

Copy link
Collaborator Author

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

Copy link
Member

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.

https://github.com/SixLabors/ImageSharp/pull/1090/files#diff-791cc76ca5e2665ba784771043fd9123R17

We don't do that anymore. The sandbox project simply references the test one.

Copy link
Collaborator Author

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.

https://github.com/SixLabors/ImageSharp/pull/1090/files#diff-791cc76ca5e2665ba784771043fd9123R17

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

@codecov
Copy link

codecov bot commented Jan 31, 2020

Codecov Report

Merging #1090 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           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
Flag Coverage Δ
#unittests 81.53% <100%> (ø) ⬆️
Impacted Files Coverage Δ
src/ImageSharp/Formats/Gif/GifDecoderCore.cs 82.83% <100%> (ø) ⬆️
src/ImageSharp/Formats/Gif/GifMetadata.cs 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0bce7af...1f3311b. Read the comment docs.

@JimBobSquarePants JimBobSquarePants merged commit 2cf2e46 into SixLabors:master Feb 2, 2020
@JimBobSquarePants JimBobSquarePants added this to the 1.0.0-rc1 milestone Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants