diff options
author | w0rp <devw0rp@gmail.com> | 2024-06-02 19:07:06 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2024-06-02 19:07:06 +0100 |
commit | c7c41e157478fc9d4f65e9f640bfce75fa211fd7 (patch) | |
tree | 70b096ad66dac124b6175acbb5b415f821394fed | |
parent | adaa7f6f62366e5ed8aa76e79ca74f32a3b196b3 (diff) | |
download | ale-c7c41e157478fc9d4f65e9f640bfce75fa211fd7.zip |
Run actionlint by default on GitHub files
Detect paths containing .github as a directory for running actionlint
by default on YAML filetypes.
-rw-r--r-- | ale_linters/yaml/actionlint.vim | 5 | ||||
-rw-r--r-- | autoload/ale/linter.vim | 2 | ||||
-rw-r--r-- | doc/ale.txt | 2 | ||||
-rw-r--r-- | supported-tools.md | 2 | ||||
-rw-r--r-- | test/handler/test_actionlint_handler.vader | 43 | ||||
-rw-r--r-- | test/linter/test_yaml_actionlint.vader | 51 | ||||
-rw-r--r-- | test/test_filetype_linter_defaults.vader | 3 |
7 files changed, 61 insertions, 47 deletions
diff --git a/ale_linters/yaml/actionlint.vim b/ale_linters/yaml/actionlint.vim index 20455765..5afe6d48 100644 --- a/ale_linters/yaml/actionlint.vim +++ b/ale_linters/yaml/actionlint.vim @@ -5,6 +5,11 @@ call ale#Set('yaml_actionlint_executable', 'actionlint') call ale#Set('yaml_actionlint_options', '') function! ale_linters#yaml#actionlint#GetCommand(buffer) abort + " Only execute actionlint on YAML files in /.github/ paths. + if expand('#' . a:buffer . ':p') !~# '\v[/\\]\.github[/\\]' + return '' + endif + let l:options = ale#Var(a:buffer, 'yaml_actionlint_options') if l:options !~# '-no-color' diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim index 20104fbc..3cfd8ead 100644 --- a/autoload/ale/linter.vim +++ b/autoload/ale/linter.vim @@ -60,7 +60,7 @@ let s:default_ale_linters = { \ 'vue': ['eslint', 'vls'], \ 'zsh': ['shell'], \ 'v': ['v'], -\ 'yaml': ['spectral', 'yaml-language-server', 'yamllint'], +\ 'yaml': ['actionlint', 'spectral', 'yaml-language-server', 'yamllint'], \} " Testing/debugging helper to unload all linters. diff --git a/doc/ale.txt b/doc/ale.txt index 9f5d4f86..c7ed1a44 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1670,7 +1670,7 @@ g:ale_linters *g:ale_linters* \ 'vue': ['eslint', 'vls'], \ 'zsh': ['shell'], \ 'v': ['v'], - \ 'yaml': ['spectral', 'yaml-language-server', 'yamllint'], + \ 'yaml': ['actionlint', 'spectral', 'yaml-language-server', 'yamllint'], \} < This option can be used to enable only a particular set of linters for a diff --git a/supported-tools.md b/supported-tools.md index 0b6383f5..56a5a6c9 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -720,7 +720,7 @@ formatting. * XML * [xmllint](http://xmlsoft.org/xmllint.html) * YAML - * [actionlint](https://github.com/rhysd/actionlint) :warning: + * [actionlint](https://github.com/rhysd/actionlint) * [circleci](https://circleci.com/docs/2.0/local-cli) :floppy_disk: :warning: * [gitlablint](https://github.com/elijah-roberts/gitlab-lint) * [prettier](https://github.com/prettier/prettier) diff --git a/test/handler/test_actionlint_handler.vader b/test/handler/test_actionlint_handler.vader new file mode 100644 index 00000000..abf01b31 --- /dev/null +++ b/test/handler/test_actionlint_handler.vader @@ -0,0 +1,43 @@ +Before: + runtime ale_linters/yaml/actionlint.vim + +After: + call ale#linter#Reset() + +Execute(Problems should be parsed correctly for actionlint): + AssertEqual + \ [ + \ { + \ 'lnum': 2, + \ 'col': 1, + \ 'type': 'E', + \ 'text': '"jobs" section is missing in workflow', + \ 'code': 'syntax-check', + \ }, + \ { + \ 'lnum': 56, + \ 'col': 23, + \ 'type': 'E', + \ 'text': 'property "unknown_input" is not defined in object type {input7: bool; input0: any; input1: any; input2: string; input3: any; input4: any; input5: number; input6: number}', + \ 'code': 'expression', + \ }, + \ ], + \ ale_linters#yaml#actionlint#Handle(bufnr(''), [ + \ '.codecov.yaml:2:1: "jobs" section is missing in workflow [syntax-check]', + \ 'workflow_call_event.yaml:56:23: property "unknown_input" is not defined in object type {input7: bool; input0: any; input1: any; input2: string; input3: any; input4: any; input5: number; input6: number} [expression]', + \ ]) + +Execute(Shellcheck issues should be reported at the line they appear): + AssertEqual + \ [ + \ { + \ 'lnum': 19, + \ 'col': 9, + \ 'type': 'E', + \ 'text': 'Double quote to prevent globbing and word splitting', + \ 'code': 'shellcheck SC2086', + \ }, + \ ], + \ ale_linters#yaml#actionlint#Handle(bufnr(''), [ + \ 'validate.yml:19:9: shellcheck reported issue in this script: SC2086:info:1:15: Double quote to prevent globbing and word splitting [shellcheck]' + \ ]) diff --git a/test/linter/test_yaml_actionlint.vader b/test/linter/test_yaml_actionlint.vader index d9970cf5..db34007f 100644 --- a/test/linter/test_yaml_actionlint.vader +++ b/test/linter/test_yaml_actionlint.vader @@ -1,57 +1,20 @@ Before: call ale#assert#SetUpLinterTest('yaml', 'actionlint') + call ale#test#SetFilename('/.github/file.yml') After: call ale#assert#TearDownLinterTest() -Execute(Problems should be parsed correctly for actionlint): - AssertEqual - \ [ - \ { - \ 'lnum': 2, - \ 'col': 1, - \ 'type': 'E', - \ 'text': '"jobs" section is missing in workflow', - \ 'code': 'syntax-check', - \ }, - \ { - \ 'lnum': 56, - \ 'col': 23, - \ 'type': 'E', - \ 'text': 'property "unknown_input" is not defined in object type {input7: bool; input0: any; input1: any; input2: string; input3: any; input4: any; input5: number; input6: number}', - \ 'code': 'expression', - \ }, - \ ], - \ ale_linters#yaml#actionlint#Handle(bufnr(''), [ - \ '.codecov.yaml:2:1: "jobs" section is missing in workflow [syntax-check]', - \ 'workflow_call_event.yaml:56:23: property "unknown_input" is not defined in object type {input7: bool; input0: any; input1: any; input2: string; input3: any; input4: any; input5: number; input6: number} [expression]', - \ ]) - -Execute(Shellcheck issues should be reported at the line they appear): - AssertEqual - \ [ - \ { - \ 'lnum': 19, - \ 'col': 9, - \ 'type': 'E', - \ 'text': 'Double quote to prevent globbing and word splitting', - \ 'code': 'shellcheck SC2086', - \ }, - \ ], - \ ale_linters#yaml#actionlint#Handle(bufnr(''), [ - \ 'validate.yml:19:9: shellcheck reported issue in this script: SC2086:info:1:15: Double quote to prevent globbing and word splitting [shellcheck]' - \ ]) - Execute(Command should always have -no-color, -oneline and - options): let g:ale_yaml_actionlint_options = '' - AssertEqual - \ '%e -no-color -oneline - ', - \ ale_linters#yaml#actionlint#GetCommand(bufnr('')) + AssertLinter 'actionlint', ale#Escape('actionlint') . ' -no-color -oneline - ' Execute(Options should be added to command): let g:ale_yaml_actionlint_options = '-shellcheck= -pyflakes=' - AssertEqual - \ '%e -shellcheck= -pyflakes= -no-color -oneline - ', - \ ale_linters#yaml#actionlint#GetCommand(bufnr('')) + AssertLinter 'actionlint', + \ ale#Escape('actionlint') . ' -shellcheck= -pyflakes= -no-color -oneline - ' + +Execute(actionlint not run on files outside of /.github/ paths): + call ale#test#SetFilename('/something-else/file.yml') diff --git a/test/test_filetype_linter_defaults.vader b/test/test_filetype_linter_defaults.vader index 242a57de..b4b6380d 100644 --- a/test/test_filetype_linter_defaults.vader +++ b/test/test_filetype_linter_defaults.vader @@ -135,3 +135,6 @@ Execute(The defaults for the vader filetype should be correct): Execute(Default aliases for React should be defined): AssertEqual ['javascript', 'jsx'], ale#linter#ResolveFiletype('javascriptreact') AssertEqual ['typescript', 'tsx'], ale#linter#ResolveFiletype('typescriptreact') + +Execute(The defaults for the yaml filetype should be correct): + AssertEqual ['actionlint', 'spectral', 'yaml-language-server', 'yamllint'], GetLinterNames('yaml') |