use consistent null conditional in rule linter

This commit is contained in:
Collin M. Barrett 2018-02-09 14:37:10 -06:00
parent 282f9cecf8
commit 9de64fcd85

View file

@ -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;
}
}
}