From 9de64fcd8535ed253a921c319e8e5230998232fc Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Fri, 9 Feb 2018 14:37:10 -0600 Subject: [PATCH] use consistent null conditional in rule linter --- .../RawRuleLinterExtensions.cs | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/FilterLists.Services/SnapshotService/RawRuleLinterExtensions.cs b/src/FilterLists.Services/SnapshotService/RawRuleLinterExtensions.cs index fae389377..b522641fb 100644 --- a/src/FilterLists.Services/SnapshotService/RawRuleLinterExtensions.cs +++ b/src/FilterLists.Services/SnapshotService/RawRuleLinterExtensions.cs @@ -4,12 +4,12 @@ public static class RawRuleLinterExtensions { public static string LintStringForMySql(this string rule) { - rule = rule.TrimLeadingAndTrailingWhitespace(); - rule = rule.DropIfEmpty(); - rule = rule.DropIfComment(); - rule = rule.DropIfTooLong(); - rule = rule.DropIfContainsBackslashSingleQuote(); - rule = rule.TrimSingleBackslashFromEnd(); + rule = rule?.TrimLeadingAndTrailingWhitespace(); + rule = rule?.DropIfEmpty(); + rule = rule?.DropIfComment(); + rule = rule?.DropIfTooLong(); + rule = rule?.DropIfContainsBackslashSingleQuote(); + rule = rule?.TrimSingleBackslashFromEnd(); return rule; } @@ -26,28 +26,22 @@ private static string DropIfEmpty(this string rule) private static string DropIfComment(this string rule) { - if (rule != null) - return rule.StartsWith(@"!") && !rule.StartsWith(@"!#") ? null : rule; - return null; + return rule.StartsWith(@"!") && !rule.StartsWith(@"!#") ? null : rule; } private static string DropIfTooLong(this string rule) { - return rule?.Length > 8192 ? null : rule; + return rule.Length > 8192 ? null : rule; } private static string DropIfContainsBackslashSingleQuote(this string rule) { - if (rule != null) - return rule.Contains(@"\'") ? null : rule; - return null; + return rule.Contains(@"\'") ? null : rule; } private static string TrimSingleBackslashFromEnd(this string rule) { - if (rule != null) - return rule.EndsWith(@"\") && !rule.EndsWith(@"\\") ? rule.Remove(rule.Length - 1) : rule; - return null; + return rule.EndsWith(@"\") && !rule.EndsWith(@"\\") ? rule.Remove(rule.Length - 1) : rule; } } } \ No newline at end of file