diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs index 1a712ea12b3752ac5e08f4112944ea691d3dfde5..c127856e9f884684df72356618617fee9905d409 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs @@ -49,15 +49,15 @@ public async Task TestPascalCaseClass_NameGetsCapitalized() [InlineData("M_bar", "bar")] [InlineData("S_bar", "bar")] [InlineData("T_bar", "bar")] - [InlineData("_Bar", "bar", Skip = "https://github.com/dotnet/roslyn/issues/26588")] - [InlineData("__Bar", "bar", Skip = "https://github.com/dotnet/roslyn/issues/26588")] + [InlineData("_Bar", "bar")] + [InlineData("__Bar", "bar")] [InlineData("M_s__t_Bar", "bar")] - [InlineData("m_bar", "bar", Skip = "https://github.com/dotnet/roslyn/issues/26588")] - [InlineData("s_bar", "bar", Skip = "https://github.com/dotnet/roslyn/issues/26588")] - [InlineData("t_bar", "bar", Skip = "https://github.com/dotnet/roslyn/issues/26588")] - [InlineData("_bar", "bar", Skip = "https://github.com/dotnet/roslyn/issues/26588")] - [InlineData("__bar", "bar", Skip = "https://github.com/dotnet/roslyn/issues/26588")] - [InlineData("m_s__t_Bar", "bar", Skip = "https://github.com/dotnet/roslyn/issues/26588")] + [InlineData("m_bar", "bar")] + [InlineData("s_bar", "bar")] + [InlineData("t_bar", "bar")] + [InlineData("_bar", "bar")] + [InlineData("__bar", "bar")] + [InlineData("m_s__t_Bar", "bar")] // Special cases to ensure empty identifiers are not produced [InlineData("M_", "m_")] [InlineData("M__", "_")] @@ -83,14 +83,14 @@ public async Task TestCamelCaseField_PrefixGetsStripped(string fieldName, string [InlineData("S_bar", "_bar")] [InlineData("T_bar", "_bar")] [InlineData("_Bar", "_bar")] - [InlineData("__Bar", "_bar", Skip = "https://github.com/dotnet/roslyn/issues/26588")] + [InlineData("__Bar", "_bar")] [InlineData("M_s__t_Bar", "_bar")] [InlineData("m_bar", "_bar")] [InlineData("s_bar", "_bar")] [InlineData("t_bar", "_bar")] [InlineData("bar", "_bar")] - [InlineData("__bar", "_bar", Skip = "https://github.com/dotnet/roslyn/issues/26588")] - [InlineData("__s_bar", "_bar", Skip = "https://github.com/dotnet/roslyn/issues/26588")] + [InlineData("__bar", "_bar")] + [InlineData("__s_bar", "_bar")] [InlineData("m_s__t_Bar", "_bar")] // Special cases to ensure empty identifiers are not produced [InlineData("M_", "_m_")] diff --git a/src/EditorFeatures/Test2/Diagnostics/NamingStyles/NamingStyleTests.IdentifierCreation.Compliance.vb b/src/EditorFeatures/Test2/Diagnostics/NamingStyles/NamingStyleTests.IdentifierCreation.Compliance.vb index d24e93894f2221d30aee481c84e145985f564595..f08a954f2a98d18ad038e9b86e2f0fc2f5fa0acd 100644 --- a/src/EditorFeatures/Test2/Diagnostics/NamingStyles/NamingStyleTests.IdentifierCreation.Compliance.vb +++ b/src/EditorFeatures/Test2/Diagnostics/NamingStyles/NamingStyleTests.IdentifierCreation.Compliance.vb @@ -32,7 +32,7 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.Diagnostics.UnitTests Public Sub TestManyEmptyWords() Dim namingStyle = CreateNamingStyle(wordSeparator:="_", capitalizationScheme:=Capitalization.PascalCase) - TestNameCompliance(namingStyle, "_____") + TestNameNoncomplianceAndFixedNames(namingStyle, "_____", "_") End Sub @@ -40,6 +40,18 @@ Namespace Microsoft.CodeAnalysis.Editor.Implementation.Diagnostics.UnitTests Dim namingStyle = CreateNamingStyle(prefix:="p_", suffix:="_s", capitalizationScheme:=Capitalization.PascalCase) TestNameNoncomplianceAndFixedNames(namingStyle, "_", "p_s", "p___s") End Sub + + + Public Sub TestPrefixAndCommonPrefix() + Dim namingStyle = CreateNamingStyle(prefix:="Test_", suffix:="_z", capitalizationScheme:=Capitalization.PascalCase) + TestNameNoncomplianceAndFixedNames(namingStyle, "Test_m_BaseName", "Test_M_BaseName_z", "Test_BaseName_z") + End Sub + + + Public Sub TestCommonPrefixAndPrefix() + Dim namingStyle = CreateNamingStyle(prefix:="Test_", suffix:="_z", capitalizationScheme:=Capitalization.PascalCase) + TestNameNoncomplianceAndFixedNames(namingStyle, "m_Test_BaseName", "Test_BaseName_z") + End Sub #End Region #Region "PascalCase" diff --git a/src/Workspaces/Core/Portable/NamingStyles/NamingStyle.cs b/src/Workspaces/Core/Portable/NamingStyles/NamingStyle.cs index 884ae882d6093b8d4234ef4719ef5696fd691075..d02379686137ea72f0022d6a3d81fa8c834a94be 100644 --- a/src/Workspaces/Core/Portable/NamingStyles/NamingStyle.cs +++ b/src/Workspaces/Core/Portable/NamingStyles/NamingStyle.cs @@ -139,11 +139,28 @@ public bool IsNameCompliant(string name, out string failureReason) if (name.Length <= Prefix.Length + Suffix.Length) { + // name consists of Prefix and Suffix and no base name + // Prefix and Suffix can overlap + // Example: Prefix = "s_", Suffix = "_t", name "s_t" failureReason = null; return true; } - var spanToCheck = TextSpan.FromBounds(Prefix.Length, name.Length - Suffix.Length); + // remove specified Prefix, then look for any other common prefixes + name = StripCommonPrefixes(name.Substring(Prefix.Length), out var prefix); + + if (prefix != string.Empty) + { + // name started with specified prefix, but has at least one additional common prefix + // Example: specified prefix "test_", actual prefix "test_m_" + failureReason = Prefix == string.Empty ? + string.Format(WorkspacesResources.Prefix_0_is_not_expected, prefix) : + string.Format(WorkspacesResources.Prefix_0_does_not_match_expected_prefix_1, prefix, Prefix); + return false; + } + + // specified and common prefixes have been removed. Now see that the base name has correct capitalization + var spanToCheck = TextSpan.FromBounds(0, name.Length - Suffix.Length); Debug.Assert(spanToCheck.Length > 0); switch (CapitalizationScheme) @@ -295,6 +312,10 @@ private bool CheckFirstUpper(string name, TextSpan nameSpan, out string reason) private string CreateCompliantNameDirectly(string name) { + // Example: for specified prefix = "Test_" and name = "Test_m_BaseName", we remove "Test_m_" + // "Test_" will be added back later in this method + name = StripCommonPrefixes(name.StartsWith(Prefix) ? name.Substring(Prefix.Length) : name, out _); + var addPrefix = !name.StartsWith(Prefix); var addSuffix = !name.EndsWith(Suffix); @@ -318,14 +339,14 @@ public IEnumerable MakeCompliant(string name) private string CreateCompliantNameReusingPartialPrefixesAndSuffixes(string name) { - name = StripCommonPrefixes(name); + name = StripCommonPrefixes(name, out _); name = EnsurePrefix(name); name = EnsureSuffix(name); return FinishFixingName(name); } - private static string StripCommonPrefixes(string name) + private static string StripCommonPrefixes(string name, out string prefix) { var index = 0; while (index + 1 < name.Length) @@ -355,6 +376,7 @@ private static string StripCommonPrefixes(string name) break; } + prefix = name.Substring(0, index); return name.Substring(index); } @@ -368,10 +390,17 @@ private string FinishFixingName(string name) name = name.Substring(Prefix.Length, name.Length - Suffix.Length - Prefix.Length); IEnumerable words = new[] { name }; + if (!string.IsNullOrEmpty(WordSeparator)) { words = name.Split(new[] { WordSeparator }, StringSplitOptions.RemoveEmptyEntries); + // Edge case: the only character(s) in the name is(are) the WordSeparator + if (words.Count() == 0) + { + return name; + } + if (words.Count() == 1) // Only Split if words have not been split before { bool isWord = true; diff --git a/src/Workspaces/Core/Portable/WorkspacesResources.Designer.cs b/src/Workspaces/Core/Portable/WorkspacesResources.Designer.cs index b4a1171d59afa42bda346ef955241d4e20d547c0..0ccdafdac41cb0bce2ac4cd57288aefdc0f2c1bc 100644 --- a/src/Workspaces/Core/Portable/WorkspacesResources.Designer.cs +++ b/src/Workspaces/Core/Portable/WorkspacesResources.Designer.cs @@ -1276,6 +1276,24 @@ internal class WorkspacesResources { } } + /// + /// Looks up a localized string similar to Prefix '{0}' does not match expected prefix '{1}'. + /// + internal static string Prefix_0_does_not_match_expected_prefix_1 { + get { + return ResourceManager.GetString("Prefix_0_does_not_match_expected_prefix_1", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Prefix '{0}' is not expected. + /// + internal static string Prefix_0_is_not_expected { + get { + return ResourceManager.GetString("Prefix_0_is_not_expected", resourceCulture); + } + } + /// /// Looks up a localized string similar to Private Method. /// diff --git a/src/Workspaces/Core/Portable/WorkspacesResources.resx b/src/Workspaces/Core/Portable/WorkspacesResources.resx index 4a2bfa4ee2569f774e4a8b80e01000e12f6aeae4..a4eceb6b93ecade3723aae05c61a024a312f98ca 100644 --- a/src/Workspaces/Core/Portable/WorkspacesResources.resx +++ b/src/Workspaces/Core/Portable/WorkspacesResources.resx @@ -807,6 +807,12 @@ Parameter preferences + + Prefix '{0}' does not match expected prefix '{1}' + + + Prefix '{0}' is not expected + DateTimeKind must be Utc diff --git a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.cs.xlf b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.cs.xlf index 6efa06555cc8cda595b24bb86413b4752b2391ee..d8b8082953308bfc2e65f3333d19d5726ce8441e 100644 --- a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.cs.xlf +++ b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.cs.xlf @@ -72,6 +72,16 @@ Parentheses preferences + + Prefix '{0}' does not match expected prefix '{1}' + Prefix '{0}' does not match expected prefix '{1}' + + + + Prefix '{0}' is not expected + Prefix '{0}' is not expected + + Refactoring Only Pouze refaktoring diff --git a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.de.xlf b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.de.xlf index 16fdef8025625e6f32fbefd98b5fe5968c3dfe65..0b6ed433a4af7ffbb7d6ae6d55025182f3c6f766 100644 --- a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.de.xlf +++ b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.de.xlf @@ -72,6 +72,16 @@ Parentheses preferences + + Prefix '{0}' does not match expected prefix '{1}' + Prefix '{0}' does not match expected prefix '{1}' + + + + Prefix '{0}' is not expected + Prefix '{0}' is not expected + + Refactoring Only Nur Refactoring diff --git a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.es.xlf b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.es.xlf index 321e02e025c0964faec2b31b939372e51de2713c..7fff49e57896d23054c07372e0e959003f0e024b 100644 --- a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.es.xlf +++ b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.es.xlf @@ -72,6 +72,16 @@ Parentheses preferences + + Prefix '{0}' does not match expected prefix '{1}' + Prefix '{0}' does not match expected prefix '{1}' + + + + Prefix '{0}' is not expected + Prefix '{0}' is not expected + + Refactoring Only Solo refactorización diff --git a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.fr.xlf b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.fr.xlf index b2f3d119ea68a02fdff469af2d419c9d784977aa..d5ce73cd51e4bad64bd10effe95cea758649e5a0 100644 --- a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.fr.xlf +++ b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.fr.xlf @@ -72,6 +72,16 @@ Parentheses preferences + + Prefix '{0}' does not match expected prefix '{1}' + Prefix '{0}' does not match expected prefix '{1}' + + + + Prefix '{0}' is not expected + Prefix '{0}' is not expected + + Refactoring Only Refactorisation uniquement diff --git a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.it.xlf b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.it.xlf index 2f0dddf3059f84849215774ff043306907dbc54f..b0019c1d5426a4fdfdcb0402d7a6e4782662a041 100644 --- a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.it.xlf +++ b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.it.xlf @@ -72,6 +72,16 @@ Parentheses preferences + + Prefix '{0}' does not match expected prefix '{1}' + Prefix '{0}' does not match expected prefix '{1}' + + + + Prefix '{0}' is not expected + Prefix '{0}' is not expected + + Refactoring Only Solo refactoring diff --git a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.ja.xlf b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.ja.xlf index f6f06127088bdf2f5c65ac05bf944c9ef7b09a45..cdc6bfafeaf1522f66626f82c44af04f571b49ab 100644 --- a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.ja.xlf +++ b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.ja.xlf @@ -72,6 +72,16 @@ Parentheses preferences + + Prefix '{0}' does not match expected prefix '{1}' + Prefix '{0}' does not match expected prefix '{1}' + + + + Prefix '{0}' is not expected + Prefix '{0}' is not expected + + Refactoring Only リファクタリングのみ diff --git a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.ko.xlf b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.ko.xlf index 610cf86ea9c45b31bc45f4878b16f9ecba01ecdf..41416a2802fd42b9f2cc0445822154f7ebcd9a5a 100644 --- a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.ko.xlf +++ b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.ko.xlf @@ -72,6 +72,16 @@ Parentheses preferences + + Prefix '{0}' does not match expected prefix '{1}' + Prefix '{0}' does not match expected prefix '{1}' + + + + Prefix '{0}' is not expected + Prefix '{0}' is not expected + + Refactoring Only 리팩터링만 diff --git a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.pl.xlf b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.pl.xlf index e2138f520ef023ebd4c1d6a2f4dc6b7f5b47b12d..9b8e45eed65222b7666b558d571cf14bbc644df8 100644 --- a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.pl.xlf +++ b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.pl.xlf @@ -72,6 +72,16 @@ Parentheses preferences + + Prefix '{0}' does not match expected prefix '{1}' + Prefix '{0}' does not match expected prefix '{1}' + + + + Prefix '{0}' is not expected + Prefix '{0}' is not expected + + Refactoring Only Tylko refaktoryzacja diff --git a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.pt-BR.xlf b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.pt-BR.xlf index 3d587769cccfda2a1f1059d15b664ee7b347addb..a2f8879b4881fde64e61df27ddaba6026e588db4 100644 --- a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.pt-BR.xlf +++ b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.pt-BR.xlf @@ -72,6 +72,16 @@ Parentheses preferences + + Prefix '{0}' does not match expected prefix '{1}' + Prefix '{0}' does not match expected prefix '{1}' + + + + Prefix '{0}' is not expected + Prefix '{0}' is not expected + + Refactoring Only Somente Refatoração diff --git a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.ru.xlf b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.ru.xlf index f8c8eb7b14d1abc393aa34ec9262b577c0262abc..5b362fa113737f25e7063decdee7dd71aa3551e7 100644 --- a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.ru.xlf +++ b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.ru.xlf @@ -72,6 +72,16 @@ Parentheses preferences + + Prefix '{0}' does not match expected prefix '{1}' + Prefix '{0}' does not match expected prefix '{1}' + + + + Prefix '{0}' is not expected + Prefix '{0}' is not expected + + Refactoring Only Только рефакторинг diff --git a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.tr.xlf b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.tr.xlf index 2fc22f373081c44e25b0b4ed928cbb036404523b..915a10e0e708dfe4e0126629334f2ad72f32422b 100644 --- a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.tr.xlf +++ b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.tr.xlf @@ -72,6 +72,16 @@ Parentheses preferences + + Prefix '{0}' does not match expected prefix '{1}' + Prefix '{0}' does not match expected prefix '{1}' + + + + Prefix '{0}' is not expected + Prefix '{0}' is not expected + + Refactoring Only Sadece Yeniden Düzenlenme diff --git a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.zh-Hans.xlf b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.zh-Hans.xlf index cefbfd30958f4743b1b157247c07c4dc09f0bc7c..7581521fd83df7bf753d6655cc42fb533f0b9aca 100644 --- a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.zh-Hans.xlf +++ b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.zh-Hans.xlf @@ -72,6 +72,16 @@ Parentheses preferences + + Prefix '{0}' does not match expected prefix '{1}' + Prefix '{0}' does not match expected prefix '{1}' + + + + Prefix '{0}' is not expected + Prefix '{0}' is not expected + + Refactoring Only 仅重构 diff --git a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.zh-Hant.xlf b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.zh-Hant.xlf index 6d2d3928f236cb95e762e9165f4bd978d8087604..76d9b839fcc0cadd67143148886e6b1f9a107c00 100644 --- a/src/Workspaces/Core/Portable/xlf/WorkspacesResources.zh-Hant.xlf +++ b/src/Workspaces/Core/Portable/xlf/WorkspacesResources.zh-Hant.xlf @@ -72,6 +72,16 @@ Parentheses preferences + + Prefix '{0}' does not match expected prefix '{1}' + Prefix '{0}' does not match expected prefix '{1}' + + + + Prefix '{0}' is not expected + Prefix '{0}' is not expected + + Refactoring Only 僅重構