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
7 changes: 3 additions & 4 deletions cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io"
"maps"
"os"
"path/filepath"

Expand Down Expand Up @@ -171,7 +172,7 @@ By setting TFLINT_LOG=trace, you can confirm the changes made by the autofix and
}(runner)
}
}
for i := 0; i < len(moduleRunners); i++ {
for range moduleRunners {
err = <-ch
if err != nil {
return issues, changes, fmt.Errorf("Failed to check ruleset; %w", err)
Expand Down Expand Up @@ -203,9 +204,7 @@ By setting TFLINT_LOG=trace, you can confirm the changes made by the autofix and
}

// Set module sources to CLI
for path, source := range cli.loader.Sources() {
cli.sources[path] = source
}
maps.Copy(cli.sources, cli.loader.Sources())

return issues, changes, nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (opts *Options) toConfig() *tflint.Config {
ignoreModules := map[string]bool{}
for _, module := range opts.IgnoreModules {
// For the backward compatibility, allow specifying like "source1,source2" style
for _, m := range strings.Split(module, ",") {
for m := range strings.SplitSeq(module, ",") {
ignoreModules[m] = true
}
}
Expand Down
8 changes: 4 additions & 4 deletions integrationtest/langserver/langserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
)

type jsonrpcMessage struct {
JSONRPC string `json:"jsonrpc"`
ID int `json:"id,omitempty"`
Method string `json:"method"`
Params interface{} `json:"params"`
JSONRPC string `json:"jsonrpc"`
ID int `json:"id,omitempty"`
Method string `json:"method"`
Params any `json:"params"`
}

func TestMain(m *testing.M) {
Expand Down
2 changes: 1 addition & 1 deletion langserver/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type handler struct {
diagsPaths []string
}

func (h *handler) handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
func (h *handler) handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
if req.Params != nil {
params, err := json.Marshal(&req.Params)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion langserver/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/sourcegraph/jsonrpc2"
)

func initialize(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
func initialize(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
return lsp.InitializeResult{
Capabilities: lsp.ServerCapabilities{
TextDocumentSync: &lsp.TextDocumentSyncOptionsOrKind{
Expand Down
2 changes: 1 addition & 1 deletion langserver/text_document_did_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/spf13/afero"
)

func (h *handler) textDocumentDidChange(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
func (h *handler) textDocumentDidChange(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
if req.Params == nil {
return nil, &jsonrpc2.Error{
Code: jsonrpc2.CodeInvalidRequest,
Expand Down
2 changes: 1 addition & 1 deletion langserver/text_document_did_open.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/spf13/afero"
)

func (h *handler) textDocumentDidOpen(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
func (h *handler) textDocumentDidOpen(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
if req.Params == nil {
return nil, &jsonrpc2.Error{
Code: jsonrpc2.CodeInvalidRequest,
Expand Down
2 changes: 1 addition & 1 deletion langserver/workspace_did_change_watched_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/terraform-linters/tflint/tflint"
)

func (h *handler) workspaceDidChangeWatchedFiles(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
func (h *handler) workspaceDidChangeWatchedFiles(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
if h.rootDir == "" {
return nil, fmt.Errorf("root directory is undefined")
}
Expand Down
7 changes: 3 additions & 4 deletions plugin/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package plugin
import (
"errors"
"fmt"
"maps"
"os"
"testing"

Expand Down Expand Up @@ -264,9 +265,7 @@ resource "aws_instance" "foo" {
}`,
})
files := runner.Files()
for name, file := range rootRunner.Files() {
files[name] = file
}
maps.Copy(files, rootRunner.Files())

server := NewGRPCServer(runner, rootRunner, files, SDKVersion)

Expand Down Expand Up @@ -480,7 +479,7 @@ variable "foo" {

// test util functions
hclExpr := func(expr string) hcl.Expression {
file, diags := hclsyntax.ParseConfig([]byte(fmt.Sprintf(`expr = %s`, expr)), "test.tf", hcl.InitialPos)
file, diags := hclsyntax.ParseConfig(fmt.Appendf(nil, `expr = %s`, expr), "test.tf", hcl.InitialPos)
if diags.HasErrors() {
panic(diags)
}
Expand Down
9 changes: 3 additions & 6 deletions tflint/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tflint
import (
"fmt"
"log"
"maps"
"os"
"strings"

Expand Down Expand Up @@ -484,9 +485,7 @@ func (c *Config) Sources() map[string][]byte {
bundledPluginConfigFilename: []byte(bundledPluginConfigContent),
}

for name, content := range c.sources {
ret[name] = content
}
maps.Copy(ret, c.sources)
return ret
}

Expand Down Expand Up @@ -518,9 +517,7 @@ func (c *Config) Merge(other *Config) {
c.Variables = append(c.Variables, other.Variables...)
c.Only = append(c.Only, other.Only...)

for name, ignore := range other.IgnoreModules {
c.IgnoreModules[name] = ignore
}
maps.Copy(c.IgnoreModules, other.IgnoreModules)

for name, rule := range other.Rules {
// HACK: If you enable the rule through the CLI instead of the file, its hcl.Body will be nil.
Expand Down
9 changes: 3 additions & 6 deletions tflint/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tflint
import (
"fmt"
"log"
"maps"
"path/filepath"

hcl "github.com/hashicorp/hcl/v2"
Expand Down Expand Up @@ -213,9 +214,7 @@ func (r *Runner) File(path string) *hcl.File {
// Files returns the raw *hcl.File representation of all Terraform configuration in the module directory.
func (r *Runner) Files() map[string]*hcl.File {
result := make(map[string]*hcl.File)
for name, file := range r.TFConfig.Module.Files {
result[name] = file
}
maps.Copy(result, r.TFConfig.Module.Files)
return result
}

Expand Down Expand Up @@ -284,9 +283,7 @@ func (r *Runner) ApplyChanges(changes map[string][]byte) hcl.Diagnostics {
if diags.HasErrors() {
return diags
}
for path, source := range changes {
r.changes[path] = source
}
maps.Copy(r.changes, changes)
return nil
}

Expand Down
Loading