Skip to content

Commit

Permalink
Add terraform-tflint checker
Browse files Browse the repository at this point in the history
  • Loading branch information
marsam committed Jun 19, 2019
1 parent d4f82aa commit d2cd2aa
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- VHDL with ``ghdl`` [GH-1160]
- mypy with ``python-mypy`` [GH-1354]
- terraform with ``terraform fmt`` [GH-1586]
- terraform-tflint with ``tflint`` [GH-1586]

- New features:

Expand Down
4 changes: 4 additions & 0 deletions doc/languages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,10 @@ to view the docstring of the syntax checker. Likewise, you may use

.. _terraform fmt: https://www.terraform.io/docs/commands/fmt.html

.. syntax-checker:: terraform-tflint

Check Terraform with `tflint <https://github.com/wata727/tflint>`_

.. supported-language:: Text

.. syntax-checker:: proselint
Expand Down
35 changes: 35 additions & 0 deletions flycheck.el
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ attention to case differences."
systemd-analyze
tcl-nagelfar
terraform
terraform-tflint
tex-chktex
tex-lacheck
texinfo
Expand Down Expand Up @@ -10770,6 +10771,40 @@ See URL `https://www.terraform.io/docs/commands/fmt.html'."
"\n\n on <stdin> line " line ":\n (source code not available)\n\n"
(message (one-or-more (and (one-or-more (not (any ?\n))) ?\n)))
line-end))
:next-checkers ((warning . terraform-tflint))
:modes terraform-mode)

(defun flycheck-parse-tflint-linter (output checker buffer)
"Parse tflint warnings from JSON OUTPUT.

CHECKER and BUFFER denote the CHECKER that returned OUTPUT and
the BUFFER that was checked respectively.

See URL `https://github.com/wata727/tflint' for more
information about tflint."
(mapcar (lambda (err)
(let-alist err
(flycheck-error-new-at
.line
nil
(pcase .type
(`"ERROR" 'error)
(`"WARNING" 'warning)
;; Default to error
(_ 'error))
.message
:id .detector
:checker checker
:buffer buffer
:filename (buffer-file-name buffer))))
(car (flycheck-parse-json output))))

(flycheck-define-checker terraform-tflint
"A Terraform checker using tflint.

See URL `https://github.com/wata727/tflint'."
:command ("tflint" "--error-with-issues" "--format=json" source)
:error-parser flycheck-parse-tflint-linter
:modes terraform-mode)

(flycheck-define-checker tex-chktex
Expand Down
6 changes: 6 additions & 0 deletions test/flycheck-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -4089,6 +4089,12 @@ Why not:
'(2 nil error "An argument definition must end with a newline."
:checker terraform)))

(flycheck-ert-def-checker-test terraform-tflint terraform nil
(flycheck-ert-should-syntax-check
"language/terraform/error.tf" 'terraform-mode
'(3 nil error "\"t1.2xlarge\" is invalid instance type."
:id "aws_instance_invalid_type" :checker terraform-tflint)))

(flycheck-ert-def-checker-test markdown-markdownlint-cli markdown nil
(flycheck-ert-should-syntax-check
"language/markdown.md" 'markdown-mode
Expand Down
4 changes: 4 additions & 0 deletions test/resources/language/terraform/error.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "aws_instance" "web" {
ami = "ami-b73b63a0"
instance_type = "t1.2xlarge" # invalid type
}

0 comments on commit d2cd2aa

Please sign in to comment.