Skip to content

(init templates): (go example causes an error using go tools) #33554

Open
@4k1k0

Description

@4k1k0

Describe the bug

The project contains examples of AWS CDK projects inside node_modules/aws-cdk/lib/init-templates, including an example for a Go project. This setup causes Go tools to incorrectly scan these files, leading to failures. Specifically, golangci-lint encounters a compile error and cannot generate expected warnings and errors.

aws-cdk version 2.1000.2
golangci-lint has version 1.59.0 built with go1.22.3 from 2059b18a on 2024-05-26T18:13:27Z
go version go1.22.3 darwin/arm64

There is an open discussion about this topic in Go's repository.
golang/go#42965

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

Do not include go code that can interfere with a Go project.

Current Behavior

$ golangci-lint run
WARN The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar.
WARN The linter 'tenv' is deprecated (since v1.64.0) due to: Duplicate feature another linter. Replaced by usetesting.
WARN The linter 'execinquery' is deprecated (since v1.58.0) due to: The repository of the linter has been archived by the owner.
ERRO [linters_context] execinquery: This linter is fully inactivated: it will not produce any reports.
ERRO [linters_context] exportloopref: This linter is fully inactivated: it will not produce any reports.
node_modules/aws-cdk/lib/init-templates/app/go/%name%.template.go:1: : invalid input file name "%name%.template.go" (typecheck)
package main
node_modules/aws-cdk/lib/init-templates/app/go/%name%.template.go:10:6: expected 'IDENT', found '%' (typecheck)
type %name.PascalCased%StackProps struct {
     ^
node_modules/aws-cdk/lib/init-templates/app/go/%name%.template.go:16:2: expected declaration, found 'if' (typecheck)
        if props != nil {
        ^
node_modules/aws-cdk/lib/init-templates/sample-app/go/%name%.template.go:1: : invalid input file name "%name%.template.go" (typecheck)
package main
node_modules/aws-cdk/lib/init-templates/sample-app/go/%name%.template.go:12:6: expected 'IDENT', found '%' (typecheck)
type %name.PascalCased%StackProps struct {
     ^
node_modules/aws-cdk/lib/init-templates/sample-app/go/%name%.template.go:18:2: expected declaration, found 'if' (typecheck)
        if props != nil {
        ^
node_modules/aws-cdk/lib/init-templates/sample-app/go/%name%_test.template.go:11:10: expected '(', found '%' (typecheck)
func Test%name.PascalCased%Stack(t *testing.T) {
         ^
node_modules/aws-cdk/test/commands/test-resources/stacks/s3.go:1: : # sdui/node_modules/aws-cdk/test/commands/test-resources/stacks
node_modules/aws-cdk/test/commands/test-resources/stacks/s3.go:35:27: undefined: WebsiteConfigurationProperty
node_modules/aws-cdk/test/commands/test-resources/stacks/s3.go:57:32: cannot use GoodGoStackProps{…} (value of type GoodGoStackProps) as *GoodGoStackProps value in argument to NewGoodGoStack (typecheck)
package main

Reproduction Steps

Create a new project using Go
Include a Golagci-lint config file
Install aws-cdk via npm
Execute $ golangci-lint run

Possible Solution

One solution would be to rename the directory from init-templates to _init-templates

Additional Information/Context

No response

CDK CLI Version

2.1000.2

Framework Version

No response

Node.js Version

v20.11.1

OS

MacOS Sequoia v15.3

Language

Go

Language Version

go version go1.22.3 darwin/arm64

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.effort/mediumMedium work item – several days of effortjsiiThis issue originates in jsii, or this feature must be implemented in jsii.p2package/toolsRelated to AWS CDK Tools or CLI

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions