From 50f8c6874c5f94e0e91687b8776cebae2fe35c09 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Thu, 22 Aug 2024 11:52:16 -0500 Subject: [PATCH] Rename method to indicate use only in tests --- .../Settings/SettingsCSharp8UnitTests.cs | 16 +++++------ .../Settings/SettingsUnitTests.cs | 28 +++++++++---------- .../Settings/SettingsHelper.cs | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/Settings/SettingsCSharp8UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/Settings/SettingsCSharp8UnitTests.cs index b3826f2f7..3f74dfb43 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/Settings/SettingsCSharp8UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/Settings/SettingsCSharp8UnitTests.cs @@ -53,7 +53,7 @@ public async Task VerifyEditorConfigSettingsAreReadCorrectlyAsync() "; var context = await this.CreateAnalysisContextFromEditorConfigAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal("TestCompany", styleCopSettings.DocumentationRules.CompanyName); Assert.Equal("Custom copyright text.", styleCopSettings.DocumentationRules.GetCopyrightText("unused")); @@ -80,7 +80,7 @@ public async Task VerifyFileHeaderTemplateFromEditorConfigAsync() "; var context = await this.CreateAnalysisContextFromEditorConfigAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal("Line 1\nLine 2.", styleCopSettings.DocumentationRules.GetCopyrightText("unused")); } @@ -95,7 +95,7 @@ public async Task VerifyStyleCopDocumentationCopyrightTextFromEditorConfigAsync( "; var context = await this.CreateAnalysisContextFromEditorConfigAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal("Line 1\nLine 2.", styleCopSettings.DocumentationRules.GetCopyrightText("unused")); } @@ -116,7 +116,7 @@ public async Task VerifyBooleanDocumentationSettingsFromEditorConfigAsync(bool v "; var context = await this.CreateAnalysisContextFromEditorConfigAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal(value, styleCopSettings.DocumentationRules.DocumentExposedElements); Assert.Equal(value, styleCopSettings.DocumentationRules.DocumentInternalElements); @@ -137,7 +137,7 @@ public async Task VerifySettingsWillUseCompanyNameInDefaultCopyrightTextFromEdit "; var context = await this.CreateAnalysisContextFromEditorConfigAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal(companyName, styleCopSettings.DocumentationRules.CompanyName); Assert.Equal($"Copyright (c) {companyName}. All rights reserved.", styleCopSettings.DocumentationRules.GetCopyrightText("unused")); @@ -153,7 +153,7 @@ public async Task VerifyCircularReferenceBehaviorFromEditorConfigAsync() "; var context = await this.CreateAnalysisContextFromEditorConfigAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal("[CircularReference]", styleCopSettings.DocumentationRules.GetCopyrightText("unused")); } @@ -168,7 +168,7 @@ public async Task VerifyInvalidReferenceBehaviorFromEditorConfigAsync() "; var context = await this.CreateAnalysisContextFromEditorConfigAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal("[InvalidReference]", styleCopSettings.DocumentationRules.GetCopyrightText("unused")); } @@ -191,7 +191,7 @@ public async Task VerifyEditorConfigSettingsReadCorrectlyDirectivePlacementWitho "; var context = await this.CreateAnalysisContextFromEditorConfigAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.NotNull(styleCopSettings.OrderingRules); Assert.Equal(expected, styleCopSettings.OrderingRules.UsingDirectivesPlacement); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Settings/SettingsUnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Settings/SettingsUnitTests.cs index ac0f16e83..f28af26f2 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Settings/SettingsUnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Settings/SettingsUnitTests.cs @@ -26,7 +26,7 @@ public class SettingsUnitTests [Fact] public void VerifySettingsDefaults() { - var styleCopSettings = SettingsHelper.GetStyleCopSettings(default(SyntaxTreeAnalysisContext), CancellationToken.None); + var styleCopSettings = SettingsHelper.GetStyleCopSettingsInTests(default(SyntaxTreeAnalysisContext), CancellationToken.None); Assert.Equal("PlaceholderCompany", styleCopSettings.DocumentationRules.CompanyName); Assert.Equal("Copyright (c) PlaceholderCompany. All rights reserved.", styleCopSettings.DocumentationRules.GetCopyrightText("unused")); @@ -65,7 +65,7 @@ public async Task VerifyDefaultCultureIsReadCorrectlyAsync() "; var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal("en-US", styleCopSettings.DocumentationRules.DocumentationCulture); Assert.Same(CultureInfo.InvariantCulture, styleCopSettings.DocumentationRules.DocumentationCultureInfo); @@ -116,7 +116,7 @@ public async Task VerifySettingsAreReadCorrectlyAsync() "; var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal("TestCompany", styleCopSettings.DocumentationRules.CompanyName); Assert.Equal("Custom copyright text.", styleCopSettings.DocumentationRules.GetCopyrightText("unused")); @@ -159,7 +159,7 @@ public async Task VerifyBooleanDocumentationSettingsAsync(bool value) "; var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal(value, styleCopSettings.DocumentationRules.DocumentExposedElements); Assert.Equal(value, styleCopSettings.DocumentationRules.DocumentInternalElements); @@ -189,7 +189,7 @@ public async Task VerifyDocumentationVariablesAsync() "; var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Single(styleCopSettings.DocumentationRules.Variables); Assert.Equal("value", styleCopSettings.DocumentationRules.Variables["var"]); @@ -217,7 +217,7 @@ public async Task VerifySettingsWillUseCompanyNameInDefaultCopyrightTextAsync(st "; var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal(companyName, styleCopSettings.DocumentationRules.CompanyName); Assert.Equal($"Copyright (c) {companyName}. All rights reserved.", styleCopSettings.DocumentationRules.GetCopyrightText("unused")); @@ -237,7 +237,7 @@ public async Task VerifyCircularReferenceBehaviorAsync() "; var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal("[CircularReference]", styleCopSettings.DocumentationRules.GetCopyrightText("unused")); } @@ -256,7 +256,7 @@ public async Task VerifyInvalidReferenceBehaviorAsync() "; var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal("[InvalidReference]", styleCopSettings.DocumentationRules.GetCopyrightText("unused")); } @@ -280,7 +280,7 @@ public async Task VerifySettingsSupportsLineCommentsAsync() "; var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal("TestCompany", styleCopSettings.DocumentationRules.CompanyName); Assert.Equal("Copyright (c) TestCompany. All rights reserved.", styleCopSettings.DocumentationRules.GetCopyrightText("unused")); @@ -307,7 +307,7 @@ public async Task VerifySettingsSupportsBlockCommentsAsync() "; var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal("TestCompany", styleCopSettings.DocumentationRules.CompanyName); Assert.Equal("Copyright (c) TestCompany. All rights reserved.", styleCopSettings.DocumentationRules.GetCopyrightText("unused")); @@ -334,7 +334,7 @@ public async Task VerifySettingsSupportsTrailingCommasAsync() "; var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal("TestCompany", styleCopSettings.DocumentationRules.CompanyName); Assert.Equal("Copyright (c) TestCompany. All rights reserved.", styleCopSettings.DocumentationRules.GetCopyrightText("unused")); @@ -357,7 +357,7 @@ public async Task VerifySettingsFileNameSupportsDotPrefixAsync() "; var context = await CreateAnalysisContextAsync(settings, ".stylecop.json").ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); Assert.Equal("TestCompany", styleCopSettings.DocumentationRules.CompanyName); } @@ -368,7 +368,7 @@ public async Task VerifyInvalidJsonBehaviorAsync() var settings = @"This is not a JSON file."; var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); // The result is the same as the default settings. Assert.Equal("PlaceholderCompany", styleCopSettings.DocumentationRules.CompanyName); @@ -381,7 +381,7 @@ public async Task VerifyEmptyOrMissingFileAsync() var settings = string.Empty; var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false); - var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None); + var styleCopSettings = context.GetStyleCopSettingsInTests(CancellationToken.None); // The result is the same as the default settings. Assert.Equal("PlaceholderCompany", styleCopSettings.DocumentationRules.CompanyName); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs index 4e66c183b..6b9c4c2e7 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs @@ -110,7 +110,7 @@ internal static StyleCopSettings GetStyleCopSettings(this SyntaxTreeAnalysisCont /// The context that will be used to determine the StyleCop settings. /// The cancellation token that the operation will observe. /// A instance that represents the StyleCop settings for the given context. - internal static StyleCopSettings GetStyleCopSettings(this SyntaxTreeAnalysisContext context, CancellationToken cancellationToken) + internal static StyleCopSettings GetStyleCopSettingsInTests(this SyntaxTreeAnalysisContext context, CancellationToken cancellationToken) { var settingsFile = GetSettingsFile(context.Options, ParseJson, cancellationToken); return GetSettings(context.Options, settingsStorage: new StrongBox(), context.Tree, settingsFile, DeserializationFailureBehavior.ReturnDefaultSettings);