-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Conversation
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out 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)); |
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.
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); |
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 think you can even get rid of this null check. Calling this method without a parameter results in an empty array
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.
Gave it a go... Analyzer doesn't like that!
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.
Hm strange. My rider is not showing me an error on that
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.
But I have more errors on my Mac.. I can not even build it correct.. Need to checkout a clean copy..
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 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 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.
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 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 reason you need the null check is you can call it like this which will result in
segments
being nullLineSergment[] 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.
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.
Looks good, some minor nits regarding !=.
other.StartColor.Equals(this.StartColor) && | ||
other.EndColor.Equals(this.EndColor); | ||
public bool Equals(Edge? other) | ||
=> other != null && |
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.
Use is
and is not
over == and != since those operators can be override (and have bugs). There is an .editorconfig to do that automatically.
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.
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; |
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.
Out of curiosity, since I do not know the usage. Why nullable over Array.Empty ?
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'll have a dig through actually. We might be better off changing it.
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.
Yeah, much better!
public virtual bool Equals(Pen other) | ||
=> this.StrokeWidth == other.StrokeWidth | ||
public virtual bool Equals(Pen? other) | ||
=> other != null |
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.
'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(); |
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'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).
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.
No warnings. We have explicit rules requiring this.
for members. I imagine the compiler understands that.
{ | ||
get | ||
{ | ||
if (this.overlayBuffer != null) |
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.
'is not'
Thanks for the reviews! Much appreciated! 🥰 |
Prerequisites
Description
Removes all
#nullable disable
compiler instructions except for PolygonClipper (which looks like a ton of work)Performs minor cleanup to remove IDE warnings