set WarningsAsErrors = true

This commit is contained in:
John Andrews
2024-05-07 14:05:03 +12:00
parent d6c2034d8e
commit d60b0486b6
81 changed files with 732 additions and 946 deletions

View File

@@ -4,7 +4,7 @@ public class ImageInfo
{
public int Width { get; set; }
public int Height { get; set; }
public string Format { get; set; }
public string Format { get; set; } = string.Empty;
public bool IsPortrait => Width < Height;
public bool IsLandscape => Height < Width;
}

View File

@@ -13,6 +13,7 @@
<Product>Image</Product>
<PackageProjectUrl>https://fileflows.com/</PackageProjectUrl>
<Description>Nodes for processing images files. This plugin contains nodes to convert and manipulate images.</Description>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup Condition=" '$(Configuration)' == 'Debug'">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />

View File

@@ -1,5 +1,4 @@
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using System.ComponentModel;
using ImageMagick;

View File

@@ -16,7 +16,7 @@ public abstract class ImageBaseNode:Node
/// <summary>
/// Gets or sets the current format of the image.
/// </summary>
protected string CurrentFormat { get; private set; }
protected string? CurrentFormat { get; private set; }
/// <summary>
/// Gets or sets the current width of the image.
@@ -72,7 +72,7 @@ public abstract class ImageBaseNode:Node
/// </summary>
/// <param name="args">The NodeParameters</param>
/// <param name="variables">Additional variables associated with the image (optional).</param>
protected void UpdateImageInfo(NodeParameters args, Dictionary<string, object> variables = null)
protected void UpdateImageInfo(NodeParameters args, Dictionary<string, object>? variables = null)
{
string extension = FileHelper.GetExtension(args.WorkingFile).ToLowerInvariant().TrimStart('.');
if (extension == "heic")
@@ -124,7 +124,7 @@ public abstract class ImageBaseNode:Node
/// <param name="format">The format of the image.</param>
/// <param name="variables">Additional variables associated with the image (optional).</param>
/// <param name="dateTaken">The date when the image was taken (optional).</param>
protected void UpdateImageInfo(NodeParameters args, int width, int height, string format, Dictionary<string, object> variables = null, DateTime? dateTaken = null)
protected void UpdateImageInfo(NodeParameters args, int width, int height, string format, Dictionary<string, object>? variables = null, DateTime? dateTaken = null)
{
var imageInfo = new ImageInfo
{

View File

@@ -18,7 +18,7 @@ public class ImageFormat: ImageNode
if(formatOpts.format?.Name == CurrentFormat)
{
args.Logger?.ILog("File already in format: " + formatOpts.format.Name);
args.Logger?.ILog("File already in format: " + (formatOpts.format?.Name ?? string.Empty));
return 2;
}

View File

@@ -15,9 +15,9 @@ namespace FileFlows.ImageNodes.Images;
public abstract class ImageNode : ImageBaseNode
{
[Select(nameof(FormatOptions), 1)]
public string Format { get; set; }
public string Format { get; set; } = string.Empty;
private static List<ListOption> _FormatOptions;
private static List<ListOption>? _FormatOptions;
public static List<ListOption> FormatOptions
{
get

View File

@@ -24,7 +24,11 @@ public class ImageResizer: ImageNode
[Select(nameof(ResizeModes), 2)]
public ResizeMode Mode { get; set; }
private static List<ListOption> _ResizeModes;
private static List<ListOption>? _ResizeModes;
/// <summary>
/// Gets the resize modes
/// </summary>
public static List<ListOption> ResizeModes
{
get

View File

@@ -15,7 +15,10 @@ public class ImageRotate: ImageNode
[Select(nameof(AngleOptions), 2)]
public int Angle { get; set; }
private static List<ListOption> _AngleOptions;
private static List<ListOption>? _AngleOptions;
/// <summary>
/// Gest the Angle Options
/// </summary>
public static List<ListOption> AngleOptions
{
get
@@ -24,9 +27,9 @@ public class ImageRotate: ImageNode
{
_AngleOptions = new List<ListOption>
{
new ListOption { Value = 90, Label = "90"},
new ListOption { Value = 180, Label = "180"},
new ListOption { Value = 270, Label = "270"}
new () { Value = 90, Label = "90"},
new () { Value = 180, Label = "180"},
new () { Value = 270, Label = "270"}
};
}
return _AngleOptions;

View File

@@ -10,11 +10,11 @@ namespace FileFlows.ImageNodes.Tests;
[TestClass]
public class ImageNodesTests
{
string TestImage1;
string TestImage2;
string TestImageHeic;
string? TestImage1;
string? TestImage2;
string? TestImageHeic;
string TempDir;
string TestCropImage1, TestCropImage2, TestCropImage3, TestCropImage4, TestCropImageNoCrop, TestExif;
string? TestCropImage1, TestCropImage2, TestCropImage3, TestCropImage4, TestCropImageNoCrop, TestExif;
public ImageNodesTests()
{
@@ -46,7 +46,7 @@ public class ImageNodesTests
[TestMethod]
public void ImageNodes_Basic_ImageFormat()
{
var args = new NodeParameters(TestImage1, new TestLogger(), false, string.Empty, null)
var args = new NodeParameters(TestImage1, new TestLogger(), false, string.Empty, null!)
{
TempPath = TempDir
};
@@ -59,7 +59,7 @@ public class ImageNodesTests
[TestMethod]
public void ImageNodes_Basic_ImageFormat_Heic()
{
var args = new NodeParameters(TestImageHeic, new TestLogger(), false, string.Empty, null)
var args = new NodeParameters(TestImageHeic, new TestLogger(), false, string.Empty, null!)
{
TempPath = TempDir
};
@@ -72,7 +72,7 @@ public class ImageNodesTests
[TestMethod]
public void ImageNodes_Basic_IsLandscape_Heic()
{
var args = new NodeParameters(TestImageHeic, new TestLogger(), false, string.Empty, null)
var args = new NodeParameters(TestImageHeic, new TestLogger(), false, string.Empty, null!)
{
TempPath = TempDir
};
@@ -89,7 +89,7 @@ public class ImageNodesTests
public void ImageNodes_Basic_Resize()
{
var logger = new TestLogger();
var args = new NodeParameters(TestImage1, logger, false, string.Empty, null)
var args = new NodeParameters(TestImage1, logger, false, string.Empty, null!)
{
TempPath = TempDir
};
@@ -107,7 +107,7 @@ public class ImageNodesTests
[TestMethod]
public void ImageNodes_Basic_Resize_Heic()
{
var args = new NodeParameters(TestImageHeic, new TestLogger(), false, string.Empty, null)
var args = new NodeParameters(TestImageHeic, new TestLogger(), false, string.Empty, null!)
{
TempPath = TempDir
};
@@ -122,15 +122,15 @@ public class ImageNodesTests
[TestMethod]
public void ImageNodes_Basic_Resize_Percent()
{
var args = new NodeParameters(TestImage1, new TestLogger(), false, string.Empty, null)
var args = new NodeParameters(TestImage1, new TestLogger(), false, string.Empty, null!)
{
TempPath = TempDir
};
var imgFile = new ImageFile();
imgFile.Execute(args);
int width = imgFile.GetImageInfo(args).Width;
int height = imgFile.GetImageInfo(args).Height;
int width = imgFile.GetImageInfo(args)?.Width ?? 0;
int height = imgFile.GetImageInfo(args)?.Height ?? 0;
var node = new ImageResizer();
node.Width = 200;
@@ -147,7 +147,7 @@ public class ImageNodesTests
[TestMethod]
public void ImageNodes_Basic_Flip()
{
var args = new NodeParameters(TestImage2, new TestLogger(), false, string.Empty, null)
var args = new NodeParameters(TestImage2, new TestLogger(), false, string.Empty, null!)
{
TempPath = TempDir
};
@@ -161,7 +161,7 @@ public class ImageNodesTests
[TestMethod]
public void ImageNodes_Basic_Flip_Heic()
{
var args = new NodeParameters(TestImageHeic, new TestLogger(), false, string.Empty, null)
var args = new NodeParameters(TestImageHeic, new TestLogger(), false, string.Empty, null!)
{
TempPath = TempDir
};
@@ -174,7 +174,7 @@ public class ImageNodesTests
[TestMethod]
public void ImageNodes_Basic_Rotate()
{
var args = new NodeParameters(TestImage2, new TestLogger(), false, string.Empty, null)
var args = new NodeParameters(TestImage2, new TestLogger(), false, string.Empty, null!)
{
TempPath = TempDir
};
@@ -187,7 +187,7 @@ public class ImageNodesTests
[TestMethod]
public void ImageNodes_Basic_Rotate_Heic()
{
var args = new NodeParameters(TestImageHeic, new TestLogger(), false, string.Empty, null)
var args = new NodeParameters(TestImageHeic, new TestLogger(), false, string.Empty, null!)
{
TempPath = TempDir
};
@@ -202,7 +202,7 @@ public class ImageNodesTests
{
Assert.IsTrue(System.IO.File.Exists(TestCropImage1));
var logger = new TestLogger();
var args = new NodeParameters(TestCropImage1, logger, false, string.Empty, null)
var args = new NodeParameters(TestCropImage1, logger, false, string.Empty, null!)
{
TempPath = TempDir
};
@@ -220,7 +220,7 @@ public class ImageNodesTests
public void ImageNodes_Basic_AutoCrop_02()
{
var logger = new TestLogger();
var args = new NodeParameters(TestCropImage2, logger, false, string.Empty, null)
var args = new NodeParameters(TestCropImage2, logger, false, string.Empty, null!)
{
TempPath = TempDir
};
@@ -237,7 +237,7 @@ public class ImageNodesTests
public void ImageNodes_Basic_AutoCrop_03()
{
var logger = new TestLogger();
var args = new NodeParameters(TestCropImage3, logger, false, string.Empty, null)
var args = new NodeParameters(TestCropImage3, logger, false, string.Empty, null!)
{
TempPath = TempDir
};
@@ -255,7 +255,7 @@ public class ImageNodesTests
public void ImageNodes_Basic_AutoCrop_04()
{
var logger = new TestLogger();
var args = new NodeParameters(TestCropImage4, logger, false, string.Empty, null)
var args = new NodeParameters(TestCropImage4, logger, false, string.Empty, null!)
{
TempPath = TempDir
};
@@ -279,7 +279,7 @@ public class ImageNodesTests
public void ImageNodes_Basic_AutoCrop_NoCrop()
{
var logger = new TestLogger();
var args = new NodeParameters(TestCropImageNoCrop, logger, false, string.Empty, null)
var args = new NodeParameters(TestCropImageNoCrop, logger, false, string.Empty, null!)
{
TempPath = TempDir
};
@@ -306,7 +306,7 @@ public class ImageNodesTests
var node = new ImageFile();
var result = node.Execute(args);
Assert.AreEqual(1, result);
if(node.Variables.TryGetValue("img.DateTaken", out object oDate) == false)
if(node.Variables.TryGetValue("img.DateTaken", out object? oDate) == false)
Assert.Fail("Failed to get date time");
if(oDate is DateTime dt == false)

View File

@@ -24,11 +24,13 @@ internal class TestLogger : ILogger
{
if (args == null || args.Length == 0)
return;
#pragma warning disable IL2026
string message = type + " -> " +
string.Join(", ", args.Select(x =>
x == null ? "null" :
x.GetType().IsPrimitive || x is string ? x.ToString() :
System.Text.Json.JsonSerializer.Serialize(x)));
#pragma warning restore IL2026
Messages.Add(message);
}

View File

@@ -17,8 +17,8 @@ public class LocalFileService : IFileService
/// <summary>
/// Gets or sets the allowed paths the file service can access
/// </summary>
public string[] AllowedPaths { get; init; }
public string[]? AllowedPaths { get; init; }
/// <summary>
/// Gets or sets a function for replacing variables in a string.
/// </summary>
@@ -26,7 +26,7 @@ public class LocalFileService : IFileService
/// The function takes a string input, a boolean indicating whether to strip missing variables,
/// and a boolean indicating whether to clean special characters.
/// </remarks>
public ReplaceVariablesDelegate ReplaceVariables { get; set; }
public ReplaceVariablesDelegate? ReplaceVariables { get; set; }
/// <summary>
/// Gets or sets the permissions to use for files
@@ -36,7 +36,7 @@ public class LocalFileService : IFileService
/// <summary>
/// Gets or sets the owner:group to use for files
/// </summary>
public string OwnerGroup { get; set; }
public string? OwnerGroup { get; set; }
/// <summary>
/// Gets or sets the logger used for logging
@@ -169,7 +169,7 @@ public class LocalFileService : IFileService
Name = fileInfo.Name,
FullName = fileInfo.FullName,
Length = fileInfo.Length,
Directory = fileInfo.DirectoryName
Directory = fileInfo.DirectoryName!
};
}
catch (Exception ex)
@@ -257,7 +257,7 @@ public class LocalFileService : IFileService
var fileInfo = new FileInfo(path);
if (fileInfo.Exists == false)
return Result<bool>.Fail("File does not exist");
var destDir = new FileInfo(destination).Directory;
var destDir = new FileInfo(destination).Directory!;
if (destDir.Exists == false)
{
destDir.Create();
@@ -286,7 +286,7 @@ public class LocalFileService : IFileService
if (fileInfo.Exists == false)
return Result<bool>.Fail("File does not exist");
var destDir = new FileInfo(destination).Directory;
var destDir = new FileInfo(destination).Directory!;
if (destDir.Exists == false)
{
destDir.Create();
@@ -435,7 +435,7 @@ public class LocalFileService : IFileService
return true;
}
public void SetPermissions(string path, int? permissions = null, Action<string> logMethod = null)
public void SetPermissions(string path, int? permissions = null, Action<string>? logMethod = null)
{
logMethod ??= (string message) => Logger?.ILog(message);
@@ -457,26 +457,9 @@ public class LocalFileService : IFileService
FileHelper.SetPermissions(logger, path, file: isFile, permissions: permissions);
FileHelper.ChangeOwner(logger, path, file: isFile, ownerGroup: OwnerGroup);
FileHelper.ChangeOwner(logger, path, file: isFile, ownerGroup: OwnerGroup ?? string.Empty);
logMethod(logger.ToString());
return;
if (OperatingSystem.IsLinux())
{
var filePermissions = FileHelper.ConvertLinuxPermissionsToUnixFileMode(permissions.Value);
if (filePermissions == UnixFileMode.None)
{
logMethod("SetPermissions: Invalid file permissions: " + permissions.Value);
return;
}
File.SetUnixFileMode(path, filePermissions);
logMethod($"SetPermissions: Permission [{filePermissions}] set on file: " + path);
}
}
}
#endif