From b7db095221088a6ece6bc92f9a16e216693fd032 Mon Sep 17 00:00:00 2001 From: Jeroen Ruigrok van der Werven Date: Wed, 20 Jun 2018 14:58:12 +0200 Subject: [PATCH 1/2] Make CloudFormation linter work again with latest - Fix regexp - Get rid of +0 since ALE does a str2nr() on lnum and col - Put all matches in numerical order for easier maintenance --- ale_linters/cloudformation/cfn_python_lint.vim | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ale_linters/cloudformation/cfn_python_lint.vim b/ale_linters/cloudformation/cfn_python_lint.vim index 25e86ca3..d0ac7b28 100644 --- a/ale_linters/cloudformation/cfn_python_lint.vim +++ b/ale_linters/cloudformation/cfn_python_lint.vim @@ -4,8 +4,8 @@ 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:]]+)\] (.*)$' + " 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) @@ -13,13 +13,13 @@ function! ale_linters#cloudformation#cfn_python_lint#Handle(buffer, lines) abort if ale#path#IsBufferPath(a:buffer, l:match[1]) call add(l:output, { - \ 'lnum': l:match[2] + 0, - \ 'col': l:match[3] + 0, - \ 'end_lnum': l:match[4] + 0, - \ 'end_col': l:match[5] + 0, - \ 'text': l:match[7], + \ 'lnum': l:match[2], + \ 'col': l:match[3], + \ 'end_lnum': l:match[4], + \ 'end_col': l:match[5], \ 'code': l:code, \ 'type': l:code[:0] is# 'E' ? 'E' : 'W', + \ 'text': l:match[7] \}) endif endfor From f14e3bb109f19e432c455314849880d08d9d5729 Mon Sep 17 00:00:00 2001 From: Jeroen Ruigrok van der Werven Date: Wed, 20 Jun 2018 15:29:26 +0200 Subject: [PATCH 2/2] Update test to match update to linter Also make lnum and col proper strings, since that is how it is matched by the regexp, ALE handles the conversion to number. --- .../test_cfn_python_lint_handler.vader | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/handler/test_cfn_python_lint_handler.vader b/test/handler/test_cfn_python_lint_handler.vader index a053e84e..2c7ddc62 100644 --- a/test/handler/test_cfn_python_lint_handler.vader +++ b/test/handler/test_cfn_python_lint_handler.vader @@ -9,25 +9,25 @@ Execute(The cfn_python_lint handler should parse items correctly): AssertEqual \ [ \ { - \ 'lnum': 96, - \ 'col': 7, - \ 'end_lnum': 96, - \ 'end_col': 15, + \ 'lnum': '96', + \ 'col': '7', + \ 'end_lnum': '96', + \ 'end_col': '15', \ 'text': 'Property Resources/Sample/Properties/FromPort should be of type Integer', \ 'code': 'E3012', \ 'type': 'E', \ }, \ { - \ 'lnum': 97, - \ 'col': 7, - \ 'end_lnum': 97, - \ 'end_col': 15, + \ 'lnum': '97', + \ 'col': '7', + \ 'end_lnum': '97', + \ 'end_col': '15', \ '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]))$"', + \ 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]))$"', \ ])