Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
; Unshipped analyzer release
; https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md

### New Rules

Rule ID | Category | Severity | Notes
--------|----------|----------|-------
AWSLambda0104 | AWSLambdaCSharpGenerator | Error | Missing reference to a required dependency
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Reflection.Metadata;
using System.Runtime.InteropServices.ComTypes;
using Microsoft.CodeAnalysis;

namespace Amazon.Lambda.Annotations.SourceGenerator.Diagnostics
Expand All @@ -10,7 +8,7 @@ public static class DiagnosticDescriptors
/// Generic errors
public static readonly DiagnosticDescriptor UnhandledException = new DiagnosticDescriptor(id: "AWSLambda0001",
title: "Unhandled exception",
messageFormat: $"This is a bug. Please run the build with detailed verbosity (dotnet build --verbosity detailed) and file a bug at https://github.com/aws/aws-lambda-dotnet with the build output and stack trace {{0}}.",
messageFormat: "This is a bug. Please run the build with detailed verbosity (dotnet build --verbosity detailed) and file a bug at https://github.com/aws/aws-lambda-dotnet with the build output and stack trace {0}.",
category: "AWSLambda",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
Expand Down Expand Up @@ -38,5 +36,13 @@ public static class DiagnosticDescriptors
category: "AWSLambdaCSharpGenerator",
DiagnosticSeverity.Info,
isEnabledByDefault: true);

public static readonly DiagnosticDescriptor MissingDependencies = new DiagnosticDescriptor(id: "AWSLambda0104",
title: "Missing reference to a required dependency",
messageFormat: "Your project has a missing required package dependency. Please add a reference to the following package: {0}",
category: "AWSLambdaCSharpGenerator",
DiagnosticSeverity.Error,
isEnabledByDefault: true);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ public void Execute(GeneratorExecutionContext context)
foreach (var lambdaMethod in receiver.LambdaMethods)
{
var lambdaMethodModel = semanticModelProvider.GetMethodSemanticModel(lambdaMethod);

// Check for necessary references
if (lambdaMethodModel.HasAttribute(context, TypeFullNames.RestApiAttribute)
|| lambdaMethodModel.HasAttribute(context, TypeFullNames.HttpApiAttribute))
{
// Check for arbitrary type from "Amazon.Lambda.APIGatewayEvents"
if (context.Compilation.ReferencedAssemblyNames.FirstOrDefault(x => x.Name == "Amazon.Lambda.APIGatewayEvents") == null)
{
diagnosticReporter.Report(Diagnostic.Create(DiagnosticDescriptors.MissingDependencies,
lambdaMethod.GetLocation(),
"Amazon.Lambda.APIGatewayEvents"));
}
}

var model = LambdaFunctionModelBuilder.Build(lambdaMethodModel, configureMethodModel, context);

// If there are more than one event, report them as errors
Expand Down