From 38aaa2b1dc48e938ca662a39233f8c86d99874b7 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Thu, 8 Jul 2021 18:47:39 -0700 Subject: [PATCH 01/27] Initial implementation --- .../Core/AnalyzerReleases.Unshipped.md | 1 + .../CodeAnalysisDiagnosticsResources.resx | 9 ++ .../Core/DiagnosticIds.cs | 1 + .../SourceGeneratorAttributeAnalyzerFix.cs | 61 +++++++++++++ .../SourceGeneratorAttributeAnalyzer.cs | 63 ++++++++++++++ .../CodeAnalysisDiagnosticsResources.cs.xlf | 15 ++++ .../CodeAnalysisDiagnosticsResources.de.xlf | 15 ++++ .../CodeAnalysisDiagnosticsResources.es.xlf | 15 ++++ .../CodeAnalysisDiagnosticsResources.fr.xlf | 15 ++++ .../CodeAnalysisDiagnosticsResources.it.xlf | 15 ++++ .../CodeAnalysisDiagnosticsResources.ja.xlf | 15 ++++ .../CodeAnalysisDiagnosticsResources.ko.xlf | 17 +++- .../CodeAnalysisDiagnosticsResources.pl.xlf | 15 ++++ ...CodeAnalysisDiagnosticsResources.pt-BR.xlf | 15 ++++ .../CodeAnalysisDiagnosticsResources.ru.xlf | 17 +++- .../CodeAnalysisDiagnosticsResources.tr.xlf | 15 ++++ ...deAnalysisDiagnosticsResources.zh-Hans.xlf | 15 ++++ ...deAnalysisDiagnosticsResources.zh-Hant.xlf | 15 ++++ .../MissingGeneratorAttributeRuleTests.cs | 85 +++++++++++++++++++ src/Utilities/Compiler/WellKnownTypeNames.cs | 2 + 20 files changed, 419 insertions(+), 2 deletions(-) create mode 100644 src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs create mode 100644 src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs create mode 100644 src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/AnalyzerReleases.Unshipped.md b/src/Microsoft.CodeAnalysis.Analyzers/Core/AnalyzerReleases.Unshipped.md index c2e30e9f91..241ef948dc 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/AnalyzerReleases.Unshipped.md +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/AnalyzerReleases.Unshipped.md @@ -5,3 +5,4 @@ Rule ID | Category | Severity | Notes --------|----------|----------|------- RS1034 | MicrosoftCodeAnalysisPerformance | Warning | PreferIsKindAnalyzer +RS1035 | MicrosoftCodeAnalysisCorrectness | Warning | SourceGeneratorAttributeAnalyzer diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx b/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx index cf294b1e96..d0ce5f2715 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx @@ -529,4 +529,13 @@ Use 'IsKind' instead of 'Kind' + + Go add it, fool + + + Missing [Generator] Attribute + + + Missing [Generator] Attribute + \ No newline at end of file diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/DiagnosticIds.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/DiagnosticIds.cs index 0db6d44644..5841cc2127 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/DiagnosticIds.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/DiagnosticIds.cs @@ -38,6 +38,7 @@ internal static class DiagnosticIds public const string DefineDiagnosticMessageCorrectlyRuleId = "RS1032"; public const string DefineDiagnosticDescriptionCorrectlyRuleId = "RS1033"; public const string PreferIsKindRuleId = "RS1034"; + public const string MissingSourceGeneratorAttributeId = "RS1035"; // Release tracking analyzer IDs public const string DeclareDiagnosticIdInAnalyzerReleaseRuleId = "RS2000"; diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs new file mode 100644 index 0000000000..43f153dd1c --- /dev/null +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Immutable; +using System.Composition; +using System.Threading; +using System.Threading.Tasks; +using Analyzer.Utilities; +using Microsoft.CodeAnalysis.CodeFixes; +using Microsoft.CodeAnalysis.Editing; + +namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.Fixers +{ + [ExportCodeFixProvider(LanguageNames.CSharp, LanguageNames.VisualBasic, Name = nameof(SourceGeneratorAttributeAnalyzerFix))] + [Shared] + public sealed class SourceGeneratorAttributeAnalyzerFix : CodeFixProvider + { + public override ImmutableArray FixableDiagnosticIds => ImmutableArray.Create( + DiagnosticIds.MissingSourceGeneratorAttributeId); + + public override async Task RegisterCodeFixesAsync(CodeFixContext context) + { + var document = context.Document; + var root = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); + var node = root.FindNode(context.Span, getInnermostNodeForTie: true); + + if (node is null) + { + return; + } + + foreach (var diagnostic in context.Diagnostics) + { + context.RegisterCodeFix(new MyCodeAction( + "Fix stuff", + (c) => FixDocumentAsync(document, node, c), + "Fix stuff"), diagnostic); + } + } + + public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; + + private static async Task FixDocumentAsync(Document document, SyntaxNode node, CancellationToken cancellationToken) + { + var editor = await DocumentEditor.CreateAsync(document, cancellationToken).ConfigureAwait(false); + var generator = editor.Generator; + var generatorAttribute = generator.Attribute(WellKnownTypeNames.MicrosoftCodeAnalysisGeneratorAttribute); + + editor.ReplaceNode(node, generator.AddAttributes(node, generatorAttribute)); + + return editor.GetChangedDocument(); + } + + private class MyCodeAction : DocumentChangeAction + { + public MyCodeAction(string title, Func> createChangedDocument, string equivalenceKey) : base(title, createChangedDocument, equivalenceKey) + { + } + } + } +} diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs new file mode 100644 index 0000000000..f244bea4f1 --- /dev/null +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Immutable; +using System.Linq; +using Analyzer.Utilities; +using Analyzer.Utilities.Extensions; +using Microsoft.CodeAnalysis.Diagnostics; + +namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers +{ + [DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)] + public sealed class SourceGeneratorAttributeAnalyzer : DiagnosticAnalyzer + { + private static readonly LocalizableString s_localizableTitle = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.MissingSourceGeneratorAttributeTitle), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources)); + private static readonly LocalizableString s_localizableMessage = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.MissingSourceGeneratorAttributeTitle), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources)); + private static readonly LocalizableString s_localizableDescription = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.MissingSourceGeneratorAttributeDescription), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources)); + + public static readonly DiagnosticDescriptor DiagnosticRule = new( + DiagnosticIds.MissingSourceGeneratorAttributeId, + s_localizableTitle, + s_localizableMessage, + DiagnosticCategory.MicrosoftCodeAnalysisCorrectness, + DiagnosticSeverity.Warning, + isEnabledByDefault: true); + + public override ImmutableArray SupportedDiagnostics => ImmutableArray.Create(DiagnosticRule); + + public override void Initialize(AnalysisContext context) + { + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); + context.EnableConcurrentExecution(); + + context.RegisterCompilationStartAction(compilationContext => + { + var sourceGenerator = compilationContext.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.MicrosoftCodeAnalysisISourceGenerator); + var sourceGeneratorAttribute = compilationContext.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.MicrosoftCodeAnalysisGeneratorAttribute); + + if (sourceGenerator == null || sourceGeneratorAttribute == null) + // We don't need to check assemblies unless they're referencing Microsoft.CodeAnalysis which defines DiagnosticAnalyzer. + return; + + compilationContext.RegisterSymbolAction(c => AnalyzeSymbol(c, sourceGenerator, sourceGeneratorAttribute), SymbolKind.NamedType); + }); + } + + private static void AnalyzeSymbol(SymbolAnalysisContext c, INamedTypeSymbol sourceGenerator, INamedTypeSymbol sourceGeneratorAttribute) + { + var symbol = (INamedTypeSymbol)c.Symbol; + + if (!symbol.AllInterfaces.Any(i => sourceGenerator.Equals(i, SymbolEqualityComparer.Default))) + { + return; + } + + if (symbol.GetApplicableAttributes(null).Any(a => a.AttributeClass.Inherits(sourceGenerator))) + { + return; + } + + c.ReportDiagnostic(symbol.CreateDiagnostic(DiagnosticRule)); + } + } +} diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf index 3bbe952d7c..811c2ce666 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf @@ -232,6 +232,21 @@ Použijte atribut DiagnosticAnalyzer jak pro {0}, tak i pro {1}. + + Go add it, fool + Go add it, fool + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + Specify at least one SymbolKind of interest when registering a symbol analyzer action Při registraci akce analyzátoru symbolů zadejte minimálně jeden požadovaný SymbolKind. diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf index f0e8910634..8bafa11c79 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf @@ -232,6 +232,21 @@ Wenden Sie das DiagnosticAnalyzer-Attribut sowohl für "{0}" als auch für "{1}" an. + + Go add it, fool + Go add it, fool + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + Specify at least one SymbolKind of interest when registering a symbol analyzer action Geben Sie bei der Registrierung einer Symbolanalyseaktion mindestens einen relevanten SymbolKind-Wert an. diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf index 1d99ded1b9..84c327112f 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf @@ -232,6 +232,21 @@ Aplique el atributo DiagnosticAnalyzer para “{0}” y “{1}”. + + Go add it, fool + Go add it, fool + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + Specify at least one SymbolKind of interest when registering a symbol analyzer action Especifique al menos un elemento SymbolKind de interés al registrar una acción del analizador de símbolos. diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf index 876746cf5c..f0bf8b02ef 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf @@ -232,6 +232,21 @@ Appliquez l'attribut DiagnosticAnalyzer pour '{0}' et '{1}'. + + Go add it, fool + Go add it, fool + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + Specify at least one SymbolKind of interest when registering a symbol analyzer action Spécifiez au moins un SymbolKind d'intérêt au moment d'inscrire une action d'analyseur de symbole diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf index 2a1e72bb7a..8f046ff291 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf @@ -232,6 +232,21 @@ Applicare l'attributo DiagnosticAnalyzer sia per '{0}' che per '{1}'. + + Go add it, fool + Go add it, fool + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + Specify at least one SymbolKind of interest when registering a symbol analyzer action Specificare almeno un elemento SymbolKind di interesse durante la registrazione di un'azione dell'analizzatore di simboli diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf index 2d4594133c..514b0f8089 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf @@ -232,6 +232,21 @@ '{0}' と '{1}' の両方に DiagnosticAnalyzer 属性を適用します。 + + Go add it, fool + Go add it, fool + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + Specify at least one SymbolKind of interest when registering a symbol analyzer action シンボル アナライザー アクションを登録する際に、関心のある SymbolKind を 1 つ以上指定してください diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf index 86d75d1d02..49075d04ad 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf @@ -232,6 +232,21 @@ '{0}' 및 '{1}'에 대한 DiagnosticAnalyzer 특성을 적용하세요. + + Go add it, fool + Go add it, fool + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + Specify at least one SymbolKind of interest when registering a symbol analyzer action 기호 분석기 작업을 등록할 때 관심 있는 SymbolKind를 하나 이상 지정하세요. @@ -692,4 +707,4 @@ - + \ No newline at end of file diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf index 34e8556753..594fd3097e 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf @@ -232,6 +232,21 @@ Zastosuj atrybut DiagnosticAnalyzer zarówno do elementu „{0}”, jak i elementu „{1}”. + + Go add it, fool + Go add it, fool + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + Specify at least one SymbolKind of interest when registering a symbol analyzer action Określ co najmniej jeden interesujący argument SymbolKind podczas rejestrowania akcji analizatora symboli diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf index 218653bcb7..93f0131644 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf @@ -232,6 +232,21 @@ Aplique o atributo DiagnosticAnalyzer para '{0}' e para '{1}'. + + Go add it, fool + Go add it, fool + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + Specify at least one SymbolKind of interest when registering a symbol analyzer action Especifique pelo menos um SymbolKind de interesse ao registrar uma ação de analisador de símbolo diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf index 2623672afe..e69772bfb6 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf @@ -232,6 +232,21 @@ Примените атрибут DiagnosticAnalyzer для "{0}" и "{1}". + + Go add it, fool + Go add it, fool + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + Specify at least one SymbolKind of interest when registering a symbol analyzer action Укажите по меньшей мере один нужный SymbolKind при регистрации действия анализатора для символов. @@ -692,4 +707,4 @@ - + \ No newline at end of file diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf index aa5f10680f..82d49337a8 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf @@ -232,6 +232,21 @@ Hem '{0}' hem de '{1}' için DiagnosticAnalyzer özniteliğini uygulayın. + + Go add it, fool + Go add it, fool + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + Specify at least one SymbolKind of interest when registering a symbol analyzer action Bir sembol çözümleyicisi eylemi kaydedilirken en az bir ilgili SymbolKind belirtin diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf index 4a5aa923b7..e67770b0eb 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf @@ -232,6 +232,21 @@ 为“{0}”和“{1}”应用 DiagnosticAnalyzer 特性。 + + Go add it, fool + Go add it, fool + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + Specify at least one SymbolKind of interest when registering a symbol analyzer action 注册符号分析器操作时,至少指定一个感兴趣的 SymbolKind diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf index 6f0ffb4eca..0217f3bd92 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf @@ -232,6 +232,21 @@ 同時為 '{0}' 與 '{1}' 套用 DiagnosticAnalyzer 屬性。 + + Go add it, fool + Go add it, fool + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + + + Missing [Generator] Attribute + Missing [Generator] Attribute + + Specify at least one SymbolKind of interest when registering a symbol analyzer action 註冊符號分析器動作時,請至少指定一個關注的 SymbolKind diff --git a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs new file mode 100644 index 0000000000..f762fb930f --- /dev/null +++ b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs @@ -0,0 +1,85 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Testing; +using Test.Utilities; +using Xunit; +using VerifyCS = Test.Utilities.CSharpCodeFixVerifier< + Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.SourceGeneratorAttributeAnalyzer, + Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.Fixers.SourceGeneratorAttributeAnalyzerFix>; + +namespace Microsoft.CodeAnalysis.Analyzers.UnitTests.MetaAnalyzers +{ + public class MissingGeneratorAttributeRuleTests + { + private const string SourceGenerator = @" +using System; +using Microsoft.CodeAnalysis; + +namespace Microsoft.CodeAnalysis +{ + [AttributeUsage(AttributeTargets.Class)] + public sealed class GeneratorAttribute : Attribute + { + } + + public interface ISourceGenerator + { + void Initialize(GeneratorInitializationContext context); + void Execute(GeneratorExecutionContext context); + } + + public struct GeneratorInitializationContext + { + } + + public readonly struct GeneratorExecutionContext + { + } +}"; + + [Fact] + public async Task Test1() + { + var code = @" +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; + +public class {|RS1035:CustomGenerator|} : ISourceGenerator +{ + public void Initialize(GeneratorInitializationContext context) {} + + public void Execute(GeneratorExecutionContext context) + { + } +}"; + + var fixedCode = @" +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; + +[Generator] +public class [|CustomGenerator|] : ISourceGenerator +{ + public void Initialize(GeneratorInitializationContext context) {} + + public void Execute(GeneratorExecutionContext context) + { + } +}"; + await new VerifyCS.Test + { + TestState = + { + Sources = { code , SourceGenerator }, + AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} + }, + FixedState = + { + Sources = { fixedCode, SourceGenerator }, + AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} + }, + }.RunAsync(); + } + } +} diff --git a/src/Utilities/Compiler/WellKnownTypeNames.cs b/src/Utilities/Compiler/WellKnownTypeNames.cs index 2775dce369..ba558e6583 100644 --- a/src/Utilities/Compiler/WellKnownTypeNames.cs +++ b/src/Utilities/Compiler/WellKnownTypeNames.cs @@ -44,6 +44,8 @@ internal static class WellKnownTypeNames public const string MicrosoftCodeAnalysisDiagnosticsCompilationStartAnalysisContext = "Microsoft.CodeAnalysis.Diagnostics.CompilationStartAnalysisContext"; public const string MicrosoftCodeAnalysisDiagnosticsDiagnosticAnalyzer = "Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer"; public const string MicrosoftCodeAnalysisDiagnosticsDiagnosticAnalyzerAttribute = "Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzerAttribute"; + public const string MicrosoftCodeAnalysisISourceGenerator = "Microsoft.CodeAnalysis.ISourceGenerator"; + public const string MicrosoftCodeAnalysisGeneratorAttribute = "Microsoft.CodeAnalysis.GeneratorAttribute"; public const string MicrosoftCodeAnalysisDiagnosticsGeneratedCodeAnalysisFlags = "Microsoft.CodeAnalysis.Diagnostics.GeneratedCodeAnalysisFlags"; public const string MicrosoftCodeAnalysisDiagnosticsOperationAnalysisContext = "Microsoft.CodeAnalysis.Diagnostics.OperationAnalysisContext"; public const string MicrosoftCodeAnalysisDiagnosticsOperationBlockAnalysisContext = "Microsoft.CodeAnalysis.Diagnostics.OperationBlockAnalysisContext"; From 82f5da3214859dc54d983e8793dcf60d9cb3f97a Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Thu, 8 Jul 2021 19:02:17 -0700 Subject: [PATCH 02/27] I forgot to type "Attribute" --- .../Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs | 2 +- .../MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs index f244bea4f1..9198789ad0 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs @@ -52,7 +52,7 @@ private static void AnalyzeSymbol(SymbolAnalysisContext c, INamedTypeSymbol sour return; } - if (symbol.GetApplicableAttributes(null).Any(a => a.AttributeClass.Inherits(sourceGenerator))) + if (symbol.GetApplicableAttributes(null).Any(a => a.AttributeClass.Inherits(sourceGeneratorAttribute))) { return; } diff --git a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs index f762fb930f..69c4f7e268 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs @@ -59,7 +59,7 @@ public void Execute(GeneratorExecutionContext context) using Microsoft.CodeAnalysis.Diagnostics; [Generator] -public class [|CustomGenerator|] : ISourceGenerator +public class {|RS1035:CustomGenerator|} : ISourceGenerator { public void Initialize(GeneratorInitializationContext context) {} @@ -77,7 +77,7 @@ public void Execute(GeneratorExecutionContext context) FixedState = { Sources = { fixedCode, SourceGenerator }, - AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} + AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference}, }, }.RunAsync(); } From 261db9028d5d2c5a356a0a9a20e2d2546d5143f3 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Sun, 11 Jul 2021 23:34:52 -0700 Subject: [PATCH 03/27] Add more tests. Don't report on abstract or anonymous types --- .../SourceGeneratorAttributeAnalyzer.cs | 6 + .../MissingGeneratorAttributeRuleTests.cs | 333 +++++++++++++++++- 2 files changed, 333 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs index 9198789ad0..684ecc5638 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs @@ -21,6 +21,7 @@ public sealed class SourceGeneratorAttributeAnalyzer : DiagnosticAnalyzer s_localizableMessage, DiagnosticCategory.MicrosoftCodeAnalysisCorrectness, DiagnosticSeverity.Warning, + description: s_localizableDescription, isEnabledByDefault: true); public override ImmutableArray SupportedDiagnostics => ImmutableArray.Create(DiagnosticRule); @@ -47,6 +48,11 @@ private static void AnalyzeSymbol(SymbolAnalysisContext c, INamedTypeSymbol sour { var symbol = (INamedTypeSymbol)c.Symbol; + if (symbol.IsAbstract || symbol.IsAnonymousType) + { + return; + } + if (!symbol.AllInterfaces.Any(i => sourceGenerator.Equals(i, SymbolEqualityComparer.Default))) { return; diff --git a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs index 69c4f7e268..a4fe3ec56c 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs @@ -8,11 +8,15 @@ Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.SourceGeneratorAttributeAnalyzer, Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.Fixers.SourceGeneratorAttributeAnalyzerFix>; +using VerifyVB = Test.Utilities.VisualBasicCodeFixVerifier< + Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.SourceGeneratorAttributeAnalyzer, + Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.Fixers.SourceGeneratorAttributeAnalyzerFix>; + namespace Microsoft.CodeAnalysis.Analyzers.UnitTests.MetaAnalyzers { public class MissingGeneratorAttributeRuleTests { - private const string SourceGenerator = @" + private const string SourceGeneratorStub_CSharp = @" using System; using Microsoft.CodeAnalysis; @@ -38,14 +42,92 @@ public readonly struct GeneratorExecutionContext } }"; + private const string SourceGeneratorStub_VisualBasic = @" +Imports System +Imports Microsoft.CodeAnalysis + +Namespace Microsoft.CodeAnalysis + + public Class GeneratorAttribute + Inherits Attribute + End Class + + public interface ISourceGenerator + Sub Initialize(context As GeneratorInitializationContext) + Sub Execute(context As GeneratorExecutionContext) + End Interface + + public Class GeneratorInitializationContext + End Class + + public Class GeneratorExecutionContext + End Class +End Namespace"; + [Fact] - public async Task Test1() + public async Task TestMissing_CSharp() { var code = @" using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; -public class {|RS1035:CustomGenerator|} : ISourceGenerator +[Generator] +public class CustomGenerator : ISourceGenerator +{ + public void Initialize(GeneratorInitializationContext context) {} + + public void Execute(GeneratorExecutionContext context) + { + } +}"; + + await new VerifyCS.Test + { + TestState = + { + Sources = { code , SourceGeneratorStub_CSharp }, + AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} + } + }.RunAsync(); + } + + [Fact] + public async Task TestMissing_VisualBasic() + { + var code = @" +Imports Microsoft.CodeAnalysis + + +Public Class CustomGenerator + Implements ISourceGenerator + + Public Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize + + End Sub + + Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute + + End Sub +End Class"; + + await new VerifyVB.Test + { + TestState = + { + Sources = { code , SourceGeneratorStub_VisualBasic }, + AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} + } + }.RunAsync(); + } + + [Fact] + public async Task TestSimpleClass_CSharp() + { + var code = @" +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; + +public class [|CustomGenerator|] : ISourceGenerator { public void Initialize(GeneratorInitializationContext context) {} @@ -59,7 +141,7 @@ public void Execute(GeneratorExecutionContext context) using Microsoft.CodeAnalysis.Diagnostics; [Generator] -public class {|RS1035:CustomGenerator|} : ISourceGenerator +public class CustomGenerator : ISourceGenerator { public void Initialize(GeneratorInitializationContext context) {} @@ -71,15 +153,254 @@ public void Execute(GeneratorExecutionContext context) { TestState = { - Sources = { code , SourceGenerator }, + Sources = { code , SourceGeneratorStub_CSharp }, AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} }, FixedState = { - Sources = { fixedCode, SourceGenerator }, + Sources = { fixedCode, SourceGeneratorStub_CSharp }, AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference}, }, }.RunAsync(); } + + [Fact] + public async Task TestSimpleClass_VisualBasic() + { + var code = @" +Imports Microsoft.CodeAnalysis + +Public Class [|CustomGenerator|] + Implements ISourceGenerator + + Public Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize + + End Sub + + Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute + + End Sub +End Class"; + + var fixedCode = @" +Imports Microsoft.CodeAnalysis + + +Public Class CustomGenerator + Implements ISourceGenerator + + Public Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize + + End Sub + + Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute + + End Sub +End Class"; + + await new VerifyVB.Test + { + TestState = + { + Sources = { code , SourceGeneratorStub_VisualBasic }, + AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} + }, + FixedState = + { + Sources = { fixedCode, SourceGeneratorStub_VisualBasic }, + AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference}, + }, + }.RunAsync(); + } + + [Fact] + public async Task TestHierarchy_CSharp() + { + var code = @" +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; + +public abstract class CustomGeneratorBase : ISourceGenerator +{ + public abstract void Initialize(GeneratorInitializationContext context); + + public abstract void Execute(GeneratorExecutionContext context); +} + +public class [|CustomGenerator|] : CustomGeneratorBase +{ + public override void Initialize(GeneratorInitializationContext context) {} + + public override void Execute(GeneratorExecutionContext context) + { + } +}"; + + var fixedCode = @" +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; + +public abstract class CustomGeneratorBase : ISourceGenerator +{ + public abstract void Initialize(GeneratorInitializationContext context); + + public abstract void Execute(GeneratorExecutionContext context); +} + +[Generator] +public class CustomGenerator : CustomGeneratorBase +{ + public override void Initialize(GeneratorInitializationContext context) {} + + public override void Execute(GeneratorExecutionContext context) + { + } +}"; + await new VerifyCS.Test + { + TestState = + { + Sources = { code , SourceGeneratorStub_CSharp }, + AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} + }, + FixedState = + { + Sources = { fixedCode, SourceGeneratorStub_CSharp }, + AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference}, + }, + }.RunAsync(); + } + + [Fact] + public async Task TestHierarchy_VisualBasic() + { + var code = @" +Imports Microsoft.CodeAnalysis + +Public MustInherit Class CustomGeneratorBase + Implements ISourceGenerator + + Public MustOverride Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize + Public MustOverride Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute +End Class + +Public Class [|CustomGenerator|] + Inherits CustomGeneratorBase + + Public Overrides Sub Initialize(context As GeneratorInitializationContext) + + End Sub + + Public Overrides Sub Execute(context As GeneratorExecutionContext) + + End Sub +End Class"; + + var fixedCode = @" +Imports Microsoft.CodeAnalysis + +Public MustInherit Class CustomGeneratorBase + Implements ISourceGenerator + + Public MustOverride Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize + Public MustOverride Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute +End Class + + +Public Class CustomGenerator + Inherits CustomGeneratorBase + + Public Overrides Sub Initialize(context As GeneratorInitializationContext) + + End Sub + + Public Overrides Sub Execute(context As GeneratorExecutionContext) + + End Sub +End Class"; + + await new VerifyVB.Test + { + TestState = + { + Sources = { code , SourceGeneratorStub_VisualBasic }, + AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} + }, + FixedState = + { + Sources = { fixedCode, SourceGeneratorStub_VisualBasic }, + AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference}, + }, + }.RunAsync(); + } + + [Fact] + public async Task TestHierarchy_InheritedAttribute_CSharp() + { + var code = @" +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; + +[Generator] +public abstract class CustomGeneratorBase : ISourceGenerator +{ + public abstract void Initialize(GeneratorInitializationContext context); + + public abstract void Execute(GeneratorExecutionContext context); +} + +public class CustomGenerator : CustomGeneratorBase +{ + public override void Initialize(GeneratorInitializationContext context) {} + + public override void Execute(GeneratorExecutionContext context) + { + } +}"; + await new VerifyCS.Test + { + TestState = + { + Sources = { code , SourceGeneratorStub_CSharp }, + AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} + } + }.RunAsync(); + } + + [Fact] + public async Task TestHierarchy_InheritedAttribute_VisualBasic() + { + var code = @" +Imports Microsoft.CodeAnalysis + + +Public MustInherit Class CustomGeneratorBase + Implements ISourceGenerator + + Public MustOverride Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize + Public MustOverride Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute +End Class + +Public Class CustomGenerator + Inherits CustomGeneratorBase + + Public Overrides Sub Initialize(context As GeneratorInitializationContext) + + End Sub + + Public Overrides Sub Execute(context As GeneratorExecutionContext) + + End Sub +End Class"; + + await new VerifyVB.Test + { + TestState = + { + Sources = { code , SourceGeneratorStub_VisualBasic }, + AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} + } + }.RunAsync(); + } } } From d1fbafacc364f3c32168478df0b060b6f541d4c8 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Sun, 11 Jul 2021 23:37:52 -0700 Subject: [PATCH 04/27] Add description --- .../Core/CodeAnalysisDiagnosticsResources.resx | 2 +- .../Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs | 2 +- .../Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf | 4 ++-- 15 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx b/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx index d0ce5f2715..5365b04dbd 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx @@ -530,7 +530,7 @@ Use 'IsKind' instead of 'Kind' - Go add it, fool + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute Missing [Generator] Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs index 684ecc5638..2dd60afaa7 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs @@ -63,7 +63,7 @@ private static void AnalyzeSymbol(SymbolAnalysisContext c, INamedTypeSymbol sour return; } - c.ReportDiagnostic(symbol.CreateDiagnostic(DiagnosticRule)); + c.ReportDiagnostic(symbol.CreateDiagnostic(DiagnosticRule, symbol.Name)); } } } diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf index 811c2ce666..4ed39e9af9 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf @@ -233,8 +233,8 @@ - Go add it, fool - Go add it, fool + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf index 8bafa11c79..5134d42798 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf @@ -233,8 +233,8 @@ - Go add it, fool - Go add it, fool + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf index 84c327112f..d217596e3c 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf @@ -233,8 +233,8 @@ - Go add it, fool - Go add it, fool + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf index f0bf8b02ef..8b951a4325 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf @@ -233,8 +233,8 @@ - Go add it, fool - Go add it, fool + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf index 8f046ff291..387faf9d43 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf @@ -233,8 +233,8 @@ - Go add it, fool - Go add it, fool + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf index 514b0f8089..59f4665818 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf @@ -233,8 +233,8 @@ - Go add it, fool - Go add it, fool + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf index 49075d04ad..36d2649a33 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf @@ -233,8 +233,8 @@ - Go add it, fool - Go add it, fool + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf index 594fd3097e..1dff886de2 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf @@ -233,8 +233,8 @@ - Go add it, fool - Go add it, fool + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf index 93f0131644..b44c411367 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf @@ -233,8 +233,8 @@ - Go add it, fool - Go add it, fool + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf index e69772bfb6..3aa71d49fe 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf @@ -233,8 +233,8 @@ - Go add it, fool - Go add it, fool + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf index 82d49337a8..b5c2150837 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf @@ -233,8 +233,8 @@ - Go add it, fool - Go add it, fool + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf index e67770b0eb..fec018a78d 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf @@ -233,8 +233,8 @@ - Go add it, fool - Go add it, fool + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf index 0217f3bd92..02b23f7b18 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf @@ -233,8 +233,8 @@ - Go add it, fool - Go add it, fool + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute From f8f5015a16287957dfdc76699994539f058a10f0 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Mon, 12 Jul 2021 09:31:57 -0700 Subject: [PATCH 05/27] PR Feedback and Cleanup --- .../CodeAnalysisDiagnosticsResources.resx | 9 +- .../SourceGeneratorAttributeAnalyzerFix.cs | 19 +- .../SourceGeneratorAttributeAnalyzer.cs | 19 +- .../CodeAnalysisDiagnosticsResources.cs.xlf | 17 +- .../CodeAnalysisDiagnosticsResources.de.xlf | 17 +- .../CodeAnalysisDiagnosticsResources.es.xlf | 17 +- .../CodeAnalysisDiagnosticsResources.fr.xlf | 17 +- .../CodeAnalysisDiagnosticsResources.it.xlf | 17 +- .../CodeAnalysisDiagnosticsResources.ja.xlf | 17 +- .../CodeAnalysisDiagnosticsResources.ko.xlf | 17 +- .../CodeAnalysisDiagnosticsResources.pl.xlf | 17 +- ...CodeAnalysisDiagnosticsResources.pt-BR.xlf | 17 +- .../CodeAnalysisDiagnosticsResources.ru.xlf | 17 +- .../CodeAnalysisDiagnosticsResources.tr.xlf | 17 +- ...deAnalysisDiagnosticsResources.zh-Hans.xlf | 17 +- ...deAnalysisDiagnosticsResources.zh-Hant.xlf | 17 +- .../MissingGeneratorAttributeRuleTests.cs | 240 +++++++----------- src/Utilities/Compiler/WellKnownTypeNames.cs | 4 +- 18 files changed, 259 insertions(+), 253 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx b/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx index 5365b04dbd..8eca932606 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx @@ -530,12 +530,15 @@ Use 'IsKind' instead of 'Kind' - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - Missing [Generator] Attribute + Missing Generator attribute - Missing [Generator] Attribute + Missing Generator Attribute + + + Add Generator Attribute \ No newline at end of file diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs index 43f153dd1c..bf6ad8cd4a 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs @@ -1,11 +1,11 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Immutable; using System.Composition; using System.Threading; using System.Threading.Tasks; using Analyzer.Utilities; +using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Editing; @@ -31,10 +31,12 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) foreach (var diagnostic in context.Diagnostics) { - context.RegisterCodeFix(new MyCodeAction( - "Fix stuff", - (c) => FixDocumentAsync(document, node, c), - "Fix stuff"), diagnostic); + context.RegisterCodeFix( + CodeAction.Create( + CodeAnalysisDiagnosticsResources.AddGeneratorAttribute, + c => FixDocumentAsync(document, node, c), + equivalenceKey: nameof(SourceGeneratorAttributeAnalyzerFix)), + diagnostic); } } @@ -50,12 +52,5 @@ private static async Task FixDocumentAsync(Document document, SyntaxNo return editor.GetChangedDocument(); } - - private class MyCodeAction : DocumentChangeAction - { - public MyCodeAction(string title, Func> createChangedDocument, string equivalenceKey) : base(title, createChangedDocument, equivalenceKey) - { - } - } } } diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs index 2dd60afaa7..e695450f34 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs @@ -31,20 +31,17 @@ public override void Initialize(AnalysisContext context) context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); context.EnableConcurrentExecution(); - context.RegisterCompilationStartAction(compilationContext => + context.RegisterCompilationStartAction(context => { - var sourceGenerator = compilationContext.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.MicrosoftCodeAnalysisISourceGenerator); - var sourceGeneratorAttribute = compilationContext.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.MicrosoftCodeAnalysisGeneratorAttribute); - - if (sourceGenerator == null || sourceGeneratorAttribute == null) - // We don't need to check assemblies unless they're referencing Microsoft.CodeAnalysis which defines DiagnosticAnalyzer. - return; - - compilationContext.RegisterSymbolAction(c => AnalyzeSymbol(c, sourceGenerator, sourceGeneratorAttribute), SymbolKind.NamedType); + if (context.Compilation.TryGetOrCreateTypeByMetadataName(WellKnownTypeNames.MicrosoftCodeAnalysisISourceGenerator, out var sourceGenerator) && + context.Compilation.TryGetOrCreateTypeByMetadataName(WellKnownTypeNames.MicrosoftCodeAnalysisGeneratorAttribute, out var generatorAttribute)) + { + context.RegisterSymbolAction(c => AnalyzeSymbol(c, sourceGenerator, generatorAttribute), SymbolKind.NamedType); + } }); } - private static void AnalyzeSymbol(SymbolAnalysisContext c, INamedTypeSymbol sourceGenerator, INamedTypeSymbol sourceGeneratorAttribute) + private static void AnalyzeSymbol(SymbolAnalysisContext c, INamedTypeSymbol sourceGenerator, INamedTypeSymbol generatorAttribute) { var symbol = (INamedTypeSymbol)c.Symbol; @@ -58,7 +55,7 @@ private static void AnalyzeSymbol(SymbolAnalysisContext c, INamedTypeSymbol sour return; } - if (symbol.GetApplicableAttributes(null).Any(a => a.AttributeClass.Inherits(sourceGeneratorAttribute))) + if (symbol.GetApplicableAttributes(null).Any(a => a.AttributeClass.Equals(generatorAttribute, SymbolEqualityComparer.Default))) { return; } diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf index 4ed39e9af9..d779aa8b56 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf @@ -7,6 +7,11 @@ Přidat položku pravidla k nevydanému souboru verze + + Add Generator Attribute + Add Generator Attribute + + Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) Zděďte typ {0} z DiagnosticAnalyzer, nebo odeberte atributy DiagnosticAnalyzerAttribute. @@ -233,18 +238,18 @@ - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator attribute + Missing Generator attribute - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator Attribute + Missing Generator Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf index 5134d42798..147d035748 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf @@ -7,6 +7,11 @@ Regeleintrag der nicht veröffentlichten Releasedatei hinzufügen + + Add Generator Attribute + Add Generator Attribute + + Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) Übernehmen Sie den Typ "{0}" von DiagnosticAnalyzer, oder entfernen Sie DiagnosticAnalyzerAttribute(s). @@ -233,18 +238,18 @@ - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator attribute + Missing Generator attribute - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator Attribute + Missing Generator Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf index d217596e3c..85df5a3f1b 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf @@ -7,6 +7,11 @@ Agregar una entrada de regla a un archivo de versión no incluido + + Add Generator Attribute + Add Generator Attribute + + Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) Herede el tipo "{0}" de DiagnosticAnalyzer o quite los elementos DiagnosticAnalyzerAttribute. @@ -233,18 +238,18 @@ - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator attribute + Missing Generator attribute - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator Attribute + Missing Generator Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf index 8b951a4325..c75aabec6a 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf @@ -7,6 +7,11 @@ Ajouter une entrée de règle au fichier de version non fourni + + Add Generator Attribute + Add Generator Attribute + + Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) Effectuez un héritage de type '{0}' à partir de DiagnosticAnalyzer, ou supprimez les instances de DiagnosticAnalyzerAttribute @@ -233,18 +238,18 @@ - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator attribute + Missing Generator attribute - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator Attribute + Missing Generator Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf index 387faf9d43..9e27851d9f 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf @@ -7,6 +7,11 @@ Aggiungere la voce della regola per il file di versione non distribuito + + Add Generator Attribute + Add Generator Attribute + + Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) Ereditare il tipo '{0}' da DiagnosticAnalyzer o rimuovere gli attributi DiagnosticAnalyzerAttribute @@ -233,18 +238,18 @@ - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator attribute + Missing Generator attribute - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator Attribute + Missing Generator Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf index 59f4665818..729427d329 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf @@ -7,6 +7,11 @@ 未出荷のリリース ファイルへのルール エントリの追加 + + Add Generator Attribute + Add Generator Attribute + + Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) DiagnosticAnalyzer から型 '{0}' を継承するか、DiagnosticAnalyzerAttribute を削除してください @@ -233,18 +238,18 @@ - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator attribute + Missing Generator attribute - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator Attribute + Missing Generator Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf index 36d2649a33..f4209a5f1f 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf @@ -7,6 +7,11 @@ 제공되지 않은 릴리스 파일에 규칙 항목 추가 + + Add Generator Attribute + Add Generator Attribute + + Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) DiagnosticAnalyzer에서 '{0}' 형식을 상속하거나 DiagnosticAnalyzerAttribute를 제거하세요. @@ -233,18 +238,18 @@ - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator attribute + Missing Generator attribute - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator Attribute + Missing Generator Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf index 1dff886de2..843a4a0bac 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf @@ -7,6 +7,11 @@ Dodaj wpis reguły do niedostarczonego pliku wydania + + Add Generator Attribute + Add Generator Attribute + + Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) Dziedzicz typ „{0}” z elementu DiagnosticAnalyzer lub usuń elementy DiagnosticAnalyzerAttribute @@ -233,18 +238,18 @@ - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator attribute + Missing Generator attribute - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator Attribute + Missing Generator Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf index b44c411367..48307a78b5 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf @@ -7,6 +7,11 @@ Adicionar uma entrada de regra ao arquivo de versão não enviado + + Add Generator Attribute + Add Generator Attribute + + Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) Herdar o tipo '{0}' de DiagnosticAnalyzer ou remover os DiagnosticAnalyzerAttributes @@ -233,18 +238,18 @@ - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator attribute + Missing Generator attribute - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator Attribute + Missing Generator Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf index 3aa71d49fe..864a9c2691 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf @@ -7,6 +7,11 @@ Добавить запись правила в неотправленный файл выпуска + + Add Generator Attribute + Add Generator Attribute + + Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) Наследуйте тип "{0}" от DiagnosticAnalyzer или удалите DiagnosticAnalyzerAttribute. @@ -233,18 +238,18 @@ - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator attribute + Missing Generator attribute - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator Attribute + Missing Generator Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf index b5c2150837..93dae8d8fa 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf @@ -7,6 +7,11 @@ Gönderilmeyen yayın dosyasına kural girişi ekle + + Add Generator Attribute + Add Generator Attribute + + Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) DiagnosticAnalyzer'dan '{0}' türünü devralın veya DiagnosticAnalyzerAttribute'ları kaldırın @@ -233,18 +238,18 @@ - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator attribute + Missing Generator attribute - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator Attribute + Missing Generator Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf index fec018a78d..daf30c50d1 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf @@ -7,6 +7,11 @@ 将规则项添加到未提供的版本文件 + + Add Generator Attribute + Add Generator Attribute + + Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) 从 DiagnosticAnalyzer 继承类型“{0}”,或者删除 DiagnosticAnalyzerAttribute @@ -233,18 +238,18 @@ - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator attribute + Missing Generator attribute - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator Attribute + Missing Generator Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf index 02b23f7b18..da0c5ffbda 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf @@ -7,6 +7,11 @@ 將規則項目新增至未送出的版本檔案 + + Add Generator Attribute + Add Generator Attribute + + Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) 從 DiagnosticAnalyzer 繼承型別 '{0}' 或移除 DiagnosticAnalyzerAttribute @@ -233,18 +238,18 @@ - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute - '{0}' inherits from ISourceGenerator but does not have the [Generator] attribute + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator attribute + Missing Generator attribute - Missing [Generator] Attribute - Missing [Generator] Attribute + Missing Generator Attribute + Missing Generator Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs index a4fe3ec56c..9a177d6dad 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Collections.Immutable; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Testing; -using Test.Utilities; using Xunit; using VerifyCS = Test.Utilities.CSharpCodeFixVerifier< Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.SourceGeneratorAttributeAnalyzer, @@ -16,150 +16,73 @@ namespace Microsoft.CodeAnalysis.Analyzers.UnitTests.MetaAnalyzers { public class MissingGeneratorAttributeRuleTests { - private const string SourceGeneratorStub_CSharp = @" -using System; + private static readonly ReferenceAssemblies ReferenceAssemblies = + ReferenceAssemblies.Default.AddPackages(ImmutableArray.Create(new PackageIdentity("Microsoft.CodeAnalysis", "3.10.0"))); + + [Fact] + public async Task TestSimpleClass_CSharp() + { + var code = @" using Microsoft.CodeAnalysis; -namespace Microsoft.CodeAnalysis +public class [|CustomGenerator|] : ISourceGenerator { - [AttributeUsage(AttributeTargets.Class)] - public sealed class GeneratorAttribute : Attribute - { - } - - public interface ISourceGenerator - { - void Initialize(GeneratorInitializationContext context); - void Execute(GeneratorExecutionContext context); - } - - public struct GeneratorInitializationContext - { - } - - public readonly struct GeneratorExecutionContext - { - } + public void Initialize(GeneratorInitializationContext context) {} + public void Execute(GeneratorExecutionContext context) {} }"; - private const string SourceGeneratorStub_VisualBasic = @" -Imports System -Imports Microsoft.CodeAnalysis - -Namespace Microsoft.CodeAnalysis - - public Class GeneratorAttribute - Inherits Attribute - End Class - - public interface ISourceGenerator - Sub Initialize(context As GeneratorInitializationContext) - Sub Execute(context As GeneratorExecutionContext) - End Interface - - public Class GeneratorInitializationContext - End Class - - public Class GeneratorExecutionContext - End Class -End Namespace"; - - [Fact] - public async Task TestMissing_CSharp() - { - var code = @" + var fixedCode = @" using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Diagnostics; [Generator] public class CustomGenerator : ISourceGenerator { public void Initialize(GeneratorInitializationContext context) {} - - public void Execute(GeneratorExecutionContext context) - { - } + public void Execute(GeneratorExecutionContext context) {} }"; - await new VerifyCS.Test { TestState = { - Sources = { code , SourceGeneratorStub_CSharp }, - AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} - } - }.RunAsync(); - } - - [Fact] - public async Task TestMissing_VisualBasic() - { - var code = @" -Imports Microsoft.CodeAnalysis - - -Public Class CustomGenerator - Implements ISourceGenerator - - Public Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize - - End Sub - - Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute - - End Sub -End Class"; - - await new VerifyVB.Test - { - TestState = + Sources = { code }, + ReferenceAssemblies = ReferenceAssemblies + }, + FixedState = { - Sources = { code , SourceGeneratorStub_VisualBasic }, - AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} - } + Sources = { fixedCode }, + ReferenceAssemblies = ReferenceAssemblies + }, }.RunAsync(); } [Fact] - public async Task TestSimpleClass_CSharp() + public async Task TestSimpleClass_FullyQualified_CSharp() { var code = @" -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Diagnostics; - -public class [|CustomGenerator|] : ISourceGenerator +public class [|CustomGenerator|] : Microsoft.CodeAnalysis.ISourceGenerator { - public void Initialize(GeneratorInitializationContext context) {} - - public void Execute(GeneratorExecutionContext context) - { - } + public void Initialize(Microsoft.CodeAnalysis.GeneratorInitializationContext context) {} + public void Execute(Microsoft.CodeAnalysis.GeneratorExecutionContext context) {} }"; var fixedCode = @" -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Diagnostics; - -[Generator] -public class CustomGenerator : ISourceGenerator +[Microsoft.CodeAnalysis.Generator] +public class CustomGenerator : Microsoft.CodeAnalysis.ISourceGenerator { - public void Initialize(GeneratorInitializationContext context) {} - - public void Execute(GeneratorExecutionContext context) - { - } + public void Initialize(Microsoft.CodeAnalysis.GeneratorInitializationContext context) {} + public void Execute(Microsoft.CodeAnalysis.GeneratorExecutionContext context) {} }"; await new VerifyCS.Test { TestState = { - Sources = { code , SourceGeneratorStub_CSharp }, - AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} + Sources = { code }, + ReferenceAssemblies = ReferenceAssemblies }, FixedState = { - Sources = { fixedCode, SourceGeneratorStub_CSharp }, - AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference}, + Sources = { fixedCode }, + ReferenceAssemblies = ReferenceAssemblies }, }.RunAsync(); } @@ -202,13 +125,54 @@ End Sub { TestState = { - Sources = { code , SourceGeneratorStub_VisualBasic }, - AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} + Sources = { code }, + ReferenceAssemblies = ReferenceAssemblies + }, + FixedState = + { + Sources = { fixedCode }, + ReferenceAssemblies = ReferenceAssemblies + }, + }.RunAsync(); + } + + [Fact] + public async Task TestSimpleClass_FullyQualified_VisualBasic() + { + var code = @" +Public Class [|CustomGenerator|] + Implements Microsoft.CodeAnalysis.ISourceGenerator + + Public Sub Initialize(context As Microsoft.CodeAnalysis.GeneratorInitializationContext) Implements Microsoft.CodeAnalysis.ISourceGenerator.Initialize + End Sub + + Sub Execute(context As Microsoft.CodeAnalysis.GeneratorExecutionContext) Implements Microsoft.CodeAnalysis.ISourceGenerator.Execute + End Sub +End Class"; + + var fixedCode = @" + +Public Class CustomGenerator + Implements Microsoft.CodeAnalysis.ISourceGenerator + + Public Sub Initialize(context As Microsoft.CodeAnalysis.GeneratorInitializationContext) Implements Microsoft.CodeAnalysis.ISourceGenerator.Initialize + End Sub + + Sub Execute(context As Microsoft.CodeAnalysis.GeneratorExecutionContext) Implements Microsoft.CodeAnalysis.ISourceGenerator.Execute + End Sub +End Class"; + + await new VerifyVB.Test + { + TestState = + { + Sources = { code }, + ReferenceAssemblies = ReferenceAssemblies }, FixedState = { - Sources = { fixedCode, SourceGeneratorStub_VisualBasic }, - AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference}, + Sources = { fixedCode }, + ReferenceAssemblies = ReferenceAssemblies }, }.RunAsync(); } @@ -223,17 +187,13 @@ public async Task TestHierarchy_CSharp() public abstract class CustomGeneratorBase : ISourceGenerator { public abstract void Initialize(GeneratorInitializationContext context); - public abstract void Execute(GeneratorExecutionContext context); } public class [|CustomGenerator|] : CustomGeneratorBase { public override void Initialize(GeneratorInitializationContext context) {} - - public override void Execute(GeneratorExecutionContext context) - { - } + public override void Execute(GeneratorExecutionContext context) {} }"; var fixedCode = @" @@ -243,7 +203,6 @@ public override void Execute(GeneratorExecutionContext context) public abstract class CustomGeneratorBase : ISourceGenerator { public abstract void Initialize(GeneratorInitializationContext context); - public abstract void Execute(GeneratorExecutionContext context); } @@ -251,22 +210,19 @@ public abstract class CustomGeneratorBase : ISourceGenerator public class CustomGenerator : CustomGeneratorBase { public override void Initialize(GeneratorInitializationContext context) {} - - public override void Execute(GeneratorExecutionContext context) - { - } + public override void Execute(GeneratorExecutionContext context) {} }"; await new VerifyCS.Test { TestState = { - Sources = { code , SourceGeneratorStub_CSharp }, - AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} + Sources = { code }, + ReferenceAssemblies = ReferenceAssemblies }, FixedState = { - Sources = { fixedCode, SourceGeneratorStub_CSharp }, - AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference}, + Sources = { fixedCode }, + ReferenceAssemblies = ReferenceAssemblies }, }.RunAsync(); } @@ -288,11 +244,9 @@ Public Class [|CustomGenerator|] Inherits CustomGeneratorBase Public Overrides Sub Initialize(context As GeneratorInitializationContext) - End Sub Public Overrides Sub Execute(context As GeneratorExecutionContext) - End Sub End Class"; @@ -311,11 +265,9 @@ Public Class CustomGenerator Inherits CustomGeneratorBase Public Overrides Sub Initialize(context As GeneratorInitializationContext) - End Sub Public Overrides Sub Execute(context As GeneratorExecutionContext) - End Sub End Class"; @@ -323,13 +275,13 @@ End Sub { TestState = { - Sources = { code , SourceGeneratorStub_VisualBasic }, - AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} + Sources = { code }, + ReferenceAssemblies = ReferenceAssemblies }, FixedState = { - Sources = { fixedCode, SourceGeneratorStub_VisualBasic }, - AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference}, + Sources = { fixedCode }, + ReferenceAssemblies = ReferenceAssemblies }, }.RunAsync(); } @@ -345,24 +297,20 @@ public async Task TestHierarchy_InheritedAttribute_CSharp() public abstract class CustomGeneratorBase : ISourceGenerator { public abstract void Initialize(GeneratorInitializationContext context); - public abstract void Execute(GeneratorExecutionContext context); } public class CustomGenerator : CustomGeneratorBase { public override void Initialize(GeneratorInitializationContext context) {} - - public override void Execute(GeneratorExecutionContext context) - { - } + public override void Execute(GeneratorExecutionContext context) {} }"; await new VerifyCS.Test { TestState = { - Sources = { code , SourceGeneratorStub_CSharp }, - AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} + Sources = { code }, + ReferenceAssemblies = ReferenceAssemblies } }.RunAsync(); } @@ -385,11 +333,9 @@ Public Class CustomGenerator Inherits CustomGeneratorBase Public Overrides Sub Initialize(context As GeneratorInitializationContext) - End Sub Public Overrides Sub Execute(context As GeneratorExecutionContext) - End Sub End Class"; @@ -397,10 +343,10 @@ End Sub { TestState = { - Sources = { code , SourceGeneratorStub_VisualBasic }, - AdditionalReferences = { AdditionalMetadataReferences.CodeAnalysisReference} + Sources = { code }, + ReferenceAssemblies = ReferenceAssemblies } }.RunAsync(); } } -} +} \ No newline at end of file diff --git a/src/Utilities/Compiler/WellKnownTypeNames.cs b/src/Utilities/Compiler/WellKnownTypeNames.cs index ba558e6583..12bb00d74a 100644 --- a/src/Utilities/Compiler/WellKnownTypeNames.cs +++ b/src/Utilities/Compiler/WellKnownTypeNames.cs @@ -44,8 +44,6 @@ internal static class WellKnownTypeNames public const string MicrosoftCodeAnalysisDiagnosticsCompilationStartAnalysisContext = "Microsoft.CodeAnalysis.Diagnostics.CompilationStartAnalysisContext"; public const string MicrosoftCodeAnalysisDiagnosticsDiagnosticAnalyzer = "Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer"; public const string MicrosoftCodeAnalysisDiagnosticsDiagnosticAnalyzerAttribute = "Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzerAttribute"; - public const string MicrosoftCodeAnalysisISourceGenerator = "Microsoft.CodeAnalysis.ISourceGenerator"; - public const string MicrosoftCodeAnalysisGeneratorAttribute = "Microsoft.CodeAnalysis.GeneratorAttribute"; public const string MicrosoftCodeAnalysisDiagnosticsGeneratedCodeAnalysisFlags = "Microsoft.CodeAnalysis.Diagnostics.GeneratedCodeAnalysisFlags"; public const string MicrosoftCodeAnalysisDiagnosticsOperationAnalysisContext = "Microsoft.CodeAnalysis.Diagnostics.OperationAnalysisContext"; public const string MicrosoftCodeAnalysisDiagnosticsOperationBlockAnalysisContext = "Microsoft.CodeAnalysis.Diagnostics.OperationBlockAnalysisContext"; @@ -54,7 +52,9 @@ internal static class WellKnownTypeNames public const string MicrosoftCodeAnalysisDiagnosticsSymbolAnalysisContext = "Microsoft.CodeAnalysis.Diagnostics.SymbolAnalysisContext"; public const string MicrosoftCodeAnalysisDiagnosticsSyntaxNodeAnalysisContext = "Microsoft.CodeAnalysis.Diagnostics.SyntaxNodeAnalysisContext"; public const string MicrosoftCodeAnalysisDiagnosticsSyntaxTreeAnalysisContext = "Microsoft.CodeAnalysis.Diagnostics.SyntaxTreeAnalysisContext"; + public const string MicrosoftCodeAnalysisGeneratorAttribute = "Microsoft.CodeAnalysis.GeneratorAttribute"; public const string MicrosoftCodeAnalysisHostMefMefConstruction = "Microsoft.CodeAnalysis.Host.Mef.MefConstruction"; + public const string MicrosoftCodeAnalysisISourceGenerator = "Microsoft.CodeAnalysis.ISourceGenerator"; public const string MicrosoftCodeAnalysisLocalizableString = "Microsoft.CodeAnalysis.LocalizableString"; public const string MicrosoftCodeAnalysisLocalizableResourceString = "Microsoft.CodeAnalysis.LocalizableResourceString"; public const string MicrosoftCodeAnalysisSharedCollectionsTemporaryArrayExtensions = "Microsoft.CodeAnalysis.Shared.Collections.TemporaryArrayExtensions"; From 8bfe76a82ed4a0fbd7dca306e99e010232efabf1 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Mon, 12 Jul 2021 09:43:05 -0700 Subject: [PATCH 06/27] Formatting --- .../MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs index 9a177d6dad..f857924d4e 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs @@ -16,7 +16,7 @@ namespace Microsoft.CodeAnalysis.Analyzers.UnitTests.MetaAnalyzers { public class MissingGeneratorAttributeRuleTests { - private static readonly ReferenceAssemblies ReferenceAssemblies = + private static readonly ReferenceAssemblies ReferenceAssemblies = ReferenceAssemblies.Default.AddPackages(ImmutableArray.Create(new PackageIdentity("Microsoft.CodeAnalysis", "3.10.0"))); [Fact] From e9528d8d0187eca6aff2e13542dffa12e31b8b3d Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Mon, 12 Jul 2021 12:29:03 -0700 Subject: [PATCH 07/27] Add single quotes around Generator --- .../Core/CodeAnalysisDiagnosticsResources.resx | 6 +++--- .../Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf | 12 ++++++------ .../Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf | 12 ++++++------ .../Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf | 12 ++++++------ .../Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf | 12 ++++++------ .../Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf | 12 ++++++------ .../Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf | 12 ++++++------ .../Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf | 12 ++++++------ .../Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf | 12 ++++++------ .../xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf | 12 ++++++------ .../Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf | 12 ++++++------ .../Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf | 12 ++++++------ .../xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf | 12 ++++++------ .../xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf | 12 ++++++------ 14 files changed, 81 insertions(+), 81 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx b/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx index 8eca932606..97507cc112 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx @@ -530,13 +530,13 @@ Use 'IsKind' instead of 'Kind' - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - Missing Generator attribute + Missing 'Generator' attribute - Missing Generator Attribute + Missing 'Generator' Attribute Add Generator Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf index d779aa8b56..057b844758 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf @@ -238,18 +238,18 @@ - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - Missing Generator attribute - Missing Generator attribute + Missing 'Generator' attribute + Missing 'Generator' attribute - Missing Generator Attribute - Missing Generator Attribute + Missing 'Generator' Attribute + Missing 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf index 147d035748..26d4f06d76 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf @@ -238,18 +238,18 @@ - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - Missing Generator attribute - Missing Generator attribute + Missing 'Generator' attribute + Missing 'Generator' attribute - Missing Generator Attribute - Missing Generator Attribute + Missing 'Generator' Attribute + Missing 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf index 85df5a3f1b..bdf8330ff3 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf @@ -238,18 +238,18 @@ - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - Missing Generator attribute - Missing Generator attribute + Missing 'Generator' attribute + Missing 'Generator' attribute - Missing Generator Attribute - Missing Generator Attribute + Missing 'Generator' Attribute + Missing 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf index c75aabec6a..6d67b0b706 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf @@ -238,18 +238,18 @@ - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - Missing Generator attribute - Missing Generator attribute + Missing 'Generator' attribute + Missing 'Generator' attribute - Missing Generator Attribute - Missing Generator Attribute + Missing 'Generator' Attribute + Missing 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf index 9e27851d9f..cdf23df918 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf @@ -238,18 +238,18 @@ - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - Missing Generator attribute - Missing Generator attribute + Missing 'Generator' attribute + Missing 'Generator' attribute - Missing Generator Attribute - Missing Generator Attribute + Missing 'Generator' Attribute + Missing 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf index 729427d329..e5e10754d7 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf @@ -238,18 +238,18 @@ - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - Missing Generator attribute - Missing Generator attribute + Missing 'Generator' attribute + Missing 'Generator' attribute - Missing Generator Attribute - Missing Generator Attribute + Missing 'Generator' Attribute + Missing 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf index f4209a5f1f..4d2e24d838 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf @@ -238,18 +238,18 @@ - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - Missing Generator attribute - Missing Generator attribute + Missing 'Generator' attribute + Missing 'Generator' attribute - Missing Generator Attribute - Missing Generator Attribute + Missing 'Generator' Attribute + Missing 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf index 843a4a0bac..728648f02e 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf @@ -238,18 +238,18 @@ - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - Missing Generator attribute - Missing Generator attribute + Missing 'Generator' attribute + Missing 'Generator' attribute - Missing Generator Attribute - Missing Generator Attribute + Missing 'Generator' Attribute + Missing 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf index 48307a78b5..f0b3cfa5f5 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf @@ -238,18 +238,18 @@ - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - Missing Generator attribute - Missing Generator attribute + Missing 'Generator' attribute + Missing 'Generator' attribute - Missing Generator Attribute - Missing Generator Attribute + Missing 'Generator' Attribute + Missing 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf index 864a9c2691..269a22b589 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf @@ -238,18 +238,18 @@ - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - Missing Generator attribute - Missing Generator attribute + Missing 'Generator' attribute + Missing 'Generator' attribute - Missing Generator Attribute - Missing Generator Attribute + Missing 'Generator' Attribute + Missing 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf index 93dae8d8fa..4700ce1326 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf @@ -238,18 +238,18 @@ - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - Missing Generator attribute - Missing Generator attribute + Missing 'Generator' attribute + Missing 'Generator' attribute - Missing Generator Attribute - Missing Generator Attribute + Missing 'Generator' Attribute + Missing 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf index daf30c50d1..f82ea243d9 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf @@ -238,18 +238,18 @@ - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - Missing Generator attribute - Missing Generator attribute + Missing 'Generator' attribute + Missing 'Generator' attribute - Missing Generator Attribute - Missing Generator Attribute + Missing 'Generator' Attribute + Missing 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf index da0c5ffbda..5703f7e2e1 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf @@ -238,18 +238,18 @@ - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. - '{0}' implements 'ISourceGenerator' but does not have the Generator attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. + '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - Missing Generator attribute - Missing Generator attribute + Missing 'Generator' attribute + Missing 'Generator' attribute - Missing Generator Attribute - Missing Generator Attribute + Missing 'Generator' Attribute + Missing 'Generator' Attribute From edeb51e17c3077a58aa3f54713c14cbe14088e0a Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Mon, 12 Jul 2021 12:30:04 -0700 Subject: [PATCH 08/27] One more set of quotes... --- .../Core/CodeAnalysisDiagnosticsResources.resx | 2 +- .../Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf | 4 ++-- .../Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf | 4 ++-- 14 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx b/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx index 97507cc112..7054e28cc6 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx @@ -539,6 +539,6 @@ Missing 'Generator' Attribute - Add Generator Attribute + Add 'Generator' Attribute \ No newline at end of file diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf index 057b844758..8895faace3 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf @@ -8,8 +8,8 @@ - Add Generator Attribute - Add Generator Attribute + Add 'Generator' Attribute + Add 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf index 26d4f06d76..065ffb30d1 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf @@ -8,8 +8,8 @@ - Add Generator Attribute - Add Generator Attribute + Add 'Generator' Attribute + Add 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf index bdf8330ff3..4024cc70fb 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf @@ -8,8 +8,8 @@ - Add Generator Attribute - Add Generator Attribute + Add 'Generator' Attribute + Add 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf index 6d67b0b706..0f10d5959a 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf @@ -8,8 +8,8 @@ - Add Generator Attribute - Add Generator Attribute + Add 'Generator' Attribute + Add 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf index cdf23df918..8405804d35 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf @@ -8,8 +8,8 @@ - Add Generator Attribute - Add Generator Attribute + Add 'Generator' Attribute + Add 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf index e5e10754d7..8915774cc4 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf @@ -8,8 +8,8 @@ - Add Generator Attribute - Add Generator Attribute + Add 'Generator' Attribute + Add 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf index 4d2e24d838..56bb7acc8b 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf @@ -8,8 +8,8 @@ - Add Generator Attribute - Add Generator Attribute + Add 'Generator' Attribute + Add 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf index 728648f02e..50556bb58e 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf @@ -8,8 +8,8 @@ - Add Generator Attribute - Add Generator Attribute + Add 'Generator' Attribute + Add 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf index f0b3cfa5f5..f23c0e4082 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf @@ -8,8 +8,8 @@ - Add Generator Attribute - Add Generator Attribute + Add 'Generator' Attribute + Add 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf index 269a22b589..0abc9e4a46 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf @@ -8,8 +8,8 @@ - Add Generator Attribute - Add Generator Attribute + Add 'Generator' Attribute + Add 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf index 4700ce1326..13d24ecb08 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf @@ -8,8 +8,8 @@ - Add Generator Attribute - Add Generator Attribute + Add 'Generator' Attribute + Add 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf index f82ea243d9..e3974cfcf6 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf @@ -8,8 +8,8 @@ - Add Generator Attribute - Add Generator Attribute + Add 'Generator' Attribute + Add 'Generator' Attribute diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf index 5703f7e2e1..bfa392ecf5 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf @@ -8,8 +8,8 @@ - Add Generator Attribute - Add Generator Attribute + Add 'Generator' Attribute + Add 'Generator' Attribute From e9c44320fc1319d4f9fe5219539883d46838d238 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Mon, 12 Jul 2021 16:20:04 -0700 Subject: [PATCH 09/27] Update src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs Co-authored-by: Youssef Victor --- .../MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs index bf6ad8cd4a..b16585a99b 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs @@ -35,7 +35,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) CodeAction.Create( CodeAnalysisDiagnosticsResources.AddGeneratorAttribute, c => FixDocumentAsync(document, node, c), - equivalenceKey: nameof(SourceGeneratorAttributeAnalyzerFix)), + equivalenceKey: nameof(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute)), diagnostic); } } From 4399ef34a2d51b57dc6a2be300368a1cc4777d37 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Mon, 12 Jul 2021 17:34:55 -0700 Subject: [PATCH 10/27] Generate docs --- .../Microsoft.CodeAnalysis.Analyzers.md | 12 ++++++++++++ .../Microsoft.CodeAnalysis.Analyzers.sarif | 15 +++++++++++++++ .../RulesMissingDocumentation.md | 1 + 3 files changed, 28 insertions(+) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.md b/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.md index 830e2f3842..271f4dbf42 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.md +++ b/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.md @@ -424,6 +424,18 @@ Prefer 'syntax.IsKind(kind)' to 'syntax.Kind() == kind' when checking syntax kin |CodeFix|True| --- +## RS1035: Missing 'Generator' Attribute + +'{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. + +|Item|Value| +|-|-| +|Category|MicrosoftCodeAnalysisCorrectness| +|Enabled|True| +|Severity|Warning| +|CodeFix|True| +--- + ## [RS2000](https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md): Add analyzer diagnostic IDs to analyzer release All supported analyzer diagnostic IDs should be part of an analyzer release. diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.sarif b/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.sarif index 35294485e6..66bfd38e3d 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.sarif +++ b/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.sarif @@ -442,6 +442,21 @@ ] } }, + "RS1035": { + "id": "RS1035", + "shortDescription": "Missing 'Generator' Attribute", + "fullDescription": "'{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute.", + "defaultLevel": "warning", + "properties": { + "category": "MicrosoftCodeAnalysisCorrectness", + "isEnabledByDefault": true, + "typeName": "SourceGeneratorAttributeAnalyzer", + "languages": [ + "C#", + "Visual Basic" + ] + } + }, "RS2000": { "id": "RS2000", "shortDescription": "Add analyzer diagnostic IDs to analyzer release", diff --git a/src/Microsoft.CodeAnalysis.Analyzers/RulesMissingDocumentation.md b/src/Microsoft.CodeAnalysis.Analyzers/RulesMissingDocumentation.md index 46b1e4b42b..12f7e38fad 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/RulesMissingDocumentation.md +++ b/src/Microsoft.CodeAnalysis.Analyzers/RulesMissingDocumentation.md @@ -35,3 +35,4 @@ RS1031 | | Define diagnostic title correctly | RS1032 | | Define diagnostic message correctly | RS1033 | | Define diagnostic description correctly | RS1034 | | Prefer 'IsKind' for checking syntax kinds | +RS1035 | | Missing 'Generator' Attribute | From e743540e5f5316f6b4d9fb59c1623d59852bf3c6 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Mon, 12 Jul 2021 17:38:25 -0700 Subject: [PATCH 11/27] Make separate code action class again --- .../Fixers/SourceGeneratorAttributeAnalyzerFix.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs index b16585a99b..937244b017 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Immutable; using System.Composition; using System.Threading; @@ -32,10 +33,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) foreach (var diagnostic in context.Diagnostics) { context.RegisterCodeFix( - CodeAction.Create( - CodeAnalysisDiagnosticsResources.AddGeneratorAttribute, - c => FixDocumentAsync(document, node, c), - equivalenceKey: nameof(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute)), + new MyCodeAction(c => FixDocumentAsync(document, node, c)), diagnostic); } } @@ -52,5 +50,13 @@ private static async Task FixDocumentAsync(Document document, SyntaxNo return editor.GetChangedDocument(); } + + private class MyCodeAction : DocumentChangeAction + { + public MyCodeAction(Func> func) + : base(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute, func, nameof(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute)) + { + } + } } } From 27433df0e6f99d33881c62b5f7c55a2530a1f82a Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Thu, 12 Aug 2021 12:47:55 -0700 Subject: [PATCH 12/27] Apply suggestions from code review Co-authored-by: Youssef Victor Co-authored-by: Sam Harwell --- .../Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs | 2 +- .../MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs index e695450f34..0f79b576ad 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs @@ -50,7 +50,7 @@ private static void AnalyzeSymbol(SymbolAnalysisContext c, INamedTypeSymbol sour return; } - if (!symbol.AllInterfaces.Any(i => sourceGenerator.Equals(i, SymbolEqualityComparer.Default))) + if (!symbol.AllInterfaces.Contains(sourceGenerator)) { return; } diff --git a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs index f857924d4e..ac0b053c34 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs @@ -42,15 +42,14 @@ public void Execute(GeneratorExecutionContext context) {} }"; await new VerifyCS.Test { + ReferenceAssemblies = ReferenceAssemblies, TestState = { Sources = { code }, - ReferenceAssemblies = ReferenceAssemblies }, FixedState = { Sources = { fixedCode }, - ReferenceAssemblies = ReferenceAssemblies }, }.RunAsync(); } From e2b0caa9775e1a376a4417c72a18c8a801b07f43 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Thu, 12 Aug 2021 13:00:00 -0700 Subject: [PATCH 13/27] Fix headers. Change to CodeAction.Create --- .../SourceGeneratorAttributeAnalyzerFix.cs | 18 ++++++------------ .../SourceGeneratorAttributeAnalyzer.cs | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs index 937244b017..37b00159e4 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. using System; using System.Collections.Immutable; @@ -32,9 +32,11 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) foreach (var diagnostic in context.Diagnostics) { - context.RegisterCodeFix( - new MyCodeAction(c => FixDocumentAsync(document, node, c)), - diagnostic); + var codeAction = CodeAction.Create(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute, + (cancellationToken) => FixDocumentAsync(document, node, cancellationToken), + nameof(SourceGeneratorAttributeAnalyzerFix)); + + context.RegisterCodeFix(codeAction, diagnostic); } } @@ -50,13 +52,5 @@ private static async Task FixDocumentAsync(Document document, SyntaxNo return editor.GetChangedDocument(); } - - private class MyCodeAction : DocumentChangeAction - { - public MyCodeAction(Func> func) - : base(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute, func, nameof(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute)) - { - } - } } } diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs index 0f79b576ad..556e3a2e2a 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. using System.Collections.Immutable; using System.Linq; From d47cb84c4b217ec505c36c0b780f685515c496ec Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Thu, 12 Aug 2021 15:33:56 -0700 Subject: [PATCH 14/27] WIP --- .../CodeAnalysisDiagnosticsResources.resx | 9 ++- .../SourceGeneratorAttributeAnalyzerFix.cs | 66 +++++++++++++++++-- .../CodeAnalysisDiagnosticsResources.cs.xlf | 13 ++-- .../CodeAnalysisDiagnosticsResources.de.xlf | 13 ++-- .../CodeAnalysisDiagnosticsResources.es.xlf | 13 ++-- .../CodeAnalysisDiagnosticsResources.fr.xlf | 13 ++-- .../CodeAnalysisDiagnosticsResources.it.xlf | 13 ++-- .../CodeAnalysisDiagnosticsResources.ja.xlf | 13 ++-- .../CodeAnalysisDiagnosticsResources.ko.xlf | 13 ++-- .../CodeAnalysisDiagnosticsResources.pl.xlf | 13 ++-- ...CodeAnalysisDiagnosticsResources.pt-BR.xlf | 13 ++-- .../CodeAnalysisDiagnosticsResources.ru.xlf | 13 ++-- .../CodeAnalysisDiagnosticsResources.tr.xlf | 13 ++-- ...deAnalysisDiagnosticsResources.zh-Hans.xlf | 13 ++-- ...deAnalysisDiagnosticsResources.zh-Hant.xlf | 13 ++-- .../MissingGeneratorAttributeRuleTests.cs | 21 +++--- 16 files changed, 192 insertions(+), 73 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx b/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx index 7054e28cc6..9f70105686 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx @@ -538,7 +538,12 @@ Missing 'Generator' Attribute - - Add 'Generator' Attribute + + Apply Generator attribute for '{0}'. + "Generator" is a named type and should not be changed + + + Apply Generator attribute for both '{0}' and '{1}'. + "Generator" is a type name and should not be changed \ No newline at end of file diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs index 37b00159e4..af1e7eff7a 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs @@ -3,6 +3,8 @@ using System; using System.Collections.Immutable; using System.Composition; +using System.Diagnostics.Contracts; +using System.Linq; using System.Threading; using System.Threading.Tasks; using Analyzer.Utilities; @@ -32,21 +34,73 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) foreach (var diagnostic in context.Diagnostics) { - var codeAction = CodeAction.Create(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute, - (cancellationToken) => FixDocumentAsync(document, node, cancellationToken), - nameof(SourceGeneratorAttributeAnalyzerFix)); + AddFix( + string.Format(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_1, LanguageNames.CSharp), + context, document, node, diagnostic, LanguageNames.CSharp); - context.RegisterCodeFix(codeAction, diagnostic); + AddFix( + string.Format(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_1, LanguageNames.VisualBasic), + context, document, node, diagnostic, LanguageNames.VisualBasic); + + AddFix( + string.Format(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_2, LanguageNames.CSharp, LanguageNames.VisualBasic), + context, document, node, diagnostic, LanguageNames.CSharp, LanguageNames.VisualBasic); } } + private void AddFix(string title, CodeFixContext context, Document document, SyntaxNode node, Diagnostic diagnostic, params string[] languageNames) + { + var codeAction = CodeAction.Create( + title, + (cancellationToken) => FixDocumentAsync(document, node, languageNames, cancellationToken), + equivalenceKey: nameof(SourceGeneratorAttributeAnalyzerFix)); + + context.RegisterCodeFix(codeAction, diagnostic); + } + public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; - private static async Task FixDocumentAsync(Document document, SyntaxNode node, CancellationToken cancellationToken) + private static async Task FixDocumentAsync(Document document, SyntaxNode node, string[] languageNames, CancellationToken cancellationToken) { var editor = await DocumentEditor.CreateAsync(document, cancellationToken).ConfigureAwait(false); var generator = editor.Generator; - var generatorAttribute = generator.Attribute(WellKnownTypeNames.MicrosoftCodeAnalysisGeneratorAttribute); + + SyntaxNode? generatorAttribute; + + if (languageNames.Length == 1 && languageNames[0] == LanguageNames.CSharp) + { + // CSharp is the only language, which is the default paramterless + // constructor for the Generator attribute + generatorAttribute = generator.Attribute(WellKnownTypeNames.MicrosoftCodeAnalysisGeneratorAttribute); + } + else + { + // For cases where the language is VB or VB and CSharp, add + // an argument to signify that + var languageNamesFullName = typeof(LanguageNames).FullName; + var splitLanguageNames = languageNamesFullName.Split('.'); + + var baseLanguageNameExpression = generator.IdentifierName(splitLanguageNames[0]); + foreach (var identifier in splitLanguageNames.Skip(1)) + { + baseLanguageNameExpression = generator.MemberAccessExpression(baseLanguageNameExpression, identifier); + } + + var arguments = new SyntaxNode[languageNames.Length]; + for (var i = 0; i < languageNames.Length; i++) + { + RoslynDebug.Assert(languageNames[i] == LanguageNames.CSharp || languageNames[i] == LanguageNames.VisualBasic); + + var language = languageNames[i] == LanguageNames.CSharp + ? nameof(LanguageNames.CSharp) + : nameof(LanguageNames.VisualBasic); + + var finalExpression = generator.MemberAccessExpression(baseLanguageNameExpression, language); + arguments[i] = finalExpression; + } + + generatorAttribute = generator.Attribute(WellKnownTypeNames.MicrosoftCodeAnalysisGeneratorAttribute, arguments); + } editor.ReplaceNode(node, generator.AddAttributes(node, generatorAttribute)); diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf index 8895faace3..5ec81bc7a1 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf @@ -7,10 +7,15 @@ Přidat položku pravidla k nevydanému souboru verze - - Add 'Generator' Attribute - Add 'Generator' Attribute - + + Apply Generator attribute for '{0}'. + Apply Generator attribute for '{0}'. + "Generator" is a named type and should not be changed + + + Apply Generator attribute for both '{0}' and '{1}'. + Apply Generator attribute for both '{0}' and '{1}'. + "Generator" is a type name and should not be changed Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf index 065ffb30d1..8adc086f9c 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf @@ -7,10 +7,15 @@ Regeleintrag der nicht veröffentlichten Releasedatei hinzufügen - - Add 'Generator' Attribute - Add 'Generator' Attribute - + + Apply Generator attribute for '{0}'. + Apply Generator attribute for '{0}'. + "Generator" is a named type and should not be changed + + + Apply Generator attribute for both '{0}' and '{1}'. + Apply Generator attribute for both '{0}' and '{1}'. + "Generator" is a type name and should not be changed Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf index 4024cc70fb..a00204d9d3 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf @@ -7,10 +7,15 @@ Agregar una entrada de regla a un archivo de versión no incluido - - Add 'Generator' Attribute - Add 'Generator' Attribute - + + Apply Generator attribute for '{0}'. + Apply Generator attribute for '{0}'. + "Generator" is a named type and should not be changed + + + Apply Generator attribute for both '{0}' and '{1}'. + Apply Generator attribute for both '{0}' and '{1}'. + "Generator" is a type name and should not be changed Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf index 0f10d5959a..bd3f2a9406 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf @@ -7,10 +7,15 @@ Ajouter une entrée de règle au fichier de version non fourni - - Add 'Generator' Attribute - Add 'Generator' Attribute - + + Apply Generator attribute for '{0}'. + Apply Generator attribute for '{0}'. + "Generator" is a named type and should not be changed + + + Apply Generator attribute for both '{0}' and '{1}'. + Apply Generator attribute for both '{0}' and '{1}'. + "Generator" is a type name and should not be changed Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf index 8405804d35..59ae87e74f 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf @@ -7,10 +7,15 @@ Aggiungere la voce della regola per il file di versione non distribuito - - Add 'Generator' Attribute - Add 'Generator' Attribute - + + Apply Generator attribute for '{0}'. + Apply Generator attribute for '{0}'. + "Generator" is a named type and should not be changed + + + Apply Generator attribute for both '{0}' and '{1}'. + Apply Generator attribute for both '{0}' and '{1}'. + "Generator" is a type name and should not be changed Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf index 8915774cc4..a7b38a1e3b 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf @@ -7,10 +7,15 @@ 未出荷のリリース ファイルへのルール エントリの追加 - - Add 'Generator' Attribute - Add 'Generator' Attribute - + + Apply Generator attribute for '{0}'. + Apply Generator attribute for '{0}'. + "Generator" is a named type and should not be changed + + + Apply Generator attribute for both '{0}' and '{1}'. + Apply Generator attribute for both '{0}' and '{1}'. + "Generator" is a type name and should not be changed Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf index 56bb7acc8b..25c75d2120 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf @@ -7,10 +7,15 @@ 제공되지 않은 릴리스 파일에 규칙 항목 추가 - - Add 'Generator' Attribute - Add 'Generator' Attribute - + + Apply Generator attribute for '{0}'. + Apply Generator attribute for '{0}'. + "Generator" is a named type and should not be changed + + + Apply Generator attribute for both '{0}' and '{1}'. + Apply Generator attribute for both '{0}' and '{1}'. + "Generator" is a type name and should not be changed Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf index 50556bb58e..58365c46ff 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf @@ -7,10 +7,15 @@ Dodaj wpis reguły do niedostarczonego pliku wydania - - Add 'Generator' Attribute - Add 'Generator' Attribute - + + Apply Generator attribute for '{0}'. + Apply Generator attribute for '{0}'. + "Generator" is a named type and should not be changed + + + Apply Generator attribute for both '{0}' and '{1}'. + Apply Generator attribute for both '{0}' and '{1}'. + "Generator" is a type name and should not be changed Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf index f23c0e4082..029b1064bd 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf @@ -7,10 +7,15 @@ Adicionar uma entrada de regra ao arquivo de versão não enviado - - Add 'Generator' Attribute - Add 'Generator' Attribute - + + Apply Generator attribute for '{0}'. + Apply Generator attribute for '{0}'. + "Generator" is a named type and should not be changed + + + Apply Generator attribute for both '{0}' and '{1}'. + Apply Generator attribute for both '{0}' and '{1}'. + "Generator" is a type name and should not be changed Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf index 0abc9e4a46..76c597e1df 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf @@ -7,10 +7,15 @@ Добавить запись правила в неотправленный файл выпуска - - Add 'Generator' Attribute - Add 'Generator' Attribute - + + Apply Generator attribute for '{0}'. + Apply Generator attribute for '{0}'. + "Generator" is a named type and should not be changed + + + Apply Generator attribute for both '{0}' and '{1}'. + Apply Generator attribute for both '{0}' and '{1}'. + "Generator" is a type name and should not be changed Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf index 13d24ecb08..6e9d17baf9 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf @@ -7,10 +7,15 @@ Gönderilmeyen yayın dosyasına kural girişi ekle - - Add 'Generator' Attribute - Add 'Generator' Attribute - + + Apply Generator attribute for '{0}'. + Apply Generator attribute for '{0}'. + "Generator" is a named type and should not be changed + + + Apply Generator attribute for both '{0}' and '{1}'. + Apply Generator attribute for both '{0}' and '{1}'. + "Generator" is a type name and should not be changed Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf index e3974cfcf6..0fa66e75e7 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf @@ -7,10 +7,15 @@ 将规则项添加到未提供的版本文件 - - Add 'Generator' Attribute - Add 'Generator' Attribute - + + Apply Generator attribute for '{0}'. + Apply Generator attribute for '{0}'. + "Generator" is a named type and should not be changed + + + Apply Generator attribute for both '{0}' and '{1}'. + Apply Generator attribute for both '{0}' and '{1}'. + "Generator" is a type name and should not be changed Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf index bfa392ecf5..bd98c81e5a 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf @@ -7,10 +7,15 @@ 將規則項目新增至未送出的版本檔案 - - Add 'Generator' Attribute - Add 'Generator' Attribute - + + Apply Generator attribute for '{0}'. + Apply Generator attribute for '{0}'. + "Generator" is a named type and should not be changed + + + Apply Generator attribute for both '{0}' and '{1}'. + Apply Generator attribute for both '{0}' and '{1}'. + "Generator" is a type name and should not be changed Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs index ac0b053c34..bf82d1729a 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs @@ -73,15 +73,14 @@ public void Execute(Microsoft.CodeAnalysis.GeneratorExecutionContext context) {} }"; await new VerifyCS.Test { + ReferenceAssemblies = ReferenceAssemblies, TestState = { Sources = { code }, - ReferenceAssemblies = ReferenceAssemblies }, FixedState = { Sources = { fixedCode }, - ReferenceAssemblies = ReferenceAssemblies }, }.RunAsync(); } @@ -122,15 +121,14 @@ End Sub await new VerifyVB.Test { + ReferenceAssemblies = ReferenceAssemblies, TestState = { Sources = { code }, - ReferenceAssemblies = ReferenceAssemblies }, FixedState = { Sources = { fixedCode }, - ReferenceAssemblies = ReferenceAssemblies }, }.RunAsync(); } @@ -163,15 +161,14 @@ End Sub await new VerifyVB.Test { + ReferenceAssemblies = ReferenceAssemblies, TestState = { Sources = { code }, - ReferenceAssemblies = ReferenceAssemblies }, FixedState = { Sources = { fixedCode }, - ReferenceAssemblies = ReferenceAssemblies }, }.RunAsync(); } @@ -213,15 +210,14 @@ public override void Execute(GeneratorExecutionContext context) {} }"; await new VerifyCS.Test { + ReferenceAssemblies = ReferenceAssemblies, TestState = { Sources = { code }, - ReferenceAssemblies = ReferenceAssemblies }, FixedState = { Sources = { fixedCode }, - ReferenceAssemblies = ReferenceAssemblies }, }.RunAsync(); } @@ -272,15 +268,14 @@ End Sub await new VerifyVB.Test { + ReferenceAssemblies = ReferenceAssemblies, TestState = { Sources = { code }, - ReferenceAssemblies = ReferenceAssemblies }, FixedState = { Sources = { fixedCode }, - ReferenceAssemblies = ReferenceAssemblies }, }.RunAsync(); } @@ -306,10 +301,10 @@ public override void Execute(GeneratorExecutionContext context) {} }"; await new VerifyCS.Test { + ReferenceAssemblies = ReferenceAssemblies, TestState = { Sources = { code }, - ReferenceAssemblies = ReferenceAssemblies } }.RunAsync(); } @@ -340,10 +335,10 @@ End Sub await new VerifyVB.Test { + ReferenceAssemblies = ReferenceAssemblies, TestState = { - Sources = { code }, - ReferenceAssemblies = ReferenceAssemblies + Sources = { code } } }.RunAsync(); } From 2d5e21b8e882426cffa71ece0b03fa50402c327c Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Fri, 3 Sep 2021 13:19:18 -0700 Subject: [PATCH 15/27] Remove getInnermostNodeForTie --- .../Fixers/SourceGeneratorAttributeAnalyzerFix.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs index af1e7eff7a..1c7e129ee2 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs @@ -1,9 +1,7 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. -using System; using System.Collections.Immutable; using System.Composition; -using System.Diagnostics.Contracts; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -25,7 +23,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var document = context.Document; var root = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); - var node = root.FindNode(context.Span, getInnermostNodeForTie: true); + var node = root.FindNode(context.Span); if (node is null) { From 81fad3a9b0dece47211da869a63b330bd094a852 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Fri, 3 Sep 2021 13:36:31 -0700 Subject: [PATCH 16/27] Add CultureInfo.CurrentCulture to string.Format calls --- .../Fixers/SourceGeneratorAttributeAnalyzerFix.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs index 1c7e129ee2..ea7ac2e083 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs @@ -2,6 +2,7 @@ using System.Collections.Immutable; using System.Composition; +using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -33,15 +34,15 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) foreach (var diagnostic in context.Diagnostics) { AddFix( - string.Format(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_1, LanguageNames.CSharp), + string.Format(CultureInfo.CurrentCulture, CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_1, LanguageNames.CSharp), context, document, node, diagnostic, LanguageNames.CSharp); AddFix( - string.Format(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_1, LanguageNames.VisualBasic), + string.Format(CultureInfo.CurrentCulture, CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_1, LanguageNames.VisualBasic), context, document, node, diagnostic, LanguageNames.VisualBasic); AddFix( - string.Format(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_2, LanguageNames.CSharp, LanguageNames.VisualBasic), + string.Format(CultureInfo.CurrentCulture, CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_2, LanguageNames.CSharp, LanguageNames.VisualBasic), context, document, node, diagnostic, LanguageNames.CSharp, LanguageNames.VisualBasic); } } From 96a23beccbd44be7232c97f3b1028c4a1af5175f Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Tue, 28 Sep 2021 23:32:00 -0700 Subject: [PATCH 17/27] Fix tests, update to no longer have batch fix now that languagename must be selected --- .../SourceGeneratorAttributeAnalyzerFix.cs | 4 +- .../MissingGeneratorAttributeRuleTests.cs | 94 +++++++------------ 2 files changed, 35 insertions(+), 63 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs index ea7ac2e083..797caad876 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs @@ -47,7 +47,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) } } - private void AddFix(string title, CodeFixContext context, Document document, SyntaxNode node, Diagnostic diagnostic, params string[] languageNames) + private static void AddFix(string title, CodeFixContext context, Document document, SyntaxNode node, Diagnostic diagnostic, params string[] languageNames) { var codeAction = CodeAction.Create( title, @@ -57,7 +57,7 @@ private void AddFix(string title, CodeFixContext context, Document document, Syn context.RegisterCodeFix(codeAction, diagnostic); } - public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; + public override FixAllProvider GetFixAllProvider() => null; private static async Task FixDocumentAsync(Document document, SyntaxNode node, string[] languageNames, CancellationToken cancellationToken) { diff --git a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs index bf82d1729a..e1e78c9a11 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. using System.Collections.Immutable; using System.Threading.Tasks; @@ -19,8 +19,11 @@ public class MissingGeneratorAttributeRuleTests private static readonly ReferenceAssemblies ReferenceAssemblies = ReferenceAssemblies.Default.AddPackages(ImmutableArray.Create(new PackageIdentity("Microsoft.CodeAnalysis", "3.10.0"))); - [Fact] - public async Task TestSimpleClass_CSharp() + [Theory] + [InlineData("[Generator]", 0)] + [InlineData("[Generator(LanguageNames.VisualBasic)]", 1)] + [InlineData("[Generator(LanguageNames.CSharp, LanguageNames.VisualBasic)]", 2)] + public async Task TestSimpleClass_CSharp(string attr, int index) { var code = @" using Microsoft.CodeAnalysis; @@ -31,26 +34,21 @@ public void Initialize(GeneratorInitializationContext context) {} public void Execute(GeneratorExecutionContext context) {} }"; - var fixedCode = @" + var fixedCode = @$" using Microsoft.CodeAnalysis; -[Generator] +{attr} public class CustomGenerator : ISourceGenerator -{ - public void Initialize(GeneratorInitializationContext context) {} - public void Execute(GeneratorExecutionContext context) {} -}"; +{{ + public void Initialize(GeneratorInitializationContext context) {{}} + public void Execute(GeneratorExecutionContext context) {{}} +}}"; await new VerifyCS.Test { ReferenceAssemblies = ReferenceAssemblies, - TestState = - { - Sources = { code }, - }, - FixedState = - { - Sources = { fixedCode }, - }, + TestCode = code, + FixedCode = fixedCode, + CodeActionIndex = index }.RunAsync(); } @@ -85,8 +83,11 @@ public void Execute(Microsoft.CodeAnalysis.GeneratorExecutionContext context) {} }.RunAsync(); } - [Fact] - public async Task TestSimpleClass_VisualBasic() + [Theory] + [InlineData("", 0)] + [InlineData("", 1)] + [InlineData("", 2)] + public async Task TestSimpleClass_VisualBasic(string attr, int index) { var code = @" Imports Microsoft.CodeAnalysis @@ -103,10 +104,10 @@ Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Ex End Sub End Class"; - var fixedCode = @" + var fixedCode = @$" Imports Microsoft.CodeAnalysis - +{attr} Public Class CustomGenerator Implements ISourceGenerator @@ -122,14 +123,9 @@ End Sub await new VerifyVB.Test { ReferenceAssemblies = ReferenceAssemblies, - TestState = - { - Sources = { code }, - }, - FixedState = - { - Sources = { fixedCode }, - }, + TestCode = code, + FixedCode = fixedCode, + CodeActionIndex = index }.RunAsync(); } @@ -162,14 +158,8 @@ End Sub await new VerifyVB.Test { ReferenceAssemblies = ReferenceAssemblies, - TestState = - { - Sources = { code }, - }, - FixedState = - { - Sources = { fixedCode }, - }, + TestCode = code, + FixedCode = fixedCode, }.RunAsync(); } @@ -211,14 +201,8 @@ public override void Execute(GeneratorExecutionContext context) {} await new VerifyCS.Test { ReferenceAssemblies = ReferenceAssemblies, - TestState = - { - Sources = { code }, - }, - FixedState = - { - Sources = { fixedCode }, - }, + TestCode = code, + FixedCode = fixedCode, }.RunAsync(); } @@ -269,14 +253,8 @@ End Sub await new VerifyVB.Test { ReferenceAssemblies = ReferenceAssemblies, - TestState = - { - Sources = { code }, - }, - FixedState = - { - Sources = { fixedCode }, - }, + TestCode = code, + FixedCode = fixedCode, }.RunAsync(); } @@ -302,10 +280,7 @@ public override void Execute(GeneratorExecutionContext context) {} await new VerifyCS.Test { ReferenceAssemblies = ReferenceAssemblies, - TestState = - { - Sources = { code }, - } + TestCode = code, }.RunAsync(); } @@ -336,10 +311,7 @@ End Sub await new VerifyVB.Test { ReferenceAssemblies = ReferenceAssemblies, - TestState = - { - Sources = { code } - } + TestCode = code, }.RunAsync(); } } From 2f43a8247a677e9a168e13be23fc7228d67112e4 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Tue, 28 Sep 2021 23:40:10 -0700 Subject: [PATCH 18/27] do nullable right... --- .../MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs index 797caad876..a2056a2e8b 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs @@ -57,7 +57,7 @@ private static void AddFix(string title, CodeFixContext context, Document docume context.RegisterCodeFix(codeAction, diagnostic); } - public override FixAllProvider GetFixAllProvider() => null; + public override FixAllProvider? GetFixAllProvider() => null; private static async Task FixDocumentAsync(Document document, SyntaxNode node, string[] languageNames, CancellationToken cancellationToken) { From 8686834b666cce01c68e82966188c6d445f3f225 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Tue, 28 Sep 2021 23:58:18 -0700 Subject: [PATCH 19/27] PR feedback --- .../Fixers/SourceGeneratorAttributeAnalyzerFix.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs index a2056a2e8b..8c28e6dbbf 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs @@ -17,7 +17,7 @@ namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.Fixers [Shared] public sealed class SourceGeneratorAttributeAnalyzerFix : CodeFixProvider { - public override ImmutableArray FixableDiagnosticIds => ImmutableArray.Create( + public override ImmutableArray FixableDiagnosticIds { get; } = ImmutableArray.Create( DiagnosticIds.MissingSourceGeneratorAttributeId); public override async Task RegisterCodeFixesAsync(CodeFixContext context) @@ -34,15 +34,15 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) foreach (var diagnostic in context.Diagnostics) { AddFix( - string.Format(CultureInfo.CurrentCulture, CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_1, LanguageNames.CSharp), + string.Format(CultureInfo.CurrentUICulture, CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_1, LanguageNames.CSharp), context, document, node, diagnostic, LanguageNames.CSharp); AddFix( - string.Format(CultureInfo.CurrentCulture, CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_1, LanguageNames.VisualBasic), + string.Format(CultureInfo.CurrentUICulture, CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_1, LanguageNames.VisualBasic), context, document, node, diagnostic, LanguageNames.VisualBasic); AddFix( - string.Format(CultureInfo.CurrentCulture, CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_2, LanguageNames.CSharp, LanguageNames.VisualBasic), + string.Format(CultureInfo.CurrentUICulture, CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_2, LanguageNames.CSharp, LanguageNames.VisualBasic), context, document, node, diagnostic, LanguageNames.CSharp, LanguageNames.VisualBasic); } } @@ -90,9 +90,7 @@ private static async Task FixDocumentAsync(Document document, SyntaxNo { RoslynDebug.Assert(languageNames[i] == LanguageNames.CSharp || languageNames[i] == LanguageNames.VisualBasic); - var language = languageNames[i] == LanguageNames.CSharp - ? nameof(LanguageNames.CSharp) - : nameof(LanguageNames.VisualBasic); + var language = languageNames[i]; var finalExpression = generator.MemberAccessExpression(baseLanguageNameExpression, language); arguments[i] = finalExpression; From 175bba9b2af341c509f0969cb3d5032b10a6f711 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Wed, 29 Sep 2021 13:23:32 -0700 Subject: [PATCH 20/27] More fixes that were wrong changes before. Create localized strings using the new hotness --- .../Fixers/SourceGeneratorAttributeAnalyzerFix.cs | 10 +++++++--- .../MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs | 10 +++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs index 8c28e6dbbf..aea70abad5 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. +using System; using System.Collections.Immutable; using System.Composition; using System.Globalization; @@ -88,9 +89,12 @@ private static async Task FixDocumentAsync(Document document, SyntaxNo var arguments = new SyntaxNode[languageNames.Length]; for (var i = 0; i < languageNames.Length; i++) { - RoslynDebug.Assert(languageNames[i] == LanguageNames.CSharp || languageNames[i] == LanguageNames.VisualBasic); - - var language = languageNames[i]; + var language = languageNames[i] switch + { + LanguageNames.CSharp => nameof(LanguageNames.CSharp), + LanguageNames.VisualBasic => nameof(LanguageNames.VisualBasic), + _ => throw new InvalidOperationException() + }; var finalExpression = generator.MemberAccessExpression(baseLanguageNameExpression, language); arguments[i] = finalExpression; diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs index 556e3a2e2a..07ac5acf91 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs @@ -11,17 +11,13 @@ namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers [DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)] public sealed class SourceGeneratorAttributeAnalyzer : DiagnosticAnalyzer { - private static readonly LocalizableString s_localizableTitle = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.MissingSourceGeneratorAttributeTitle), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources)); - private static readonly LocalizableString s_localizableMessage = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.MissingSourceGeneratorAttributeTitle), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources)); - private static readonly LocalizableString s_localizableDescription = new LocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.MissingSourceGeneratorAttributeDescription), CodeAnalysisDiagnosticsResources.ResourceManager, typeof(CodeAnalysisDiagnosticsResources)); - public static readonly DiagnosticDescriptor DiagnosticRule = new( DiagnosticIds.MissingSourceGeneratorAttributeId, - s_localizableTitle, - s_localizableMessage, + CodeAnalysisDiagnosticsResources.CreateLocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.MissingSourceGeneratorAttributeTitle)), + CodeAnalysisDiagnosticsResources.CreateLocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.MissingSourceGeneratorAttributeTitle)), DiagnosticCategory.MicrosoftCodeAnalysisCorrectness, DiagnosticSeverity.Warning, - description: s_localizableDescription, + description: CodeAnalysisDiagnosticsResources.CreateLocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.MissingSourceGeneratorAttributeDescription)), isEnabledByDefault: true); public override ImmutableArray SupportedDiagnostics => ImmutableArray.Create(DiagnosticRule); From bdf1cf607aa8cb34e14b56c7dc367358bc9dcfda Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Wed, 29 Sep 2021 13:39:13 -0700 Subject: [PATCH 21/27] Don't pass an IFormatProvider to string.Format --- .../Fixers/SourceGeneratorAttributeAnalyzerFix.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs index aea70abad5..6b30174920 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs @@ -35,15 +35,15 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) foreach (var diagnostic in context.Diagnostics) { AddFix( - string.Format(CultureInfo.CurrentUICulture, CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_1, LanguageNames.CSharp), + string.Format(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_1, LanguageNames.CSharp), context, document, node, diagnostic, LanguageNames.CSharp); AddFix( - string.Format(CultureInfo.CurrentUICulture, CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_1, LanguageNames.VisualBasic), + string.Format(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_1, LanguageNames.VisualBasic), context, document, node, diagnostic, LanguageNames.VisualBasic); AddFix( - string.Format(CultureInfo.CurrentUICulture, CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_2, LanguageNames.CSharp, LanguageNames.VisualBasic), + string.Format(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_2, LanguageNames.CSharp, LanguageNames.VisualBasic), context, document, node, diagnostic, LanguageNames.CSharp, LanguageNames.VisualBasic); } } From 7d63d312ec84bad3c1b53b18be4894f75d1198c5 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Wed, 19 Jan 2022 12:58:07 -0800 Subject: [PATCH 22/27] Apply suggestions from code review Co-authored-by: Youssef Victor --- .../Fixers/SourceGeneratorAttributeAnalyzerFix.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs index 6b30174920..58963dc91c 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs @@ -71,7 +71,7 @@ private static async Task FixDocumentAsync(Document document, SyntaxNo { // CSharp is the only language, which is the default paramterless // constructor for the Generator attribute - generatorAttribute = generator.Attribute(WellKnownTypeNames.MicrosoftCodeAnalysisGeneratorAttribute); + generatorAttribute = generator.Attribute(WellKnownTypeNames.MicrosoftCodeAnalysisGeneratorAttribute).WithAddImportsAnnotation(); } else { @@ -100,7 +100,7 @@ private static async Task FixDocumentAsync(Document document, SyntaxNo arguments[i] = finalExpression; } - generatorAttribute = generator.Attribute(WellKnownTypeNames.MicrosoftCodeAnalysisGeneratorAttribute, arguments); + generatorAttribute = generator.Attribute(WellKnownTypeNames.MicrosoftCodeAnalysisGeneratorAttribute, arguments).WithAddImportsAnnotation(); } editor.ReplaceNode(node, generator.AddAttributes(node, generatorAttribute)); From f9c3aff8be16a1bcec1fe01650f8973acd3621c0 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Wed, 19 Jan 2022 13:55:47 -0800 Subject: [PATCH 23/27] PR feedback --- .../CodeAnalysisDiagnosticsResources.resx | 13 ++++++----- .../SourceGeneratorAttributeAnalyzerFix.cs | 1 - .../CodeAnalysisDiagnosticsResources.cs.xlf | 22 +++++++++---------- .../CodeAnalysisDiagnosticsResources.de.xlf | 22 +++++++++---------- .../CodeAnalysisDiagnosticsResources.es.xlf | 22 +++++++++---------- .../CodeAnalysisDiagnosticsResources.fr.xlf | 22 +++++++++---------- .../CodeAnalysisDiagnosticsResources.it.xlf | 22 +++++++++---------- .../CodeAnalysisDiagnosticsResources.ja.xlf | 22 +++++++++---------- .../CodeAnalysisDiagnosticsResources.ko.xlf | 22 +++++++++---------- .../CodeAnalysisDiagnosticsResources.pl.xlf | 22 +++++++++---------- ...CodeAnalysisDiagnosticsResources.pt-BR.xlf | 22 +++++++++---------- .../CodeAnalysisDiagnosticsResources.ru.xlf | 22 +++++++++---------- .../CodeAnalysisDiagnosticsResources.tr.xlf | 22 +++++++++---------- ...deAnalysisDiagnosticsResources.zh-Hans.xlf | 22 +++++++++---------- ...deAnalysisDiagnosticsResources.zh-Hant.xlf | 22 +++++++++---------- 15 files changed, 151 insertions(+), 149 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx b/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx index e249501372..67daea5f0c 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx @@ -530,20 +530,23 @@ Use 'IsKind' instead of 'Kind' - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + {Locked="ISourceGenerator"}{Locked="Generator"} Missing 'Generator' attribute + {Locked="Generator"} Missing 'Generator' Attribute + {Locked="Generator"} - Apply Generator attribute for '{0}'. - "Generator" is a named type and should not be changed + Apply 'Generator' attribute for '{0}'. + {Locked="Generator"} - Apply Generator attribute for both '{0}' and '{1}'. - "Generator" is a type name and should not be changed + Apply 'Generator' attribute for both '{0}' and '{1}'. + {Locked="Generator"} \ No newline at end of file diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs index 6b30174920..df6890a845 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Immutable; using System.Composition; -using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf index 511a8d90dc..f4931a5a1f 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.cs.xlf @@ -8,14 +8,14 @@ - Apply Generator attribute for '{0}'. - Apply Generator attribute for '{0}'. - "Generator" is a named type and should not be changed + Apply 'Generator' attribute for '{0}'. + Apply 'Generator' attribute for '{0}'. + {Locked="Generator"} - Apply Generator attribute for both '{0}' and '{1}'. - Apply Generator attribute for both '{0}' and '{1}'. - "Generator" is a type name and should not be changed + Apply 'Generator' attribute for both '{0}' and '{1}'. + Apply 'Generator' attribute for both '{0}' and '{1}'. + {Locked="Generator"} Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) @@ -243,19 +243,19 @@ - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + {Locked="ISourceGenerator"}{Locked="Generator"} Missing 'Generator' attribute Missing 'Generator' attribute - + {Locked="Generator"} Missing 'Generator' Attribute Missing 'Generator' Attribute - + {Locked="Generator"} Specify at least one SymbolKind of interest when registering a symbol analyzer action diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf index 022625ac5b..d8f95e67e6 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.de.xlf @@ -8,14 +8,14 @@ - Apply Generator attribute for '{0}'. - Apply Generator attribute for '{0}'. - "Generator" is a named type and should not be changed + Apply 'Generator' attribute for '{0}'. + Apply 'Generator' attribute for '{0}'. + {Locked="Generator"} - Apply Generator attribute for both '{0}' and '{1}'. - Apply Generator attribute for both '{0}' and '{1}'. - "Generator" is a type name and should not be changed + Apply 'Generator' attribute for both '{0}' and '{1}'. + Apply 'Generator' attribute for both '{0}' and '{1}'. + {Locked="Generator"} Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) @@ -243,19 +243,19 @@ - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + {Locked="ISourceGenerator"}{Locked="Generator"} Missing 'Generator' attribute Missing 'Generator' attribute - + {Locked="Generator"} Missing 'Generator' Attribute Missing 'Generator' Attribute - + {Locked="Generator"} Specify at least one SymbolKind of interest when registering a symbol analyzer action diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf index 67390f8cc5..4d23eca8dd 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.es.xlf @@ -8,14 +8,14 @@ - Apply Generator attribute for '{0}'. - Apply Generator attribute for '{0}'. - "Generator" is a named type and should not be changed + Apply 'Generator' attribute for '{0}'. + Apply 'Generator' attribute for '{0}'. + {Locked="Generator"} - Apply Generator attribute for both '{0}' and '{1}'. - Apply Generator attribute for both '{0}' and '{1}'. - "Generator" is a type name and should not be changed + Apply 'Generator' attribute for both '{0}' and '{1}'. + Apply 'Generator' attribute for both '{0}' and '{1}'. + {Locked="Generator"} Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) @@ -243,19 +243,19 @@ - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + {Locked="ISourceGenerator"}{Locked="Generator"} Missing 'Generator' attribute Missing 'Generator' attribute - + {Locked="Generator"} Missing 'Generator' Attribute Missing 'Generator' Attribute - + {Locked="Generator"} Specify at least one SymbolKind of interest when registering a symbol analyzer action diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf index 6bfc84a14b..710be50b38 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.fr.xlf @@ -8,14 +8,14 @@ - Apply Generator attribute for '{0}'. - Apply Generator attribute for '{0}'. - "Generator" is a named type and should not be changed + Apply 'Generator' attribute for '{0}'. + Apply 'Generator' attribute for '{0}'. + {Locked="Generator"} - Apply Generator attribute for both '{0}' and '{1}'. - Apply Generator attribute for both '{0}' and '{1}'. - "Generator" is a type name and should not be changed + Apply 'Generator' attribute for both '{0}' and '{1}'. + Apply 'Generator' attribute for both '{0}' and '{1}'. + {Locked="Generator"} Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) @@ -243,19 +243,19 @@ - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + {Locked="ISourceGenerator"}{Locked="Generator"} Missing 'Generator' attribute Missing 'Generator' attribute - + {Locked="Generator"} Missing 'Generator' Attribute Missing 'Generator' Attribute - + {Locked="Generator"} Specify at least one SymbolKind of interest when registering a symbol analyzer action diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf index 449f8a5373..6afbc8303a 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.it.xlf @@ -8,14 +8,14 @@ - Apply Generator attribute for '{0}'. - Apply Generator attribute for '{0}'. - "Generator" is a named type and should not be changed + Apply 'Generator' attribute for '{0}'. + Apply 'Generator' attribute for '{0}'. + {Locked="Generator"} - Apply Generator attribute for both '{0}' and '{1}'. - Apply Generator attribute for both '{0}' and '{1}'. - "Generator" is a type name and should not be changed + Apply 'Generator' attribute for both '{0}' and '{1}'. + Apply 'Generator' attribute for both '{0}' and '{1}'. + {Locked="Generator"} Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) @@ -243,19 +243,19 @@ - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + {Locked="ISourceGenerator"}{Locked="Generator"} Missing 'Generator' attribute Missing 'Generator' attribute - + {Locked="Generator"} Missing 'Generator' Attribute Missing 'Generator' Attribute - + {Locked="Generator"} Specify at least one SymbolKind of interest when registering a symbol analyzer action diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf index 0617c1ad4d..db52102e49 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ja.xlf @@ -8,14 +8,14 @@ - Apply Generator attribute for '{0}'. - Apply Generator attribute for '{0}'. - "Generator" is a named type and should not be changed + Apply 'Generator' attribute for '{0}'. + Apply 'Generator' attribute for '{0}'. + {Locked="Generator"} - Apply Generator attribute for both '{0}' and '{1}'. - Apply Generator attribute for both '{0}' and '{1}'. - "Generator" is a type name and should not be changed + Apply 'Generator' attribute for both '{0}' and '{1}'. + Apply 'Generator' attribute for both '{0}' and '{1}'. + {Locked="Generator"} Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) @@ -243,19 +243,19 @@ - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + {Locked="ISourceGenerator"}{Locked="Generator"} Missing 'Generator' attribute Missing 'Generator' attribute - + {Locked="Generator"} Missing 'Generator' Attribute Missing 'Generator' Attribute - + {Locked="Generator"} Specify at least one SymbolKind of interest when registering a symbol analyzer action diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf index f502630d67..eda45d6273 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ko.xlf @@ -8,14 +8,14 @@ - Apply Generator attribute for '{0}'. - Apply Generator attribute for '{0}'. - "Generator" is a named type and should not be changed + Apply 'Generator' attribute for '{0}'. + Apply 'Generator' attribute for '{0}'. + {Locked="Generator"} - Apply Generator attribute for both '{0}' and '{1}'. - Apply Generator attribute for both '{0}' and '{1}'. - "Generator" is a type name and should not be changed + Apply 'Generator' attribute for both '{0}' and '{1}'. + Apply 'Generator' attribute for both '{0}' and '{1}'. + {Locked="Generator"} Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) @@ -243,19 +243,19 @@ - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + {Locked="ISourceGenerator"}{Locked="Generator"} Missing 'Generator' attribute Missing 'Generator' attribute - + {Locked="Generator"} Missing 'Generator' Attribute Missing 'Generator' Attribute - + {Locked="Generator"} Specify at least one SymbolKind of interest when registering a symbol analyzer action diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf index 6c052c95f5..01ea69d832 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pl.xlf @@ -8,14 +8,14 @@ - Apply Generator attribute for '{0}'. - Apply Generator attribute for '{0}'. - "Generator" is a named type and should not be changed + Apply 'Generator' attribute for '{0}'. + Apply 'Generator' attribute for '{0}'. + {Locked="Generator"} - Apply Generator attribute for both '{0}' and '{1}'. - Apply Generator attribute for both '{0}' and '{1}'. - "Generator" is a type name and should not be changed + Apply 'Generator' attribute for both '{0}' and '{1}'. + Apply 'Generator' attribute for both '{0}' and '{1}'. + {Locked="Generator"} Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) @@ -243,19 +243,19 @@ - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + {Locked="ISourceGenerator"}{Locked="Generator"} Missing 'Generator' attribute Missing 'Generator' attribute - + {Locked="Generator"} Missing 'Generator' Attribute Missing 'Generator' Attribute - + {Locked="Generator"} Specify at least one SymbolKind of interest when registering a symbol analyzer action diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf index 47254cb7f6..e459649e72 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.pt-BR.xlf @@ -8,14 +8,14 @@ - Apply Generator attribute for '{0}'. - Apply Generator attribute for '{0}'. - "Generator" is a named type and should not be changed + Apply 'Generator' attribute for '{0}'. + Apply 'Generator' attribute for '{0}'. + {Locked="Generator"} - Apply Generator attribute for both '{0}' and '{1}'. - Apply Generator attribute for both '{0}' and '{1}'. - "Generator" is a type name and should not be changed + Apply 'Generator' attribute for both '{0}' and '{1}'. + Apply 'Generator' attribute for both '{0}' and '{1}'. + {Locked="Generator"} Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) @@ -243,19 +243,19 @@ - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + {Locked="ISourceGenerator"}{Locked="Generator"} Missing 'Generator' attribute Missing 'Generator' attribute - + {Locked="Generator"} Missing 'Generator' Attribute Missing 'Generator' Attribute - + {Locked="Generator"} Specify at least one SymbolKind of interest when registering a symbol analyzer action diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf index 1215ab6085..41590c7d3c 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.ru.xlf @@ -8,14 +8,14 @@ - Apply Generator attribute for '{0}'. - Apply Generator attribute for '{0}'. - "Generator" is a named type and should not be changed + Apply 'Generator' attribute for '{0}'. + Apply 'Generator' attribute for '{0}'. + {Locked="Generator"} - Apply Generator attribute for both '{0}' and '{1}'. - Apply Generator attribute for both '{0}' and '{1}'. - "Generator" is a type name and should not be changed + Apply 'Generator' attribute for both '{0}' and '{1}'. + Apply 'Generator' attribute for both '{0}' and '{1}'. + {Locked="Generator"} Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) @@ -243,19 +243,19 @@ - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + {Locked="ISourceGenerator"}{Locked="Generator"} Missing 'Generator' attribute Missing 'Generator' attribute - + {Locked="Generator"} Missing 'Generator' Attribute Missing 'Generator' Attribute - + {Locked="Generator"} Specify at least one SymbolKind of interest when registering a symbol analyzer action diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf index 7ea72b5dcd..525cfb91d2 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.tr.xlf @@ -8,14 +8,14 @@ - Apply Generator attribute for '{0}'. - Apply Generator attribute for '{0}'. - "Generator" is a named type and should not be changed + Apply 'Generator' attribute for '{0}'. + Apply 'Generator' attribute for '{0}'. + {Locked="Generator"} - Apply Generator attribute for both '{0}' and '{1}'. - Apply Generator attribute for both '{0}' and '{1}'. - "Generator" is a type name and should not be changed + Apply 'Generator' attribute for both '{0}' and '{1}'. + Apply 'Generator' attribute for both '{0}' and '{1}'. + {Locked="Generator"} Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) @@ -243,19 +243,19 @@ - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + {Locked="ISourceGenerator"}{Locked="Generator"} Missing 'Generator' attribute Missing 'Generator' attribute - + {Locked="Generator"} Missing 'Generator' Attribute Missing 'Generator' Attribute - + {Locked="Generator"} Specify at least one SymbolKind of interest when registering a symbol analyzer action diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf index a9fe79b3a8..358538e14c 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hans.xlf @@ -8,14 +8,14 @@ - Apply Generator attribute for '{0}'. - Apply Generator attribute for '{0}'. - "Generator" is a named type and should not be changed + Apply 'Generator' attribute for '{0}'. + Apply 'Generator' attribute for '{0}'. + {Locked="Generator"} - Apply Generator attribute for both '{0}' and '{1}'. - Apply Generator attribute for both '{0}' and '{1}'. - "Generator" is a type name and should not be changed + Apply 'Generator' attribute for both '{0}' and '{1}'. + Apply 'Generator' attribute for both '{0}' and '{1}'. + {Locked="Generator"} Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) @@ -243,19 +243,19 @@ - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + {Locked="ISourceGenerator"}{Locked="Generator"} Missing 'Generator' attribute Missing 'Generator' attribute - + {Locked="Generator"} Missing 'Generator' Attribute Missing 'Generator' Attribute - + {Locked="Generator"} Specify at least one SymbolKind of interest when registering a symbol analyzer action diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf index f493f03730..4bcbc55694 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/xlf/CodeAnalysisDiagnosticsResources.zh-Hant.xlf @@ -8,14 +8,14 @@ - Apply Generator attribute for '{0}'. - Apply Generator attribute for '{0}'. - "Generator" is a named type and should not be changed + Apply 'Generator' attribute for '{0}'. + Apply 'Generator' attribute for '{0}'. + {Locked="Generator"} - Apply Generator attribute for both '{0}' and '{1}'. - Apply Generator attribute for both '{0}' and '{1}'. - "Generator" is a type name and should not be changed + Apply 'Generator' attribute for both '{0}' and '{1}'. + Apply 'Generator' attribute for both '{0}' and '{1}'. + {Locked="Generator"} Inherit type '{0}' from DiagnosticAnalyzer or remove the DiagnosticAnalyzerAttribute(s) @@ -243,19 +243,19 @@ - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - '{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. - + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. + {Locked="ISourceGenerator"}{Locked="Generator"} Missing 'Generator' attribute Missing 'Generator' attribute - + {Locked="Generator"} Missing 'Generator' Attribute Missing 'Generator' Attribute - + {Locked="Generator"} Specify at least one SymbolKind of interest when registering a symbol analyzer action From 8bd19df396bb1f126a57775c4f0328b9bd6bab9e Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Wed, 19 Jan 2022 17:19:10 -0800 Subject: [PATCH 24/27] Support fix all and add tests --- .../SourceGeneratorAttributeAnalyzerFix.cs | 16 +- .../MissingGeneratorAttributeRuleTests.cs | 168 ++++++++++++++++-- 2 files changed, 168 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs index df6890a845..8b5d533ac4 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/Fixers/SourceGeneratorAttributeAnalyzerFix.cs @@ -17,6 +17,10 @@ namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.Fixers [Shared] public sealed class SourceGeneratorAttributeAnalyzerFix : CodeFixProvider { + public const string CSharpEquivalenceKey = "GeneratorFixCSharp"; + public const string VisualBasicEquivalenceKey = "GeneratorFixVisualBasic"; + public const string CSharpVisualBasicEquivalenceKey = "GeneratorFixCSharpVisualBasic"; + public override ImmutableArray FixableDiagnosticIds { get; } = ImmutableArray.Create( DiagnosticIds.MissingSourceGeneratorAttributeId); @@ -35,29 +39,29 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) { AddFix( string.Format(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_1, LanguageNames.CSharp), - context, document, node, diagnostic, LanguageNames.CSharp); + context, document, node, diagnostic, CSharpEquivalenceKey, LanguageNames.CSharp); AddFix( string.Format(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_1, LanguageNames.VisualBasic), - context, document, node, diagnostic, LanguageNames.VisualBasic); + context, document, node, diagnostic, VisualBasicEquivalenceKey, LanguageNames.VisualBasic); AddFix( string.Format(CodeAnalysisDiagnosticsResources.AddGeneratorAttribute_2, LanguageNames.CSharp, LanguageNames.VisualBasic), - context, document, node, diagnostic, LanguageNames.CSharp, LanguageNames.VisualBasic); + context, document, node, diagnostic, CSharpVisualBasicEquivalenceKey, LanguageNames.CSharp, LanguageNames.VisualBasic); } } - private static void AddFix(string title, CodeFixContext context, Document document, SyntaxNode node, Diagnostic diagnostic, params string[] languageNames) + private static void AddFix(string title, CodeFixContext context, Document document, SyntaxNode node, Diagnostic diagnostic, string equivalenceKey, params string[] languageNames) { var codeAction = CodeAction.Create( title, (cancellationToken) => FixDocumentAsync(document, node, languageNames, cancellationToken), - equivalenceKey: nameof(SourceGeneratorAttributeAnalyzerFix)); + equivalenceKey: equivalenceKey); context.RegisterCodeFix(codeAction, diagnostic); } - public override FixAllProvider? GetFixAllProvider() => null; + public override FixAllProvider? GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; private static async Task FixDocumentAsync(Document document, SyntaxNode node, string[] languageNames, CancellationToken cancellationToken) { diff --git a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs index e1e78c9a11..74761d4353 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/UnitTests/MetaAnalyzers/MissingGeneratorAttributeRuleTests.cs @@ -1,7 +1,9 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. +using System; using System.Collections.Immutable; using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.Fixers; using Microsoft.CodeAnalysis.Testing; using Xunit; using VerifyCS = Test.Utilities.CSharpCodeFixVerifier< @@ -20,10 +22,10 @@ public class MissingGeneratorAttributeRuleTests ReferenceAssemblies.Default.AddPackages(ImmutableArray.Create(new PackageIdentity("Microsoft.CodeAnalysis", "3.10.0"))); [Theory] - [InlineData("[Generator]", 0)] - [InlineData("[Generator(LanguageNames.VisualBasic)]", 1)] - [InlineData("[Generator(LanguageNames.CSharp, LanguageNames.VisualBasic)]", 2)] - public async Task TestSimpleClass_CSharp(string attr, int index) + [InlineData("[Generator]", 0, SourceGeneratorAttributeAnalyzerFix.CSharpEquivalenceKey)] + [InlineData("[Generator(LanguageNames.VisualBasic)]", 1, SourceGeneratorAttributeAnalyzerFix.VisualBasicEquivalenceKey)] + [InlineData("[Generator(LanguageNames.CSharp, LanguageNames.VisualBasic)]", 2, SourceGeneratorAttributeAnalyzerFix.CSharpVisualBasicEquivalenceKey)] + public async Task TestSimpleClass_CSharp(string attr, int index, string equivalenceKey) { var code = @" using Microsoft.CodeAnalysis; @@ -48,7 +50,8 @@ public void Execute(GeneratorExecutionContext context) {{}} ReferenceAssemblies = ReferenceAssemblies, TestCode = code, FixedCode = fixedCode, - CodeActionIndex = index + CodeActionIndex = index, + CodeActionEquivalenceKey = equivalenceKey }.RunAsync(); } @@ -84,10 +87,10 @@ public void Execute(Microsoft.CodeAnalysis.GeneratorExecutionContext context) {} } [Theory] - [InlineData("", 0)] - [InlineData("", 1)] - [InlineData("", 2)] - public async Task TestSimpleClass_VisualBasic(string attr, int index) + [InlineData("", 0, SourceGeneratorAttributeAnalyzerFix.CSharpEquivalenceKey)] + [InlineData("", 1, SourceGeneratorAttributeAnalyzerFix.VisualBasicEquivalenceKey)] + [InlineData("", 2, SourceGeneratorAttributeAnalyzerFix.CSharpVisualBasicEquivalenceKey)] + public async Task TestSimpleClass_VisualBasic(string attr, int index, string equivalenceKey) { var code = @" Imports Microsoft.CodeAnalysis @@ -125,7 +128,8 @@ End Sub ReferenceAssemblies = ReferenceAssemblies, TestCode = code, FixedCode = fixedCode, - CodeActionIndex = index + CodeActionIndex = index, + CodeActionEquivalenceKey = equivalenceKey }.RunAsync(); } @@ -314,5 +318,149 @@ End Sub TestCode = code, }.RunAsync(); } + + [Theory] + [InlineData("[Generator]", 0, SourceGeneratorAttributeAnalyzerFix.CSharpEquivalenceKey)] + [InlineData("[Generator(LanguageNames.VisualBasic)]", 1, SourceGeneratorAttributeAnalyzerFix.VisualBasicEquivalenceKey)] + [InlineData("[Generator(LanguageNames.CSharp, LanguageNames.VisualBasic)]", 2, SourceGeneratorAttributeAnalyzerFix.CSharpVisualBasicEquivalenceKey)] + public async Task TestFixAllCSharp(string attr, int index, string equivalenceKey) + { + var code1 = @" +using Microsoft.CodeAnalysis; + +public class [|CustomGenerator1|] : ISourceGenerator +{ + public void Initialize(GeneratorInitializationContext context) {} + public void Execute(GeneratorExecutionContext context) {} +}"; + + var code2 = @" +using Microsoft.CodeAnalysis; + +public class [|CustomGenerator2|] : ISourceGenerator +{ + public void Initialize(GeneratorInitializationContext context) {} + public void Execute(GeneratorExecutionContext context) {} +}"; + + var fixedCode1 = @$" +using Microsoft.CodeAnalysis; + +{attr} +public class CustomGenerator1 : ISourceGenerator +{{ + public void Initialize(GeneratorInitializationContext context) {{}} + public void Execute(GeneratorExecutionContext context) {{}} +}}"; + + var fixedCode2 = @$" +using Microsoft.CodeAnalysis; + +{attr} +public class CustomGenerator2 : ISourceGenerator +{{ + public void Initialize(GeneratorInitializationContext context) {{}} + public void Execute(GeneratorExecutionContext context) {{}} +}}"; + + await new VerifyCS.Test + { + ReferenceAssemblies = ReferenceAssemblies, + TestState = + { + Sources = {code1, code2 } + }, + FixedState = + { + Sources = {fixedCode1, fixedCode2} + }, + CodeActionEquivalenceKey = equivalenceKey, + CodeActionIndex = index + }.RunAsync(); + } + + [Theory] + [InlineData("", 0, SourceGeneratorAttributeAnalyzerFix.CSharpEquivalenceKey)] + [InlineData("", 1, SourceGeneratorAttributeAnalyzerFix.VisualBasicEquivalenceKey)] + [InlineData("", 2, SourceGeneratorAttributeAnalyzerFix.CSharpVisualBasicEquivalenceKey)] + public async Task TestFixAllVisualBasic(string attr, int index, string equivalenceKey) + { + var code1 = @" +Imports Microsoft.CodeAnalysis + +Public Class [|CustomGenerator1|] + Implements ISourceGenerator + + Public Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize + + End Sub + + Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute + + End Sub +End Class"; + + var code2 = @" +Imports Microsoft.CodeAnalysis + +Public Class [|CustomGenerator2|] + Implements ISourceGenerator + + Public Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize + + End Sub + + Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute + + End Sub +End Class"; + + var fixedCode1 = @$" +Imports Microsoft.CodeAnalysis + +{attr} +Public Class CustomGenerator1 + Implements ISourceGenerator + + Public Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize + + End Sub + + Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute + + End Sub +End Class"; + + var fixedCode2 = @$" +Imports Microsoft.CodeAnalysis + +{attr} +Public Class CustomGenerator2 + Implements ISourceGenerator + + Public Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize + + End Sub + + Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute + + End Sub +End Class"; + + await new VerifyVB.Test + { + ReferenceAssemblies = ReferenceAssemblies, + TestState = + { + Sources = {code1, code2} + }, + FixedState = + { + Sources = {fixedCode1, fixedCode2} + }, + CodeActionIndex = index, + CodeActionEquivalenceKey = equivalenceKey + }.RunAsync(); + } } } \ No newline at end of file From 3a244e87a893b1850db339418a0c8b99d599deb0 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Wed, 19 Jan 2022 17:23:15 -0800 Subject: [PATCH 25/27] using static Microsoft.CodeAnalysis.Analyzers.CodeAnalysisDiagnosticsResources; --- .../Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs index 07ac5acf91..17d3f8b1c5 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs +++ b/src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/SourceGeneratorAttributeAnalyzer.cs @@ -5,6 +5,7 @@ using Analyzer.Utilities; using Analyzer.Utilities.Extensions; using Microsoft.CodeAnalysis.Diagnostics; +using static Microsoft.CodeAnalysis.Analyzers.CodeAnalysisDiagnosticsResources; namespace Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers { @@ -13,11 +14,11 @@ public sealed class SourceGeneratorAttributeAnalyzer : DiagnosticAnalyzer { public static readonly DiagnosticDescriptor DiagnosticRule = new( DiagnosticIds.MissingSourceGeneratorAttributeId, - CodeAnalysisDiagnosticsResources.CreateLocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.MissingSourceGeneratorAttributeTitle)), - CodeAnalysisDiagnosticsResources.CreateLocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.MissingSourceGeneratorAttributeTitle)), + CreateLocalizableResourceString(nameof(MissingSourceGeneratorAttributeTitle)), + CreateLocalizableResourceString(nameof(MissingSourceGeneratorAttributeTitle)), DiagnosticCategory.MicrosoftCodeAnalysisCorrectness, DiagnosticSeverity.Warning, - description: CodeAnalysisDiagnosticsResources.CreateLocalizableResourceString(nameof(CodeAnalysisDiagnosticsResources.MissingSourceGeneratorAttributeDescription)), + description: CreateLocalizableResourceString(nameof(MissingSourceGeneratorAttributeDescription)), isEnabledByDefault: true); public override ImmutableArray SupportedDiagnostics => ImmutableArray.Create(DiagnosticRule); From 79d0ef2b5120f8699005b6b48600803ca6a82d69 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Wed, 19 Jan 2022 17:33:45 -0800 Subject: [PATCH 26/27] Update md --- .../Microsoft.CodeAnalysis.Analyzers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.md b/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.md index e0957e5a85..6515d3e0d8 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.md +++ b/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.md @@ -426,7 +426,7 @@ Prefer 'syntax.IsKind(kind)' to 'syntax.Kind() == kind' when checking syntax kin ## RS1035: Missing 'Generator' Attribute -'{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute. +A type implements 'ISourceGenerator' but does not have the 'Generator' attribute. |Item|Value| |-|-| From 469c7491ecfac8c67d4be54b4d15a5006ffd71c1 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Wed, 19 Jan 2022 19:50:00 -0800 Subject: [PATCH 27/27] Run pack --- .../Microsoft.CodeAnalysis.Analyzers.sarif | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.sarif b/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.sarif index d5bfd8d79d..a3fd5651b3 100644 --- a/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.sarif +++ b/src/Microsoft.CodeAnalysis.Analyzers/Microsoft.CodeAnalysis.Analyzers.sarif @@ -445,7 +445,7 @@ "RS1035": { "id": "RS1035", "shortDescription": "Missing 'Generator' Attribute", - "fullDescription": "'{0}' implements 'ISourceGenerator' but does not have the 'Generator' attribute.", + "fullDescription": "A type implements 'ISourceGenerator' but does not have the 'Generator' attribute.", "defaultLevel": "warning", "properties": { "category": "MicrosoftCodeAnalysisCorrectness",