Browse Source

Cosmetics

Piotr Czajkowski 3 months ago
parent
commit
6d35ec03e8

+ 15 - 20
ProcessFiles/ProcessFiles.cs

@@ -14,7 +14,7 @@ namespace ProcessFiles
 
     public static class ProcessFiles
     {
-        private static List<string> _errors = new();
+        private static List<string> errors = new();
 
         private static Result WhatIsIt(string path)
         {
@@ -28,21 +28,18 @@ namespace ProcessFiles
             }
             catch (Exception e)
             {
-                _errors.Add(e.ToString());
+                errors.Add(e.ToString());
                 return Result.Failure;
             }
         }
 
         private static string? GetExtension(string path)
         {
-            var extension = Path.GetExtension(path)?.TrimStart('.');
-            if (string.IsNullOrWhiteSpace(extension))
-            {
-                _errors.Add($"Can't establish extension of {path}!");
-                return null;
-            }
-
-            return extension;
+            var extension = Path.GetExtension(path).TrimStart('.');
+            if (!string.IsNullOrWhiteSpace(extension)) return extension;
+            
+            errors.Add($"Can't establish extension of {path}!");
+            return null;
         }
 
         private static bool CheckExtension(string extension, string[] validExtensions)
@@ -60,7 +57,7 @@ namespace ProcessFiles
         {
             if (!File.Exists(path))
             {
-                _errors.Add($"{path} doesn't exist!");
+                errors.Add($"{path} doesn't exist!");
                 return false;
             }
 
@@ -70,7 +67,7 @@ namespace ProcessFiles
 
             if (!CheckExtension(extension, fileExtensions))
             {
-                _errors.Add($"Extension of {path} doesn't match any extension ({string.Join(", ", fileExtensions)})!");
+                errors.Add($"Extension of {path} doesn't match any extension ({string.Join(", ", fileExtensions)})!");
                 return false;
             }
 
@@ -85,7 +82,7 @@ namespace ProcessFiles
             }
             catch (Exception e)
             {
-                _errors.Add($"{path}:\n{e}");
+                errors.Add($"{path}:\n{e}");
             }
         }
 
@@ -101,7 +98,7 @@ namespace ProcessFiles
         {
             if (!Directory.Exists(path))
             {
-                _errors.Add($"{path} doesn't exist!");
+                errors.Add($"{path} doesn't exist!");
                 return;
             }
 
@@ -119,7 +116,7 @@ namespace ProcessFiles
 
             if (!files.Any())
             {
-                _errors.Add($"There are no files in {path} with given extensions ({string.Join(", ", fileExtensions)})!");
+                errors.Add($"There are no files in {path} with given extensions ({string.Join(", ", fileExtensions)})!");
                 return;
             }
 
@@ -129,12 +126,12 @@ namespace ProcessFiles
 
         public static IEnumerable<string> Process(IEnumerable<string> arguments, string fileExtension, Action<string> action, bool recursive = false)
         {
-            return Process(arguments, new string[] {fileExtension}, action, recursive);
+            return Process(arguments, new[] {fileExtension}, action, recursive);
         }
 
         public static IEnumerable<string> Process(IEnumerable<string> arguments, string[] fileExtensions, Action<string> action, bool recursive = false)
         {
-            _errors = new List<string>();
+            errors = new List<string>();
 
             foreach (var argument in arguments)
             {
@@ -148,12 +145,10 @@ namespace ProcessFiles
                         break;
                     case Result.Failure:
                         continue;
-                    default:
-                        break;
                 }
             }
 
-            return _errors;
+            return errors;
         }
     }
 }

+ 1 - 1
ProcessFiles/ProcessFiles.csproj

@@ -1,8 +1,8 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFrameworks>net6</TargetFrameworks>
     <Nullable>enable</Nullable>
+    <TargetFramework>net6.0</TargetFramework>
   </PropertyGroup>
 
 </Project>

+ 1 - 1
ProcessFilesTests/ProcessFilesTests.cs

@@ -135,7 +135,7 @@ namespace ProcessFilesTests
                 result.Add(Path.GetFileName(value));
             }
 
-            var errors = ProcessFiles.ProcessFiles.Process(new[] { testFolder }, new string[] { "txt", "json" }, TestAction, true);
+            var errors = ProcessFiles.ProcessFiles.Process(new[] { testFolder }, new[] { "txt", "json" }, TestAction, true);
             Assert.Empty(errors);
             Assert.True(CheckResult(result, expectedInSubFolderMultipleExtensions));
         }

+ 2 - 0
ProcessFilesTests/ProcessFilesTests.csproj

@@ -4,6 +4,8 @@
     <TargetFramework>net6.0</TargetFramework>
 
     <IsPackable>false</IsPackable>
+
+    <OutputType>Library</OutputType>
   </PropertyGroup>
 
   <ItemGroup>