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
14 changes: 14 additions & 0 deletions cmd/inspect_parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (cli *CLI) inspectParallel(opts Options) int {
if err := json.Unmarshal(stdout, &workerIssues); err != nil {
panic(fmt.Errorf("failed to parse issues in %s; %s; stdout=%s; stderr=%s", worker.dir, err, stdout, stderr))
}
fillNoRangeIssueFilenames(worker.dir, workerIssues)
issues = append(issues, workerIssues...)

if len(stderr) > 0 {
Expand Down Expand Up @@ -103,6 +104,19 @@ func (cli *CLI) inspectParallel(opts Options) int {
return ExitCodeOK
}

func fillNoRangeIssueFilenames(dir string, issues tflint.Issues) {
for _, issue := range issues {
if issue.Range.Filename == "" {
issue.Range.Filename = dir
}
for idx := range issue.Callers {
if issue.Callers[idx].Filename == "" {
issue.Callers[idx].Filename = dir
}
}
}
}

// Spawn workers to run in parallel for each directory.
// A worker is a process that runs itself as a child process.
// The number of parallelism is controlled by --max-workers flag. The default is the number of CPUs.
Expand Down
43 changes: 43 additions & 0 deletions cmd/inspect_parallel_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package cmd

import (
"testing"

"github.com/google/go-cmp/cmp"
hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint/tflint"
)

func TestFillNoRangeIssueFilenames(t *testing.T) {
issues := tflint.Issues{
{
Range: hcl.Range{},
Callers: []hcl.Range{
{},
{Filename: "main.tf"},
},
},
{
Range: hcl.Range{Filename: "subdir/main.tf"},
},
}

fillNoRangeIssueFilenames("subdir", issues)

expected := tflint.Issues{
{
Range: hcl.Range{Filename: "subdir"},
Callers: []hcl.Range{
{Filename: "subdir"},
{Filename: "main.tf"},
},
},
{
Range: hcl.Range{Filename: "subdir/main.tf"},
},
}

if diff := cmp.Diff(expected, issues); diff != "" {
t.Fatal(diff)
}
}
Loading