diff --git a/src/ModularPipelines.Analyzers/ModularPipelines.Analyzers/AnalyzerReleases.Unshipped.md b/src/ModularPipelines.Analyzers/ModularPipelines.Analyzers/AnalyzerReleases.Unshipped.md index 72915de64c..c39f1c1456 100644 --- a/src/ModularPipelines.Analyzers/ModularPipelines.Analyzers/AnalyzerReleases.Unshipped.md +++ b/src/ModularPipelines.Analyzers/ModularPipelines.Analyzers/AnalyzerReleases.Unshipped.md @@ -4,7 +4,6 @@ Rule ID | Category | Severity | Notes --------|----------|----------|-------------------- AwaitThis | Usage | Error | Prohibit await this in modules StatefulModule | Design | Warning | Detects mutable instance fields in modules that could leak state between executions -MP0010 | Migration | Warning | Warns when deprecated Arguments property is used on CommandLineToolOptions MPDEP001 | Usage | Error | DependsOn type does not implement IModule MPDEP002 | Usage | Error | Circular dependency detected between modules (renamed from ConflictingDependsOnAttribute) MPDEP003 | Usage | Error | Module depends on itself diff --git a/src/ModularPipelines.Analyzers/ModularPipelines.Analyzers/ArgumentsPropertyDeprecatedAnalyzer.cs b/src/ModularPipelines.Analyzers/ModularPipelines.Analyzers/ArgumentsPropertyDeprecatedAnalyzer.cs deleted file mode 100644 index 4f5f89f029..0000000000 --- a/src/ModularPipelines.Analyzers/ModularPipelines.Analyzers/ArgumentsPropertyDeprecatedAnalyzer.cs +++ /dev/null @@ -1,107 +0,0 @@ -using System.Collections.Immutable; -using System.Diagnostics.CodeAnalysis; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Diagnostics; - -namespace ModularPipelines.Analyzers; - -/// -/// Analyzer that warns when the deprecated 'Arguments' property is used on CommandLineToolOptions. -/// The Arguments property bypasses type safety - users should use typed positional argument properties instead. -/// -[DiagnosticAnalyzer(LanguageNames.CSharp)] -[ExcludeFromCodeCoverage] -public class ArgumentsPropertyDeprecatedAnalyzer : DiagnosticAnalyzer -{ - /// - /// The diagnostic ID for this analyzer. - /// - public const string DiagnosticId = "MP0010"; - - /// - /// The fully qualified type name for CommandLineToolOptions base class. - /// - private const string CommandLineToolOptionsFullName = "ModularPipelines.Options.CommandLineToolOptions"; - - /// - /// The property name being deprecated. - /// - private const string ArgumentsPropertyName = "Arguments"; - - /// - /// The diagnostic rule for this analyzer. - /// - public static DiagnosticDescriptor Rule { get; } = DiagnosticDescriptorFactory.Create( - DiagnosticId, - nameof(Resources.ArgumentsPropertyDeprecatedAnalyzerTitle), - nameof(Resources.ArgumentsPropertyDeprecatedAnalyzerMessageFormat), - nameof(Resources.ArgumentsPropertyDeprecatedAnalyzerDescription), - category: "Migration", - severity: DiagnosticSeverity.Warning); - - /// - public override ImmutableArray SupportedDiagnostics => ImmutableArray.Create(Rule); - - /// - public override void Initialize(AnalysisContext context) - { - context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); - context.EnableConcurrentExecution(); - - // Register for object initializer expressions where Arguments might be set - context.RegisterSyntaxNodeAction(AnalyzeAssignment, SyntaxKind.SimpleAssignmentExpression); - } - - private void AnalyzeAssignment(SyntaxNodeAnalysisContext context) - { - if (context.Node is not AssignmentExpressionSyntax assignment) - { - return; - } - - // Check if the left side is an identifier named "Arguments" - if (assignment.Left is not IdentifierNameSyntax identifierName || - identifierName.Identifier.Text != ArgumentsPropertyName) - { - return; - } - - // Get the symbol for the property being assigned - var symbolInfo = context.SemanticModel.GetSymbolInfo(identifierName); - if (symbolInfo.Symbol is not IPropertySymbol propertySymbol) - { - return; - } - - // Check if the property is from a type that inherits from CommandLineToolOptions - var containingType = propertySymbol.ContainingType; - if (!InheritsFromCommandLineToolOptions(containingType)) - { - return; - } - - // Report the diagnostic - var typeName = containingType.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat); - context.ReportDiagnostic(Diagnostic.Create(Rule, assignment.GetLocation(), typeName)); - } - - /// - /// Checks if the given type inherits from CommandLineToolOptions. - /// - private static bool InheritsFromCommandLineToolOptions(INamedTypeSymbol? type) - { - while (type != null) - { - if (type.ToDisplayString() == CommandLineToolOptionsFullName) - { - return true; - } - - type = type.BaseType; - } - - return false; - } -} diff --git a/src/ModularPipelines.Analyzers/ModularPipelines.Analyzers/Resources.resx b/src/ModularPipelines.Analyzers/ModularPipelines.Analyzers/Resources.resx index 0a05c1e513..3b4bfb9244 100644 --- a/src/ModularPipelines.Analyzers/ModularPipelines.Analyzers/Resources.resx +++ b/src/ModularPipelines.Analyzers/ModularPipelines.Analyzers/Resources.resx @@ -189,15 +189,6 @@ Modules are registered as Singletons in the dependency injection container and can be executed multiple times (retries, sub-modules, parallel pipelines). Instance fields can leak state between executions. Use readonly fields for injected dependencies, or store execution state in IModuleContext. - - Arguments property is deprecated - - - The 'Arguments' property on '{0}' is deprecated. Use typed positional argument properties instead - - - The Arguments property bypasses type safety. In ModularPipelines v2, use typed positional argument properties marked with [CliArgument] instead. For example, use 'Committish = "HEAD"' on GitRevParseOptions instead of 'Arguments = ["HEAD"]'. If no typed property exists, request one be added or use GenericCommandLineToolOptions. - Invalid DependsOn type