Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tflint initialization #1204

Merged
merged 6 commits into from
Jan 27, 2022
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
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions megalinter/descriptors/terraform.megalinter-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 24 additions & 0 deletions megalinter/linters/TfLintLinter.py
Original file line number Diff line number Diff line change
@@ -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)