From 672c19f9fa6145b318aa74ea7de571f1b654a7b7 Mon Sep 17 00:00:00 2001 From: Lasse Gaardsholt Date: Fri, 3 Jan 2025 13:43:51 +0100 Subject: [PATCH 1/2] added check to test if list is empty Signed-off-by: Lasse Gaardsholt --- README.md | 11 +++-------- rules/terraform_lists_trailing_comma.go | 3 ++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ea5da53..d4b43af 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,16 @@ -# TFLint Ruleset Template -[![Build Status](https://github.com/terraform-linters/tflint-ruleset-template/workflows/build/badge.svg?branch=main)](https://github.com/terraform-linters/tflint-ruleset-template/actions) - -This is a template repository for building a custom ruleset. You can create a plugin repository from "Use this template". See also [Writing Plugins](https://github.com/terraform-linters/tflint/blob/master/docs/developer-guide/plugins.md). +# TFLint Ruleset trailing-comma ## Requirements - TFLint v0.42+ -- Go v1.22 +- Go v1.22 or newer ## Installation -TODO: This template repository does not contain release binaries, so this installation will not work. Please rewrite for your repository. See the "Building the plugin" section to get this template ruleset working. - You can install the plugin with `tflint --init`. Declare a config in `.tflint.hcl` as follows: ```hcl -plugin "template" { +plugin "trailing-comma" { enabled = true version = "0.1.0" diff --git a/rules/terraform_lists_trailing_comma.go b/rules/terraform_lists_trailing_comma.go index 195e6d5..aaecae9 100644 --- a/rules/terraform_lists_trailing_comma.go +++ b/rules/terraform_lists_trailing_comma.go @@ -48,9 +48,10 @@ func (r *TerraformListsTrailingCommaRule) Check(runner tflint.Runner) error { file := files[filename] list, ok := e.(*hclsyntax.TupleConsExpr) - if !ok { + if !ok || len(list.Exprs) <= 0 { return nil } + listRange := list.Range() lastItem := list.Exprs[len(list.Exprs)-1] lastItemRange := lastItem.Range() From be4fc4f19f553fd460be1ae2e36e660a6da41c48 Mon Sep 17 00:00:00 2001 From: Lasse Gaardsholt Date: Fri, 3 Jan 2025 13:45:35 +0100 Subject: [PATCH 2/2] removed this trigger as we are not using autolabeler Signed-off-by: Lasse Gaardsholt --- .github/workflows/release-drafter.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 3bb1620..db3bc02 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -5,13 +5,6 @@ on: # branches to consider in the event; optional, defaults to all branches: - main - # pull_request event is required only for autolabeler - pull_request: - # Only following types are handled by the action, but one can default to all as well - types: [opened, reopened, synchronize] - # pull_request_target event is required for autolabeler to support PRs from forks - # pull_request_target: - # types: [opened, reopened, synchronize] permissions: # write permission is required to create a github release