Skip to content

Commit

Permalink
Merge pull request #3762 from kvpt/fix_directive_placement_setting
Browse files Browse the repository at this point in the history
Fix csharp_using_directive_placement setting retrieval
  • Loading branch information
sharwell authored Dec 27, 2023
2 parents 1b5a75a + d0ad21f commit 73b34ac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace StyleCop.Analyzers.Test.CSharp8.Settings
{
using System;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -172,6 +173,30 @@ public async Task VerifyInvalidReferenceBehaviorFromEditorConfigAsync()
Assert.Equal("[InvalidReference]", styleCopSettings.DocumentationRules.GetCopyrightText("unused"));
}

[Theory]
[InlineData("outside_namespace")]
[InlineData("inside_namespace")]
public async Task VerifyEditorConfigSettingsReadCorrectlyDirectivePlacementWithoutSeverityLevelAsync(string placement)
{
var expected = placement switch
{
"outside_namespace" => UsingDirectivesPlacement.OutsideNamespace,
"inside_namespace" => UsingDirectivesPlacement.InsideNamespace,
_ => throw new InvalidOperationException(),
};
var settings = $@"root = true
[*]
csharp_using_directive_placement = {placement}
";
var context = await this.CreateAnalysisContextFromEditorConfigAsync(settings).ConfigureAwait(false);

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

Assert.NotNull(styleCopSettings.OrderingRules);
Assert.Equal(expected, styleCopSettings.OrderingRules.UsingDirectivesPlacement);
}

protected virtual AnalyzerConfigOptionsProvider CreateAnalyzerConfigOptionsProvider(AnalyzerConfigSet analyzerConfigSet)
=> new TestAnalyzerConfigOptionsProvider(analyzerConfigSet);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ internal static string TryGetMultiLineStringValue(AnalyzerConfigOptionsWrapper a
{
return new KeyValuePair<string, string>(value.Substring(0, colonIndex), value.Substring(colonIndex + 1));
}

return new KeyValuePair<string, string>(value, string.Empty);
}

return null;
Expand Down

0 comments on commit 73b34ac

Please sign in to comment.