From c37cc1c8a3cd2d014258d4252c4b495e48e844a5 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Thu, 8 Oct 2020 11:54:17 -0400 Subject: [PATCH 01/12] dafny: include correct filename in lint results Results can come from included files, not just the current buffer. --- ale_linters/dafny/dafny.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ale_linters/dafny/dafny.vim b/ale_linters/dafny/dafny.vim index b5b90675..e6021d99 100644 --- a/ale_linters/dafny/dafny.vim +++ b/ale_linters/dafny/dafny.vim @@ -6,7 +6,7 @@ function! ale_linters#dafny#dafny#Handle(buffer, lines) abort for l:match in ale#util#GetMatches(a:lines, l:pattern) call add(l:output, { - \ 'bufnr': a:buffer, + \ 'filename': l:match[1], \ 'col': l:match[3] + 0, \ 'lnum': l:match[2] + 0, \ 'text': l:match[5], From 160af4945079ae8df28f298f6d508f15005418fb Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Thu, 8 Oct 2020 12:02:30 -0400 Subject: [PATCH 02/12] update tests --- test/handler/test_dafny_handler.vader | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/handler/test_dafny_handler.vader b/test/handler/test_dafny_handler.vader index 674f691d..797d348e 100644 --- a/test/handler/test_dafny_handler.vader +++ b/test/handler/test_dafny_handler.vader @@ -8,14 +8,14 @@ Execute(The Dafny handler should parse output correctly): AssertEqual \ [ \ { - \ 'bufnr': 0, + \ 'filename': 'File.dfy', \ 'col': 45, \ 'lnum': 123, \ 'text': 'A precondition for this call might not hold.', \ 'type': 'E' \ }, \ { - \ 'bufnr': 0, + \ 'filename': 'File.dfy', \ 'col': 90, \ 'lnum': 678, \ 'text': 'This is the precondition that might not hold.', From 373ffa0f316f14559870fb3903d723c6d88597ee Mon Sep 17 00:00:00 2001 From: Ivor Peles Date: Tue, 6 Oct 2020 02:12:05 -0400 Subject: [PATCH 03/12] Use pipenv isort executable when python_auto_pipenv = 1 --- autoload/ale/fixers/isort.vim | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/autoload/ale/fixers/isort.vim b/autoload/ale/fixers/isort.vim index 9070fb27..926822f2 100644 --- a/autoload/ale/fixers/isort.vim +++ b/autoload/ale/fixers/isort.vim @@ -5,14 +5,23 @@ call ale#Set('python_isort_executable', 'isort') call ale#Set('python_isort_options', '') call ale#Set('python_isort_use_global', get(g:, 'ale_use_global_executables', 0)) +function! ale#fixers#isort#GetExecutable(buffer) abort + if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_isort_auto_pipenv')) + \ && ale#python#PipenvPresent(a:buffer) + return 'pipenv' + endif + + return ale#python#FindExecutable(a:buffer, 'python_isort', ['isort']) +endfunction + function! ale#fixers#isort#Fix(buffer) abort let l:options = ale#Var(a:buffer, 'python_isort_options') - let l:executable = ale#python#FindExecutable( - \ a:buffer, - \ 'python_isort', - \ ['isort'], - \) + let l:executable = ale#fixers#isort#GetExecutable(a:buffer) + + let l:exec_args = l:executable =~? 'pipenv$' + \ ? ' run isort' + \ : '' if !executable(l:executable) return 0 @@ -20,6 +29,7 @@ function! ale#fixers#isort#Fix(buffer) abort return { \ 'command': ale#path#BufferCdString(a:buffer) - \ . ale#Escape(l:executable) . (!empty(l:options) ? ' ' . l:options : '') . ' -', + \ . ale#Escape(l:executable) . l:exec_args + \ . (!empty(l:options) ? ' ' . l:options : '') . ' -', \} endfunction From 64471e6ea88cc45dcd33e3a0ca5ee857797985e3 Mon Sep 17 00:00:00 2001 From: Ivor Peles Date: Tue, 6 Oct 2020 02:27:08 -0400 Subject: [PATCH 04/12] Document ale_python_isort_auto_pipenv option --- doc/ale-python.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/ale-python.txt b/doc/ale-python.txt index f0c8bfb8..504705f2 100644 --- a/doc/ale-python.txt +++ b/doc/ale-python.txt @@ -280,6 +280,15 @@ g:ale_python_isort_use_global *g:ale_python_isort_use_global* See |ale-integrations-local-executables| +g:ale_python_isort_auto_pipenv *g:ale_python_isort_auto_pipenv* + *b:ale_python_isort_auto_pipenv* + Type: |Number| + Default: `0` + + Detect whether the file is inside a pipenv, and set the executable to `pipenv` + if true. This is overridden by a manually-set executable. + + =============================================================================== mypy *ale-python-mypy* From ae86d10e48ae27e08665502772886016c3a3aa3b Mon Sep 17 00:00:00 2001 From: Ivor Peles Date: Tue, 6 Oct 2020 04:00:45 -0400 Subject: [PATCH 05/12] Set default value for python_isort_auto_pipenv --- autoload/ale/fixers/isort.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autoload/ale/fixers/isort.vim b/autoload/ale/fixers/isort.vim index 926822f2..13825f7e 100644 --- a/autoload/ale/fixers/isort.vim +++ b/autoload/ale/fixers/isort.vim @@ -2,8 +2,9 @@ " Description: Fixing Python imports with isort. call ale#Set('python_isort_executable', 'isort') -call ale#Set('python_isort_options', '') call ale#Set('python_isort_use_global', get(g:, 'ale_use_global_executables', 0)) +call ale#Set('python_isort_options', '') +call ale#Set('python_isort_auto_pipenv', 0) function! ale#fixers#isort#GetExecutable(buffer) abort if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_isort_auto_pipenv')) From 6efca486e8c228e9358d05e0a87d17e973da249e Mon Sep 17 00:00:00 2001 From: Ivor Peles Date: Tue, 6 Oct 2020 04:06:44 -0400 Subject: [PATCH 06/12] Add test for isort with auto_pipenv flag(s) --- test/fixers/test_isort_fixer_callback.vader | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/fixers/test_isort_fixer_callback.vader b/test/fixers/test_isort_fixer_callback.vader index 7f389dcf..76c8a4cb 100644 --- a/test/fixers/test_isort_fixer_callback.vader +++ b/test/fixers/test_isort_fixer_callback.vader @@ -5,6 +5,7 @@ Before: " Use an invalid global executable, so we don't match it. let g:ale_python_isort_executable = 'xxxinvalid' let g:ale_python_isort_options = '' + let g:ale_python_isort_auto_pipenv = 0 call ale#test#SetDirectory('/testplugin/test/fixers') silent cd .. @@ -48,3 +49,12 @@ Execute(The isort callback should respect custom options): \ . ' --multi-line=3 --trailing-comma -', \ }, \ ale#fixers#isort#Fix(bufnr('')) + +Execute(Pipenv is detected when python_isort_auto_pipenv is set): + let g:ale_python_isort_auto_pipenv = 1 + + call ale#test#SetFilename('/testplugin/test/python_fixtures/pipenv/whatever.py') + + AssertEqual + \ {'command': 'cd %s:h && ' . ale#Escape('pipenv') . ' run isort -'}, + \ ale#fixers#isort#Fix(bufnr('')) From d27a3f453cc15e6b801486115ef5693a499efcc3 Mon Sep 17 00:00:00 2001 From: Ivor Peles Date: Tue, 6 Oct 2020 04:07:10 -0400 Subject: [PATCH 07/12] Ignore executable check when executable is pipenv --- autoload/ale/fixers/isort.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/ale/fixers/isort.vim b/autoload/ale/fixers/isort.vim index 13825f7e..0ef166e5 100644 --- a/autoload/ale/fixers/isort.vim +++ b/autoload/ale/fixers/isort.vim @@ -24,7 +24,7 @@ function! ale#fixers#isort#Fix(buffer) abort \ ? ' run isort' \ : '' - if !executable(l:executable) + if !executable(l:executable) && l:executable != 'pipenv' return 0 endif From 340e9660556b87fafb4b9665115bbdcf831c9bc3 Mon Sep 17 00:00:00 2001 From: Ivor Peles Date: Wed, 25 Nov 2020 17:34:03 -0500 Subject: [PATCH 08/12] Fix comparison operator --- autoload/ale/fixers/isort.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/ale/fixers/isort.vim b/autoload/ale/fixers/isort.vim index 0ef166e5..1ae6f590 100644 --- a/autoload/ale/fixers/isort.vim +++ b/autoload/ale/fixers/isort.vim @@ -24,7 +24,7 @@ function! ale#fixers#isort#Fix(buffer) abort \ ? ' run isort' \ : '' - if !executable(l:executable) && l:executable != 'pipenv' + if !executable(l:executable) && l:executable !=# 'pipenv' return 0 endif From 713e53e3f64520b0501cb5d7b4c525946e6c7783 Mon Sep 17 00:00:00 2001 From: Ivor Peles Date: Wed, 25 Nov 2020 17:51:27 -0500 Subject: [PATCH 09/12] Ensure isort / pipenv test conforms to ALE coding standards --- test/fixers/test_isort_fixer_callback.vader | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixers/test_isort_fixer_callback.vader b/test/fixers/test_isort_fixer_callback.vader index 76c8a4cb..3941f6dd 100644 --- a/test/fixers/test_isort_fixer_callback.vader +++ b/test/fixers/test_isort_fixer_callback.vader @@ -56,5 +56,5 @@ Execute(Pipenv is detected when python_isort_auto_pipenv is set): call ale#test#SetFilename('/testplugin/test/python_fixtures/pipenv/whatever.py') AssertEqual - \ {'command': 'cd %s:h && ' . ale#Escape('pipenv') . ' run isort -'}, + \ {'command': ale#path#BufferCdString(bufnr('')) . ale#Escape('pipenv') . ' run isort -'}, \ ale#fixers#isort#Fix(bufnr('')) From ce3d891bed18f610beb9117518ef560871ef00a0 Mon Sep 17 00:00:00 2001 From: Ivor Peles Date: Wed, 25 Nov 2020 17:57:40 -0500 Subject: [PATCH 10/12] Use better string comparison operators in isort fixer --- autoload/ale/fixers/isort.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/ale/fixers/isort.vim b/autoload/ale/fixers/isort.vim index 1ae6f590..55bb550e 100644 --- a/autoload/ale/fixers/isort.vim +++ b/autoload/ale/fixers/isort.vim @@ -24,7 +24,7 @@ function! ale#fixers#isort#Fix(buffer) abort \ ? ' run isort' \ : '' - if !executable(l:executable) && l:executable !=# 'pipenv' + if !executable(l:executable) && l:executable isnot# 'pipenv' return 0 endif From e358afdd9ba5108680afc6aa017075b44f6c18fa Mon Sep 17 00:00:00 2001 From: Benjamin Binier Date: Thu, 17 Dec 2020 08:59:57 +0100 Subject: [PATCH 11/12] Add salt-lint support --- ale_linters/salt/salt_lint.vim | 32 +++++++++++++++++ doc/ale-salt.tmt | 43 +++++++++++++++++++++++ doc/ale-supported-languages-and-tools.txt | 2 ++ doc/ale.txt | 2 ++ supported-tools.md | 2 ++ test/handler/test_salt_salt_lint.vader | 34 ++++++++++++++++++ 6 files changed, 115 insertions(+) create mode 100644 ale_linters/salt/salt_lint.vim create mode 100644 doc/ale-salt.tmt create mode 100644 test/handler/test_salt_salt_lint.vader diff --git a/ale_linters/salt/salt_lint.vim b/ale_linters/salt/salt_lint.vim new file mode 100644 index 00000000..d2027119 --- /dev/null +++ b/ale_linters/salt/salt_lint.vim @@ -0,0 +1,32 @@ +" Author: Benjamin BINIER +" Description: salt-lint, saltstack linter + +call ale#Set('salt_salt_lint_executable', 'salt-lint') +call ale#Set('salt_salt_lint_options', '') + +function! ale_linters#salt#salt_lint#GetCommand(buffer) abort + return '%e' . ale#Pad(ale#Var(a:buffer, 'salt_salt_lint_options')) + \ . ' --json' +endfunction + +function! ale_linters#salt#salt_lint#Handle(buffer, lines) abort + let l:output = [] + + for l:error in ale#util#FuzzyJSONDecode(a:lines, []) + call add(l:output, { + \ 'lnum': l:error.linenumber + 0, + \ 'code': l:error.id + 0, + \ 'text': l:error.message, + \ 'type': l:error.severity is# 'HIGH' ? 'E' : 'W', + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('salt', { +\ 'name': 'salt-lint', +\ 'executable': {b -> ale#Var(b, 'salt_salt_lint_executable')}, +\ 'command': function('ale_linters#salt#salt_lint#GetCommand'), +\ 'callback': 'ale_linters#salt#salt_lint#Handle' +\}) diff --git a/doc/ale-salt.tmt b/doc/ale-salt.tmt new file mode 100644 index 00000000..ac500d37 --- /dev/null +++ b/doc/ale-salt.tmt @@ -0,0 +1,43 @@ +=============================================================================== +ALE SALT Integration *ale-salt-options* + +=============================================================================== +salt-lint *ale-salt-salt-lint* + +Website: https://github.com/warpnet/salt-lint + + +Installation +------------------------------------------------------------------------------- + +Install salt-lint in your a virtualenv directory, locally, or globally: > + + pip install salt-lint # After activating virtualenv + pip install --user salt-lint # Install to ~/.local/bin + sudo pip install salt-lint # Install globally + +See |g:ale_virtualenv_dir_names| for configuring how ALE searches for +virtualenv directories. + + +Options +------------------------------------------------------------------------------- + +g:ale_salt_salt-lint_executable *g:ale_salt_salt_lint_executable* + *b:ale_salt_salt_lint_executable* + Type: |String| + Default: `'salt-lint'` + + This variable can be set to change the path to salt-lint. + + +g:ale_salt_salt-lint_options *g:ale_salt_salt-lint_options* + *b:ale_salt_salt-lint_options* + Type: |String| + Default: `''` + + This variable can be set to pass additional options to salt-lint. + + +=============================================================================== + vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 36e27932..4844d0aa 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -428,6 +428,8 @@ Notes: * `rust-analyzer` * `rustc` (see |ale-integration-rust|) * `rustfmt` +* Salt + * `salt-lint` * Sass * `sass-lint` * `stylelint` diff --git a/doc/ale.txt b/doc/ale.txt index f9f40d12..d23e6fb6 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2882,6 +2882,8 @@ documented in additional help files. rls...................................|ale-rust-rls| rustc.................................|ale-rust-rustc| rustfmt...............................|ale-rust-rustfmt| + salt....................................|ale-salt-options| + salt-lint.............................|ale-salt-salt-lint| sass....................................|ale-sass-options| sasslint..............................|ale-sass-sasslint| stylelint.............................|ale-sass-stylelint| diff --git a/supported-tools.md b/supported-tools.md index 96ef273b..9d70b6b2 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -437,6 +437,8 @@ formatting. * [rust-analyzer](https://github.com/rust-analyzer/rust-analyzer) :warning: * [rustc](https://www.rust-lang.org/) :warning: * [rustfmt](https://github.com/rust-lang-nursery/rustfmt) +* Salt + * [salt-lint](https://github.com/warpnet/salt-lint) * Sass * [sass-lint](https://www.npmjs.com/package/sass-lint) * [stylelint](https://github.com/stylelint/stylelint) diff --git a/test/handler/test_salt_salt_lint.vader b/test/handler/test_salt_salt_lint.vader new file mode 100644 index 00000000..7e234785 --- /dev/null +++ b/test/handler/test_salt_salt_lint.vader @@ -0,0 +1,34 @@ +Before: + runtime ale_linters/salt/salt_lint.vim + +After: + call ale#linter#Reset() + +Execute(The salt handler should parse lines correctly and show error in severity HIGH): + AssertEqual + \ [ + \ { + \ 'lnum': 5, + \ 'code': 207, + \ 'text': 'File modes should always be encapsulated in quotation marks', + \ 'type': 'E' + \ } + \ ], + \ ale_linters#salt#salt_lint#Handle(255, [ + \ '[{"id": "207", "message": "File modes should always be encapsulated in quotation marks", "filename": "test.sls", "linenumber": 5, "line": " - mode: 0755", "severity": "HIGH"}]' + \ ]) + + +Execute(The salt handler should parse lines correctly and show error in severity not HIGH): + AssertEqual + \ [ + \ { + \ 'lnum': 27, + \ 'code': 204, + \ 'text': 'Lines should be no longer that 160 chars', + \ 'type': 'W' + \ } + \ ], + \ ale_linters#salt#salt_lint#Handle(255, [ + \ '[{"id": "204", "message": "Lines should be no longer that 160 chars", "filename": "test2.sls", "linenumber": 27, "line": "this line is definitely longer than 160 chars, this line is definitely longer than 160 chars, this line is definitely longer than 160 chars", "severity": "VERY_LOW"}]' + \ ]) From b4d889b682c2b55508f006ef8d1377a4ca3d9739 Mon Sep 17 00:00:00 2001 From: ttys3 Date: Mon, 4 Jan 2021 23:10:39 +0800 Subject: [PATCH 12/12] fix: proper initialization options call in php intelephense --- ale_linters/php/intelephense.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 ale_linters/php/intelephense.vim diff --git a/ale_linters/php/intelephense.vim b/ale_linters/php/intelephense.vim old mode 100644 new mode 100755 index e9e07d1f..aca619e3 --- a/ale_linters/php/intelephense.vim +++ b/ale_linters/php/intelephense.vim @@ -18,8 +18,8 @@ function! ale_linters#php#intelephense#GetProjectRoot(buffer) abort return !empty(l:git_path) ? fnamemodify(l:git_path, ':h:h') : '' endfunction -function! ale_linters#php#intelephense#GetInitializationOptions() abort - return ale#Get('php_intelephense_config') +function! ale_linters#php#intelephense#GetInitializationOptions(buffer) abort + return ale#Var(a:buffer, 'php_intelephense_config') endfunction call ale#linter#Define('php', {