chore(sonar): hoist constant array literals to static readonly fields (CA1861)
Applied via `dotnet format analyzers --diagnostics CA1861 --severity info`,
plus manual cleanup:
- Renamed two cryptic fixer-generated field names:
- QueryBreakdownCollection.stringArray -> SnowflakeFunctionNames (and
inlined the now-redundant local alias)
- ExpressionObjectTests.arg2 -> NotInValues
- Deduped three identical `separator = ['\r','\n']` fields the fixer
emitted in the same test class (kept the first declaration; the other
two test methods now reuse it).
8 files touched.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
84b06557e5
commit
f5d539b906
@@ -182,6 +182,15 @@ public class QueryBreakdownCollection : SqlServer.QueryBreakdownCollectionBase<Q
|
||||
});
|
||||
}
|
||||
|
||||
private static readonly string[] SnowflakeFunctionNames =
|
||||
[
|
||||
"PARSE_JSON", "OBJECT_INSERT", "ARRAY_CONSTRUCT", "ARRAY_AGG",
|
||||
"FLATTEN", "GET_PATH", "TRY_PARSE_JSON", "JSON_EXTRACT_PATH_TEXT",
|
||||
"JSON_EXTRACT_PATH_WITH_DEFAULT", "HASHAGGREGATE", "LISTAGG",
|
||||
"APPROX_COUNT_DISTINCT", "APPROX_PERCENTILE", "GREATEST", "LEAST",
|
||||
"NULLIF", "ZEROIFNULL", "STRTOK", "SPLIT_PART", "PIVOT", "UNPIVOT"
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Filters queries that use Snowflake functions (PARSE_JSON, OBJECT_INSERT, ARRAY, etc.).
|
||||
/// </summary>
|
||||
@@ -191,17 +200,7 @@ public class QueryBreakdownCollection : SqlServer.QueryBreakdownCollectionBase<Q
|
||||
return QueryBreakdownList.Where(q =>
|
||||
{
|
||||
var sql = q.GetSql().ToUpperInvariant();
|
||||
|
||||
var snowflakeFunctions = new[]
|
||||
{
|
||||
"PARSE_JSON", "OBJECT_INSERT", "ARRAY_CONSTRUCT", "ARRAY_AGG",
|
||||
"FLATTEN", "GET_PATH", "TRY_PARSE_JSON", "JSON_EXTRACT_PATH_TEXT",
|
||||
"JSON_EXTRACT_PATH_WITH_DEFAULT", "HASHAGGREGATE", "LISTAGG",
|
||||
"APPROX_COUNT_DISTINCT", "APPROX_PERCENTILE", "GREATEST", "LEAST",
|
||||
"NULLIF", "ZEROIFNULL", "STRTOK", "SPLIT_PART", "PIVOT", "UNPIVOT"
|
||||
};
|
||||
|
||||
return snowflakeFunctions.Any(func => sql.Contains(func));
|
||||
return SnowflakeFunctionNames.Any(func => sql.Contains(func));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ public static partial class SqlUtils
|
||||
public const string DATETIME_INSERT_FORMAT = "yyyyMMdd HH:mm:ss";
|
||||
|
||||
private const string DEFAULT_SCHEMA = "dbo";
|
||||
private static readonly char[] separator = new[] { ',' };
|
||||
|
||||
#region SQL String Manipulation
|
||||
|
||||
@@ -34,7 +35,7 @@ public static partial class SqlUtils
|
||||
public static string StripColumnTableAlias(string sql)
|
||||
{
|
||||
// Break sql into words and remove "abc." from each column
|
||||
string[] commaWords = sql.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] commaWords = sql.Split(separator, StringSplitOptions.RemoveEmptyEntries);
|
||||
var newParts = new List<string>();
|
||||
|
||||
foreach (string commaWord in commaWords)
|
||||
|
||||
@@ -21,6 +21,7 @@ public class StatementParser
|
||||
public const string KeywordGroupBy = "GROUP BY";
|
||||
public const string KeywordHaving = "HAVING";
|
||||
public const string KeywordOrderBy = "ORDER BY";
|
||||
private static readonly char[] separator = new[] { '\r', '\n' };
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -50,7 +51,7 @@ public class StatementParser
|
||||
// Replace multiple spaces/tabs with single space, but preserve newlines for comment handling
|
||||
sql = Regex.Replace(sql, @"[ \t]+", " ", RegexOptions.None, RegexDefaults.MatchTimeout);
|
||||
// Remove leading/trailing whitespace from each line
|
||||
var lines = sql.Split(new[] { '\r', '\n' }, StringSplitOptions.None);
|
||||
var lines = sql.Split(separator, StringSplitOptions.None);
|
||||
sql = string.Join("\n", lines.Select(line => line.Trim()));
|
||||
return sql.Trim();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user