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

Enable nullability checks #289

Merged
merged 6 commits into from
Sep 6, 2023
Merged

Enable nullability checks #289

merged 6 commits into from
Sep 6, 2023

Conversation

JimBobSquarePants
Copy link
Member

@JimBobSquarePants JimBobSquarePants commented Aug 22, 2023

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

Removes all #nullable disable compiler instructions except for PolygonClipper (which looks like a ton of work)
Performs minor cleanup to remove IDE warnings

Sorry, something went wrong.

@codecov
Copy link

codecov bot commented Aug 22, 2023

Codecov Report

Merging #289 (6ef0a7b) into main (b7402f4) will increase coverage by 0%.
The diff coverage is 79%.

@@         Coverage Diff         @@
##           main   #289   +/-   ##
===================================
  Coverage    80%    80%           
===================================
  Files        97     97           
  Lines      4875   4873    -2     
  Branches    880    869   -11     
===================================
+ Hits       3925   3929    +4     
+ Misses      753    752    -1     
+ Partials    197    192    -5     
Flag Coverage Δ
unittests 80% <79%> (+<1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/ImageSharp.Drawing/Processing/Brush.cs 0% <0%> (ø)
...rawing/Processing/Extensions/DrawTextExtensions.cs 80% <ø> (ø)
src/ImageSharp.Drawing/Processing/GradientBrush.cs 81% <ø> (ø)
src/ImageSharp.Drawing/Processing/ImageBrush.cs 80% <ø> (-1%) ⬇️
...ageSharp.Drawing/Processing/LinearGradientBrush.cs 84% <ø> (ø)
src/ImageSharp.Drawing/Processing/PatternBrush.cs 75% <ø> (ø)
src/ImageSharp.Drawing/Processing/PatternPen.cs 50% <ø> (ø)
...ageSharp.Drawing/Processing/RadialGradientBrush.cs 76% <ø> (ø)
src/ImageSharp.Drawing/Processing/RecolorBrush.cs 87% <ø> (ø)
src/ImageSharp.Drawing/Processing/SolidBrush.cs 86% <ø> (ø)
... and 21 more

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

=> this.lineSegments = segments ?? throw new ArgumentNullException(nameof(segments));
{
ArgumentNullException.ThrowIfNull(segments);
this.lineSegments = segments ?? throw new ArgumentNullException(nameof(segments));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.lineSegments = segments ?? throw new ArgumentNullException(nameof(segments));
this.lineSegments = segments;

@@ -49,7 +48,10 @@ public Path(Path path)
/// </summary>
/// <param name="segments">The segments.</param>
public Path(params ILineSegment[] segments)
=> this.lineSegments = segments ?? throw new ArgumentNullException(nameof(segments));
{
ArgumentNullException.ThrowIfNull(segments);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can even get rid of this null check. Calling this method without a parameter results in an empty array

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gave it a go... Analyzer doesn't like that!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm strange. My rider is not showing me an error on that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I have more errors on my Mac.. I can not even build it correct.. Need to checkout a clean copy..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A disturbance in the force!

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason you need the null check is you can call it like this which will result in segments being null

LineSergment[] segments = null;
var path = new Path(segments)

where as if called as new Path() then an empty array will be passed for you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A disturbance in the force!

image

hmm
image
^^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason you need the null check is you can call it like this which will result in segments being null

LineSergment[] segments = null;
var path = new Path(segments)

where as if called as new Path() then an empty array will be passed for you.

Yeah this can happen on many path. But this will not compile when Nullable Errors are turned on.

Copy link

@mandel-macaque mandel-macaque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, some minor nits regarding !=.

other.StartColor.Equals(this.StartColor) &&
other.EndColor.Equals(this.EndColor);
public bool Equals(Edge? other)
=> other != null &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use is and is not over == and != since those operators can be override (and have bugs). There is an .editorconfig to do that automatically.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I've considered this but will only enforce once I update the config. It's shared across all the projects via a Git submodule.

@@ -23,7 +21,7 @@ namespace SixLabors.ImageSharp.Drawing.Processing;
/// </remarks>
public abstract class Pen : IEquatable<Pen>
{
private readonly float[] pattern;
private readonly float[]? pattern;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, since I do not know the usage. Why nullable over Array.Empty ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have a dig through actually. We might be better off changing it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, much better!

public virtual bool Equals(Pen other)
=> this.StrokeWidth == other.StrokeWidth
public virtual bool Equals(Pen? other)
=> other != null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'is not' ?

@@ -133,7 +130,7 @@ public IPath Transform(Matrix3x2 matrix)
/// <inheritdoc />
public IEnumerable<ISimplePath> Flatten()
{
var paths = new List<ISimplePath>();
List<ISimplePath> paths = new();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised you don't get a warning when declaring paths in a diff scope. Does it? (I'm doing a dry review without compiling).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No warnings. We have explicit rules requiring this. for members. I imagine the compiler understands that.

{
get
{
if (this.overlayBuffer != null)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'is not'

@JimBobSquarePants
Copy link
Member Author

Thanks for the reviews! Much appreciated! 🥰

@JimBobSquarePants JimBobSquarePants merged commit 3f1b4fa into main Sep 6, 2023
@JimBobSquarePants JimBobSquarePants deleted the js/nullable-enable branch September 6, 2023 05:29
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.

None yet

4 participants