mirror of
https://github.com/dense-analysis/ale.git
synced 2026-11-11 14:40:27 +08:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9acafa8018 | ||
|
|
11cbd96667 | ||
|
|
ce1ee7c598 | ||
|
|
a083d58c7f | ||
|
|
3539f39d4d |
No files matched your search
@@ -61,6 +61,14 @@ linting and fixing of code in Vim. ALE offers the following.
|
||||
* Windows support
|
||||
* Well-integrated with other plugins
|
||||
|
||||
## Sponsorship
|
||||
|
||||
If you would like to donate to Dense Analysis to say thank you for ALE, please
|
||||
consider visiting our [Sponsorship page](https://denseanalysis.org/sponsors/).
|
||||
Funds will be used to pay for our hosting fees and research. Whilst visiting our
|
||||
site, please feel free to make use of our educational resources and other
|
||||
recommended tools.
|
||||
|
||||
## Supported Languages and Tools
|
||||
|
||||
ALE supports a wide variety of languages and tools. See the
|
||||
|
||||
@@ -5,6 +5,14 @@ call ale#Set('bitbake_oelint_adv_executable', 'oelint-adv')
|
||||
call ale#Set('bitbake_oelint_adv_options', '')
|
||||
call ale#Set('bitbake_oelint_adv_config', '.oelint.cfg')
|
||||
|
||||
function! ale_linters#bitbake#oelint_adv#StripAnsiCodes(line) abort
|
||||
return substitute(a:line, '\e\[[0-9;]\+[mK]', '', 'g')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#bitbake#oelint_adv#RemoveBranch(line) abort
|
||||
return substitute(a:line, ' \[branch:.*', '', 'g')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#bitbake#oelint_adv#Command(buffer) abort
|
||||
let l:config_file = ale#path#FindNearestFile(a:buffer,
|
||||
\ ale#Var(a:buffer, 'bitbake_oelint_adv_config'))
|
||||
@@ -17,26 +25,25 @@ function! ale_linters#bitbake#oelint_adv#Command(buffer) abort
|
||||
endfunction
|
||||
|
||||
function! ale_linters#bitbake#oelint_adv#Handle(buffer, lines) abort
|
||||
let l:pattern = '\v^(.+):(.+):(.+):(.+):(.+)$'
|
||||
let l:pattern = '\v^(.{-}):(.{-}):(.{-}):(.{-}):(.{-})$'
|
||||
let l:output = []
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
call add(l:output, {
|
||||
\ 'lnum': str2nr(l:match[2]),
|
||||
\ 'type': l:match[3] is# 'error'
|
||||
\ ? 'E' : (l:match[3] is# 'warning' ? 'W' : 'I'),
|
||||
\ 'text': StripAnsiCodes(l:match[5]),
|
||||
\ 'code': l:match[4]
|
||||
\ })
|
||||
\ 'lnum': str2nr(l:match[2]),
|
||||
\ 'type': l:match[3] is# 'error'
|
||||
\ ? 'E'
|
||||
\ : (l:match[3] is# 'warning' ? 'W' : 'I'),
|
||||
\ 'text': ale_linters#bitbake#oelint_adv#RemoveBranch(
|
||||
\ ale_linters#bitbake#oelint_adv#StripAnsiCodes(l:match[5])
|
||||
\ ),
|
||||
\ 'code': l:match[4],
|
||||
\})
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
function! StripAnsiCodes(line) abort
|
||||
return substitute(a:line, '\e\[[0-9;]\+[mK]', '', 'g')
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('bitbake', {
|
||||
\ 'name': 'oelint_adv',
|
||||
\ 'output_stream': 'both',
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
" Author: J. Handsel <jennpbc@posteo.net>, Thyme-87 <thyme-87@posteo.me>
|
||||
" Description: use checkov for providing warnings for cloudformation via ale
|
||||
|
||||
call ale#Set('cloudformation_checkov_executable', 'checkov')
|
||||
call ale#Set('cloudformation_checkov_options', '')
|
||||
|
||||
function! ale_linters#cloudformation#checkov#GetExecutable(buffer) abort
|
||||
return ale#Var(a:buffer, 'cloudformation_checkov_executable')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#cloudformation#checkov#GetCommand(buffer) abort
|
||||
return '%e ' . '-f %t -o json --quiet --framework cloudformation ' . ale#Var(a:buffer, 'cloudformation_checkov_options')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#cloudformation#checkov#Handle(buffer, lines) abort
|
||||
let l:output = []
|
||||
|
||||
let l:results = get(get(ale#util#FuzzyJSONDecode(a:lines, {}), 'results', []), 'failed_checks', [])
|
||||
|
||||
for l:violation in l:results
|
||||
call add(l:output, {
|
||||
\ 'filename': l:violation['file_path'],
|
||||
\ 'lnum': l:violation['file_line_range'][0],
|
||||
\ 'end_lnum': l:violation['file_line_range'][1],
|
||||
\ 'text': l:violation['check_name'] . ' [' . l:violation['check_id'] . ']',
|
||||
\ 'detail': l:violation['check_id'] . ': ' . l:violation['check_name'] . "\n" .
|
||||
\ 'For more information, see: '. l:violation['guideline'],
|
||||
\ 'type': 'W',
|
||||
\ })
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('cloudformation', {
|
||||
\ 'name': 'checkov',
|
||||
\ 'output_stream': 'stdout',
|
||||
\ 'executable': function('ale_linters#cloudformation#checkov#GetExecutable'),
|
||||
\ 'command': function('ale_linters#cloudformation#checkov#GetCommand'),
|
||||
\ 'callback': 'ale_linters#cloudformation#checkov#Handle',
|
||||
\})
|
||||
@@ -41,5 +41,51 @@ Just put the following in `ftdetect/cloudformation.vim`: >
|
||||
This will get both cloudformation and yaml linters to work on any file with
|
||||
`.template.yaml` extension.
|
||||
|
||||
|
||||
===============================================================================
|
||||
checkov *ale-cloudformation-checkov*
|
||||
|
||||
*ale-options.cloudformation_checkov_executable*
|
||||
*g:ale_cloudformation_checkov_executable*
|
||||
*b:ale_cloudformation_checkov_executable*
|
||||
cloudformation_checkov_executable
|
||||
g:ale_cloudformation_checkov_executable
|
||||
Type: |String|
|
||||
Default: `'checkov'`
|
||||
|
||||
This variable can be changed to use a different executable for checkov.
|
||||
|
||||
*ale-options.cloudformation_checkov_options*
|
||||
*g:ale_cloudformation_checkov_options*
|
||||
*b:ale_cloudformation_checkov_options*
|
||||
cloudformation_checkov_options
|
||||
g:ale_cloudformation_checkov_options
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
This variable can be changed to set additional options for checkov.
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Configuration
|
||||
|
||||
To get chekov to work with cloudformation files (rather than general yaml
|
||||
files) we must set the buffer |filetype| to `yaml.cloudformation`. This
|
||||
causes ALE to lint the file with linters configured for cloudformation and
|
||||
YAML files.
|
||||
|
||||
One option is to put the following in `ftdetect/cloudformation.vim`: >
|
||||
|
||||
au BufRead,BufNewFile *.template.yaml set filetype=yaml.cloudformation
|
||||
|
||||
This will get both cloudformation and yaml linters to work on any file with
|
||||
`.template.yaml` extension.
|
||||
|
||||
Another option is to check for the presence of 'AWSTemplateFormatVersion' in
|
||||
the yaml file: >
|
||||
|
||||
au BufRead,BufNewFile *.yaml,*.yml if search('AWSTemplateFormatVersion', 'nw') | set filetype=yaml.cloudformation | endif
|
||||
<
|
||||
|
||||
===============================================================================
|
||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||
+10
-5
@@ -49,17 +49,22 @@ g:ale_lua_language_server_executable
|
||||
If you have compiled the language server yourself in `/some/path`, the path
|
||||
will be `'/some/path/bin/lua-language-server'`.
|
||||
|
||||
*ale-options.lua_lua_language_server_config*
|
||||
*g:ale_lua_lua_language_server_config*
|
||||
*b:ale_lua_lua_language_server_config*
|
||||
lua_lua_language_server_config
|
||||
g:ale_lua_lua_language_server_config
|
||||
*ale-options.lua_language_server_config*
|
||||
*g:ale_lua_language_server_config*
|
||||
*b:ale_lua_language_server_config*
|
||||
lua_language_server_config
|
||||
g:ale_lua_language_server_config
|
||||
|
||||
Type: |Dictionary|
|
||||
Default: `{}`
|
||||
|
||||
Dictionary containing configuration settings that will be passed to the
|
||||
language server.
|
||||
|
||||
For available configuration parameters, see `Settings` on the luals wiki:
|
||||
|
||||
https://luals.github.io/wiki/settings/
|
||||
|
||||
|
||||
===============================================================================
|
||||
luac *ale-lua-luac*
|
||||
|
||||
@@ -121,6 +121,7 @@ Notes:
|
||||
* `joker`
|
||||
* CloudFormation
|
||||
* `cfn-python-lint`
|
||||
* `checkov`
|
||||
* CMake
|
||||
* `cmake-format`
|
||||
* `cmake-lint`
|
||||
|
||||
@@ -3419,6 +3419,7 @@ documented in additional help files.
|
||||
joker.................................|ale-clojure-joker|
|
||||
cloudformation..........................|ale-cloudformation-options|
|
||||
cfn-python-lint.......................|ale-cloudformation-cfn-python-lint|
|
||||
checkov...............................|ale-cloudformation-checkov|
|
||||
cmake...................................|ale-cmake-options|
|
||||
cmakelint.............................|ale-cmake-cmakelint|
|
||||
cmake-lint............................|ale-cmake-cmake-lint|
|
||||
|
||||
@@ -131,6 +131,7 @@ formatting.
|
||||
* [joker](https://github.com/candid82/joker)
|
||||
* CloudFormation
|
||||
* [cfn-python-lint](https://github.com/awslabs/cfn-python-lint)
|
||||
* [checkov](https://github.com/bridgecrewio/checkov)
|
||||
* CMake
|
||||
* [cmake-format](https://github.com/cheshirekow/cmake_format)
|
||||
* [cmake-lint](https://github.com/cheshirekow/cmake_format)
|
||||
|
||||
@@ -7,6 +7,27 @@ After:
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(The oelint_adv handler should handle warnings):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 1234,
|
||||
\ 'type': 'I',
|
||||
\ 'code': 'oelint.var.suggestedvar.BUGTRACKER',
|
||||
\ 'text': 'Variable ''BUGTRACKER'' should be set',
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 17,
|
||||
\ 'type': 'E',
|
||||
\ 'code': 'oelint.var.mandatoryvar.DESCRIPTION',
|
||||
\ 'text': 'Variable ''DESCRIPTION'' should be set',
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#bitbake#oelint_adv#Handle(1, [
|
||||
\ '/meta-x/recipes-y/example/example_1.0.bb:1234:info:oelint.var.suggestedvar.BUGTRACKER:Variable ''BUGTRACKER'' should be set [branch:true]',
|
||||
\ '[31mexample2_1.1.bb:17:error:oelint.var.mandatoryvar.DESCRIPTION:Variable ''DESCRIPTION'' should be set[0m [branch:true]',
|
||||
\ ])
|
||||
|
||||
Execute(The oelint_adv handler should handle warnings without branch message):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
Before:
|
||||
runtime ale_linters/cloudformation/checkov.vim
|
||||
call ale#test#SetFilename('sample.template.yaml')
|
||||
|
||||
After:
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(Handle output for no findings correctly):
|
||||
AssertEqual
|
||||
\ [],
|
||||
\ ale_linters#cloudformation#checkov#Handle(bufnr(''), [
|
||||
\'{',
|
||||
\' "passed": 0,',
|
||||
\' "failed": 0,',
|
||||
\' "skipped": 0,',
|
||||
\' "parsing_errors": 0,',
|
||||
\' "resource_count": 0,',
|
||||
\' "checkov_version": "3.2.415"',
|
||||
\'}'
|
||||
\])
|
||||
|
||||
Execute(Handle output for all tests passed):
|
||||
AssertEqual
|
||||
\ [],
|
||||
\ ale_linters#cloudformation#checkov#Handle(bufnr(''), [
|
||||
\'{',
|
||||
\' "check_type": "cloudformation",',
|
||||
\' "results": {',
|
||||
\' "failed_checks": []',
|
||||
\' },',
|
||||
\' "summary": {',
|
||||
\' "passed": 18,',
|
||||
\' "failed": 0,',
|
||||
\' "skipped": 0,',
|
||||
\' "parsing_errors": 0,',
|
||||
\' "resource_count": 3,',
|
||||
\' "checkov_version": "3.2.415"',
|
||||
\' }',
|
||||
\'}'
|
||||
\])
|
||||
|
||||
Execute(The JSON output of checkov should be handled correctly):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'filename': '/sample.template.yaml',
|
||||
\ 'lnum': 57,
|
||||
\ 'end_lnum': 79,
|
||||
\ 'text': 'Ensure that AWS Lambda function is configured for a Dead Letter Queue(DLQ) [CKV_AWS_116]',
|
||||
\ 'detail': "CKV_AWS_116: Ensure that AWS Lambda function is configured for a Dead Letter Queue(DLQ)\n" .
|
||||
\ 'For more information, see: https://docs.prismacloud.io/en/enterprise-edition/policy-reference/aws-policies/aws-general-policies/ensure-that-aws-lambda-function-is-configured-for-a-dead-letter-queue-dlq',
|
||||
\ 'type': 'W',
|
||||
\ }
|
||||
\ ],
|
||||
\ ale_linters#cloudformation#checkov#Handle(bufnr(''), [
|
||||
\'{',
|
||||
\' "check_type": "cloudformation",',
|
||||
\' "results": {',
|
||||
\' "failed_checks": [',
|
||||
\' {',
|
||||
\' "check_id": "CKV_AWS_116",',
|
||||
\' "bc_check_id": "BC_AWS_GENERAL_64",',
|
||||
\' "check_name": "Ensure that AWS Lambda function is configured for a Dead Letter Queue(DLQ)",',
|
||||
\' "check_result": {',
|
||||
\' "result": "FAILED",',
|
||||
\' "evaluated_keys": [',
|
||||
\' "Properties/DeadLetterQueue/TargetArn"',
|
||||
\' ]',
|
||||
\' },',
|
||||
\' "file_path": "/sample.template.yaml",',
|
||||
\' "repo_file_path": "/sample.template.yaml",',
|
||||
\' "file_line_range": [',
|
||||
\' 57,',
|
||||
\' 79',
|
||||
\' ],',
|
||||
\' "resource": "AWS::Serverless::Function.FunctionName",',
|
||||
\' "evaluations": {},',
|
||||
\' "check_class": "checkov.cloudformation.checks.resource.aws.LambdaDLQConfigured",',
|
||||
\' "entity_tags": null,',
|
||||
\' "resource_address": null,',
|
||||
\' "guideline": "https://docs.prismacloud.io/en/enterprise-edition/policy-reference/aws-policies/aws-general-policies/ensure-that-aws-lambda-function-is-configured-for-a-dead-letter-queue-dlq"',
|
||||
\' }',
|
||||
\' ]',
|
||||
\' }',
|
||||
\'}'
|
||||
\ ])
|
||||
@@ -0,0 +1,15 @@
|
||||
Before:
|
||||
call ale#assert#SetUpLinterTest('cloudformation', 'checkov')
|
||||
|
||||
After:
|
||||
call ale#assert#TearDownLinterTest()
|
||||
|
||||
Execute(The default command should be direct):
|
||||
AssertLinter 'checkov',
|
||||
\ ale#Escape('checkov') . ' -f %t -o json --quiet --framework cloudformation '
|
||||
|
||||
Execute(It should be possible to override the default command):
|
||||
let b:ale_cloudformation_checkov_executable = '/bin/other/checkov'
|
||||
AssertLinter '/bin/other/checkov',
|
||||
\ ale#Escape('/bin/other/checkov') . ' -f %t -o json --quiet --framework cloudformation '
|
||||
|
||||
Reference in new issue
Block a user