diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/StyleCopCodeFixVerifier`2.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/StyleCopCodeFixVerifier`2.cs index 59949aecb..1876c56b3 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/StyleCopCodeFixVerifier`2.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/StyleCopCodeFixVerifier`2.cs @@ -22,6 +22,7 @@ namespace StyleCop.Analyzers.Test.Verifiers using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.Testing.Verifiers; using Microsoft.CodeAnalysis.Text; + using StyleCop.Analyzers.Lightup; using StyleCop.Analyzers.Settings.ObjectModel; using StyleCop.Analyzers.Test.Helpers; using Xunit; @@ -112,7 +113,7 @@ public CSharpTest() public CSharpTest(LanguageVersion? languageVersion) { this.ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssemblies; - this.LanguageVersion = languageVersion; + this.LanguageVersion = languageVersion ?? this.GetDefaultLanguageVersion(); this.OptionsTransforms.Add(options => options @@ -274,6 +275,19 @@ protected override IEnumerable GetCodeFixProviders() Assert.NotSame(WellKnownFixAllProviders.BatchFixer, codeFixProvider.GetFixAllProvider()); return new[] { codeFixProvider }; } + + // TODO: Remove when c# 11 is a supported language version + private LanguageVersion? GetDefaultLanguageVersion() + { + // Temporary fix since c# 11 is not yet the default language version + // in the c# 11 test project. + if (LightupHelpers.SupportsCSharp11) + { + return LanguageVersionEx.Preview; + } + + return null; + } } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/StyleCopDiagnosticVerifier`1.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/StyleCopDiagnosticVerifier`1.cs index 379ace4be..e1f33e2dc 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/StyleCopDiagnosticVerifier`1.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/StyleCopDiagnosticVerifier`1.cs @@ -13,6 +13,7 @@ namespace StyleCop.Analyzers.Test.Verifiers using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.Testing.Verifiers; + using StyleCop.Analyzers.Lightup; internal static class StyleCopDiagnosticVerifier where TAnalyzer : DiagnosticAnalyzer, new() @@ -64,7 +65,7 @@ public CSharpTest() public CSharpTest(LanguageVersion? languageVersion) { - this.LanguageVersion = languageVersion; + this.LanguageVersion = languageVersion ?? this.GetDefaultLanguageVersion(); } private LanguageVersion? LanguageVersion { get; } @@ -79,6 +80,19 @@ protected override ParseOptions CreateParseOptions() return parseOptions; } + + // TODO: Remove when c# 11 is a supported language version + private LanguageVersion? GetDefaultLanguageVersion() + { + // Temporary fix since c# 11 is not yet the default language version + // in the c# 11 test project. + if (LightupHelpers.SupportsCSharp11) + { + return LanguageVersionEx.Preview; + } + + return null; + } } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs index 20fa401d6..420992807 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/LightupHelpers.cs @@ -46,6 +46,11 @@ internal static class LightupHelpers public static bool SupportsCSharp10 { get; } = Enum.GetNames(typeof(LanguageVersion)).Contains(nameof(LanguageVersionEx.CSharp10)); + // NOTE: Since c# is only in preview yet, we need to check something else than available language versions. Picked a new syntax kind temporarily. + // TODO: Update when c# 11 is available as a language version. + public static bool SupportsCSharp11 { get; } + = Enum.GetNames(typeof(SyntaxKind)).Contains(nameof(SyntaxKindEx.SlicePattern)); + public static bool SupportsIOperation => SupportsCSharp73; internal static bool CanWrapObject(object obj, Type underlyingType) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs index be1f8ec3d..894c79ec3 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs @@ -48,6 +48,8 @@ internal static class SyntaxKindEx public const SyntaxKind SwitchExpressionArm = (SyntaxKind)9026; public const SyntaxKind VarPattern = (SyntaxKind)9027; public const SyntaxKind ParenthesizedPattern = (SyntaxKind)9028; + public const SyntaxKind SlicePattern = (SyntaxKind)9034; + public const SyntaxKind ListPattern = (SyntaxKind)9035; public const SyntaxKind DeclarationExpression = (SyntaxKind)9040; public const SyntaxKind RefExpression = (SyntaxKind)9050; public const SyntaxKind RefType = (SyntaxKind)9051;