Skip to content

Commit

Permalink
Merge pull request #3617 from bjornhellander/feature/file_header_temp…
Browse files Browse the repository at this point in the history
…late

Update reading of file_header_template and stylecop.documentation.copyrightText to allow multiple lines
  • Loading branch information
sharwell committed Mar 21, 2023
2 parents 73bc6cf + c569611 commit 84e2324
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,36 @@ public async Task VerifyEditorConfigSettingsAreReadCorrectlyAsync()
Assert.Equal(OptionSetting.Allow, styleCopSettings.OrderingRules.BlankLinesBetweenUsingGroups);
}

[Fact]
public async Task VerifyFileHeaderTemplateFromEditorConfigAsync()
{
var settings = @"root = true
[*]
file_header_template = Line 1\nLine 2.
";
var context = await this.CreateAnalysisContextFromEditorConfigAsync(settings).ConfigureAwait(false);

var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None);

Assert.Equal("Line 1\nLine 2.", styleCopSettings.DocumentationRules.GetCopyrightText("unused"));
}

[Fact]
public async Task VerifyStyleCopDocumentationCopyrightTextFromEditorConfigAsync()
{
var settings = @"root = true
[*]
stylecop.documentation.copyrightText = Line 1\nLine 2.
";
var context = await this.CreateAnalysisContextFromEditorConfigAsync(settings).ConfigureAwait(false);

var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None);

Assert.Equal("Line 1\nLine 2.", styleCopSettings.DocumentationRules.GetCopyrightText("unused"));
}

[Theory]
[CombinatorialData]
public async Task VerifyBooleanDocumentationSettingsFromEditorConfigAsync(bool value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ internal static string TryGetStringValue(AnalyzerConfigOptionsWrapper analyzerCo
return null;
}

internal static string TryGetMultiLineStringValue(AnalyzerConfigOptionsWrapper analyzerConfigOptions, string key, bool allowExplicitUnset = true)
{
var orgValue = TryGetStringValue(analyzerConfigOptions, key, allowExplicitUnset);
return orgValue?.Replace("\\r", "\r").Replace("\\n", "\n");
}

internal static KeyValuePair<string, string>? TryGetStringValueAndNotification(AnalyzerConfigOptionsWrapper analyzerConfigOptions, string key, bool allowExplicitUnset = true)
{
if (analyzerConfigOptions.TryGetValue(key, out var value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ protected internal DocumentationSettings(JsonObject documentationSettingsObject,
documentPrivateFields ??= AnalyzerConfigHelper.TryGetBooleanValue(analyzerConfigOptions, "stylecop.documentation.documentPrivateFields");

companyName ??= AnalyzerConfigHelper.TryGetStringValue(analyzerConfigOptions, "stylecop.documentation.companyName");
copyrightText ??= AnalyzerConfigHelper.TryGetStringValue(analyzerConfigOptions, "stylecop.documentation.copyrightText")
?? AnalyzerConfigHelper.TryGetStringValue(analyzerConfigOptions, "file_header_template");
copyrightText ??= AnalyzerConfigHelper.TryGetMultiLineStringValue(analyzerConfigOptions, "stylecop.documentation.copyrightText")
?? AnalyzerConfigHelper.TryGetMultiLineStringValue(analyzerConfigOptions, "file_header_template");
headerDecoration ??= AnalyzerConfigHelper.TryGetStringValue(analyzerConfigOptions, "stylecop.documentation.headerDecoration");

xmlHeader ??= AnalyzerConfigHelper.TryGetBooleanValue(analyzerConfigOptions, "stylecop.documentation.xmlHeader");
Expand Down

0 comments on commit 84e2324

Please sign in to comment.