Skip to content

Commit

Permalink
Merge 83f80a2 into ccaac20
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornhellander authored Apr 15, 2023
2 parents ccaac20 + 83f80a2 commit ad0c737
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ internal class DocumentationSettings
/// </summary>
internal static readonly ImmutableArray<string> DefaultExcludeFromPunctuationCheck = ImmutableArray.Create("seealso");

/// <summary>
/// A Regex instance matching valid variable names.
/// </summary>
private static readonly Regex ValidVariableNameRegex = new Regex("^[a-zA-Z0-9]+$");

/// <summary>
/// This is the backing field for the <see cref="CompanyName"/> property.
/// </summary>
Expand Down Expand Up @@ -199,7 +204,7 @@ protected internal DocumentationSettings(JsonObject documentationSettingsObject,
{
string name = child.Key;

if (!Regex.IsMatch(name, "^[a-zA-Z0-9]+$"))
if (!ValidVariableNameRegex.IsMatch(name))
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace StyleCop.Analyzers.Settings.ObjectModel

internal class NamingSettings
{
private static readonly Regex ValidHungarianPrefixRegex = new Regex("^[a-z]{1,2}$");

/// <summary>
/// Initializes a new instance of the <see cref="NamingSettings"/> class.
/// </summary>
Expand Down Expand Up @@ -55,7 +57,7 @@ protected internal NamingSettings(JsonObject namingSettingsObject, AnalyzerConfi
{
var prefix = prefixJsonValue.ToStringValue(kvp.Key);

if (!Regex.IsMatch(prefix, "^[a-z]{1,2}$"))
if (!ValidHungarianPrefixRegex.IsMatch(prefix))
{
continue;
}
Expand Down Expand Up @@ -86,7 +88,7 @@ protected internal NamingSettings(JsonObject namingSettingsObject, AnalyzerConfi

allowCommonHungarianPrefixes ??= AnalyzerConfigHelper.TryGetBooleanValue(analyzerConfigOptions, "stylecop.naming.allowCommonHungarianPrefixes");
allowedHungarianPrefixes ??= AnalyzerConfigHelper.TryGetStringListValue(analyzerConfigOptions, "stylecop.naming.allowedHungarianPrefixes")
?.Where(value => Regex.IsMatch(value, "^[a-z]{1,2}$"))
?.Where(value => ValidHungarianPrefixRegex.IsMatch(value))
.ToImmutableArray()
.ToBuilder();
allowedNamespaceComponents ??= AnalyzerConfigHelper.TryGetStringListValue(analyzerConfigOptions, "stylecop.naming.allowedNamespaceComponents")?.ToBuilder();
Expand Down

0 comments on commit ad0c737

Please sign in to comment.