diff --git a/CHANGELOG.md b/CHANGELOG.md index f4ec3ed988c..653c3ade601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), Note: Can be used with `megalinter/megalinter@beta` in your GitHub Action mega-linter.yml file, or with `megalinter/megalinter:beta` docker image +Linter updates: + - New reporter **GITLAB_COMMENT_REPORTER** allowing to post MegaLinter results as comments on Gitlab merge requests +- Add configuration file option for SQLFluff ([#1200](https://github.com/megalinter/megalinter/pull/1200)) - secretlint: Use .gitignore as .secretlintignore if --secretlintignore is not defined and .secretlintignore not found ([#1207](https://github.com/megalinter/megalinter/issues/1207)) -- Fix v5 doc deployment when there is a new release ([1190](https://github.com/megalinter/megalinter/issues/1190)) + +Fixes: + +- Fix v5 doc deployment when there is a new release ([#1190](https://github.com/megalinter/megalinter/issues/1190)) - Fix issue when using `VALIDATE_ALL_CODEBASE: false` on Azure Pipelines by defining auth header in CI env variable GIT_AUTHORIZATION_BEARER ([#1125](https://github.com/megalinter/megalinter/issues/1125)) +- Fix tflint initialization so it uses configuration file when defined ([#1134](https://github.com/megalinter/megalinter/issues/1134)) - Linter versions upgrades - [stylelint](https://stylelint.io) from 14.2.0 to **14.3.0** on 2022-01-23 diff --git a/megalinter/descriptors/terraform.megalinter-descriptor.yml b/megalinter/descriptors/terraform.megalinter-descriptor.yml index 52d721fe803..c4b7fa57adb 100644 --- a/megalinter/descriptors/terraform.megalinter-descriptor.yml +++ b/megalinter/descriptors/terraform.megalinter-descriptor.yml @@ -6,16 +6,14 @@ file_extensions: - ".tf" linters: # TFLINT - - linter_name: tflint + - class: TfLintLinter + linter_name: tflint name: TERRAFORM_TFLINT linter_url: https://github.com/terraform-linters/tflint linter_rules_url: https://github.com/terraform-linters/tflint/tree/master/docs/rules#rules linter_rules_configuration_url: https://github.com/terraform-linters/tflint/blob/master/docs/guides/config.md linter_rules_inline_disable_url: https://github.com/terraform-linters/tflint/blob/master/docs/guides/annotations.md config_file_name: .tflint.hcl - pre_commands: - - command: tflint --init - cwd: workspace examples: - "tflint myfile.tf" - "tflint -c .tflint.hcl myfile.tf" diff --git a/megalinter/linters/TfLintLinter.py b/megalinter/linters/TfLintLinter.py new file mode 100644 index 00000000000..e8abb208b63 --- /dev/null +++ b/megalinter/linters/TfLintLinter.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +""" +Use TfLint to lint terraform files +https://github.com/terraform-linters/tflint +""" +import logging + +import megalinter + + +class TfLintLinter(megalinter.Linter): + + # To execute before linting files + def before_lint_files(self): + # Build pre-command + tflint_init_command = "tflint --init" + if self.config_file is not None: + tflint_init_command += f" --config {self.config_file}" + logging.debug("tflint before_lint_files: " + tflint_init_command) + # Add to pre-commands + tflint_pre_command = {"command": tflint_init_command, "cwd": self.workspace} + if self.pre_commands is None: + self.pre_commands = [] + self.pre_commands.append(tflint_pre_command)