mirror of
https://github.com/dense-analysis/ale
synced 2024-12-22 06:10:07 +00:00
Add linter for AWS CloudFormation template file
This commit is contained in:
parent
22a9dcd03e
commit
ae25d71fa8
@ -98,6 +98,7 @@ formatting.
|
||||
| C# | [mcs](http://www.mono-project.com/docs/about-mono/languages/csharp/) see:`help ale-cs-mcs` for details, [mcsc](http://www.mono-project.com/docs/about-mono/languages/csharp/) !! see:`help ale-cs-mcsc` for details and configuration|
|
||||
| Chef | [foodcritic](http://www.foodcritic.io/) |
|
||||
| Clojure | [joker](https://github.com/candid82/joker) |
|
||||
| CloudFormation | [cfn-python-lint](https://github.com/awslabs/cfn-python-lint) |
|
||||
| CMake | [cmakelint](https://github.com/richq/cmake-lint) |
|
||||
| CoffeeScript | [coffee](http://coffeescript.org/), [coffeelint](https://www.npmjs.com/package/coffeelint) |
|
||||
| Crystal | [crystal](https://crystal-lang.org/) !! |
|
||||
|
33
ale_linters/cloudformation/cfn_python_lint.vim
Normal file
33
ale_linters/cloudformation/cfn_python_lint.vim
Normal file
@ -0,0 +1,33 @@
|
||||
" Author: Yasuhiro Kiyota <yasuhiroki.duck@gmail.com>
|
||||
" Description: Support cfn-python-lint for AWS Cloudformation template file
|
||||
|
||||
function! ale_linters#cloudformation#cfn_python_lint#Handle(buffer, lines) abort
|
||||
" Matches patterns line the following:
|
||||
"
|
||||
" sample.template.yaml:96:7:96:15: [E3012] Property Resources/Sample/Properties/FromPort should be of type Integer
|
||||
let l:pattern = '\v^(.*):(\d+):(\d+):(\d+):(\d+): \[([[:alnum:]]+)\] (.*)$'
|
||||
let l:output = []
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
let l:code = l:match[6]
|
||||
|
||||
if ale#path#IsBufferPath(a:buffer, l:match[1])
|
||||
call add(l:output, {
|
||||
\ 'lnum': l:match[2] + 0,
|
||||
\ 'col': l:match[3] + 0,
|
||||
\ 'text': l:match[7],
|
||||
\ 'code': l:code,
|
||||
\ 'type': l:code[:0] is# 'E' ? 'E' : 'W',
|
||||
\})
|
||||
endif
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('cloudformation', {
|
||||
\ 'name': 'cloudformation',
|
||||
\ 'executable': 'cfn-lint',
|
||||
\ 'command': 'cfn-lint --template %t --format parseable',
|
||||
\ 'callback': 'ale_linters#cloudformation#cfn_python_lint#Handle',
|
||||
\})
|
14
doc/ale-cloudformation.txt
Normal file
14
doc/ale-cloudformation.txt
Normal file
@ -0,0 +1,14 @@
|
||||
===============================================================================
|
||||
ALE CloudFormation Integration *ale-cloudformation-options*
|
||||
|
||||
|
||||
===============================================================================
|
||||
cfn-python-lint *ale-cloudformation-cfn-python-lint*
|
||||
|
||||
cfn-python-lint is a linter for AWS CloudFormation template file.
|
||||
|
||||
https://github.com/awslabs/cfn-python-lint
|
||||
|
||||
===============================================================================
|
||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||
|
@ -35,6 +35,8 @@ CONTENTS *ale-contents*
|
||||
foodcritic..........................|ale-chef-foodcritic|
|
||||
clojure...............................|ale-clojure-options|
|
||||
joker...............................|ale-clojure-joker|
|
||||
cloudformation........................|ale-cloudformation-options|
|
||||
cfn-python-lint.....................|ale-cloudformation-cfn-python-lint|
|
||||
cmake.................................|ale-cmake-options|
|
||||
cmakelint...........................|ale-cmake-cmakelint|
|
||||
cpp...................................|ale-cpp-options|
|
||||
@ -325,6 +327,7 @@ Notes:
|
||||
* C#: `mcs`, `mcsc`!!
|
||||
* Chef: `foodcritic`
|
||||
* Clojure: `joker`
|
||||
* CloudFormation: `cfn-python-lint`
|
||||
* CMake: `cmakelint`
|
||||
* CoffeeScript: `coffee`, `coffeelint`
|
||||
* Crystal: `crystal`!!
|
||||
|
29
test/handler/test_cfn_python_lint_handler.vader
Normal file
29
test/handler/test_cfn_python_lint_handler.vader
Normal file
@ -0,0 +1,29 @@
|
||||
Before:
|
||||
runtime! ale_linters/cloudformation/cfn_python_lint.vim
|
||||
call ale#test#SetFilename('sample.template.yaml')
|
||||
|
||||
After:
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(The cfn_python_lint handler should parse items correctly):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 96,
|
||||
\ 'col': 7,
|
||||
\ 'text': 'Property Resources/Sample/Properties/FromPort should be of type Integer',
|
||||
\ 'code': 'E3012',
|
||||
\ 'type': 'E',
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 97,
|
||||
\ 'col': 7,
|
||||
\ 'text': 'AllowedPattern and/or AllowedValues for Parameter should be specified at Parameters/SampleIpAddress. Example for AllowedPattern "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$"',
|
||||
\ 'code': 'W2509',
|
||||
\ 'type': 'W',
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#cloudformation#cfn_python_lint#Handle(bufnr(''), [
|
||||
\ fnamemodify(tempname(), ':h') . '/sample.template.yaml:96:7:96:15: [E3012] Property Resources/Sample/Properties/FromPort should be of type Integer',
|
||||
\ fnamemodify(tempname(), ':h') . '/sample.template.yaml:97:7:97:15: [W2509] AllowedPattern and/or AllowedValues for Parameter should be specified at Parameters/SampleIpAddress. Example for AllowedPattern "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$"',
|
||||
\ ])
|
Loading…
Reference in New Issue
Block a user