From 4c8f68d67e7a78e8d6a8a96bb170caf52f43810f Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Mon, 4 Sep 2023 15:53:40 +0100 Subject: [PATCH] validations: Limit ref. validation to only LocalOrigin(s) (#1379) * validations: Limit ref. validation to only LocalOrigin(s) * validations: add test for disabled origins --- .../validations/unreferenced_origin.go | 7 ++++++ .../validations/unreferenced_origin_test.go | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/internal/decoder/validations/unreferenced_origin.go b/internal/decoder/validations/unreferenced_origin.go index ad5f550d..aa19bfdf 100644 --- a/internal/decoder/validations/unreferenced_origin.go +++ b/internal/decoder/validations/unreferenced_origin.go @@ -27,6 +27,13 @@ func UnreferencedOrigins(ctx context.Context, pathCtx *decoder.PathContext) lang continue } + _, ok = origin.(reference.LocalOrigin) + if !ok { + // we avoid reporting on origins outside of the current module + // for now, to reduce complexity and reduce performance impact + continue + } + // we only initially validate variables // resources and data sources can have unknown schema // and will be researched at a later point diff --git a/internal/decoder/validations/unreferenced_origin_test.go b/internal/decoder/validations/unreferenced_origin_test.go index f36b6122..2f0457a9 100644 --- a/internal/decoder/validations/unreferenced_origin_test.go +++ b/internal/decoder/validations/unreferenced_origin_test.go @@ -50,6 +50,28 @@ func TestUnreferencedOrigins(t *testing.T) { }, }, }, + { + name: "unsupported path origins (module input)", + origins: reference.Origins{ + reference.PathOrigin{ + Range: hcl.Range{ + Filename: "test.tf", + Start: hcl.Pos{}, + End: hcl.Pos{}, + }, + TargetAddr: lang.Address{ + lang.RootStep{Name: "var"}, + lang.AttrStep{Name: "foo"}, + }, + TargetPath: lang.Path{ + Path: "./submodule", + LanguageID: "terraform", + }, + Constraints: reference.OriginConstraints{}, + }, + }, + want: lang.DiagnosticsMap{}, + }, { name: "many undeclared variables", origins: reference.Origins{