From ff8d4c5286ff3d290b155a554289075afc653b8c Mon Sep 17 00:00:00 2001 From: Jonatan Olofsson Date: Mon, 1 Jan 2018 12:02:32 +0100 Subject: [PATCH 01/69] Fix #1255: Move extra clang-check args to before user options --- ale_linters/cpp/clangcheck.vim | 2 +- .../test_cpp_clangcheck_command_callbacks.vader | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ale_linters/cpp/clangcheck.vim b/ale_linters/cpp/clangcheck.vim index 4b6169c..a109d5d 100644 --- a/ale_linters/cpp/clangcheck.vim +++ b/ale_linters/cpp/clangcheck.vim @@ -24,9 +24,9 @@ function! ale_linters#cpp#clangcheck#GetCommand(buffer) abort " detected. return ale#Escape(ale_linters#cpp#clangcheck#GetExecutable(a:buffer)) \ . ' -analyze %s' + \ . (empty(l:build_dir) ? ' -extra-arg -Xclang -extra-arg -analyzer-output=text' : '') \ . (!empty(l:user_options) ? ' ' . l:user_options : '') \ . (!empty(l:build_dir) ? ' -p ' . ale#Escape(l:build_dir) : '') - \ . (empty(l:build_dir) ? ' -extra-arg -Xanalyzer -extra-arg -analyzer-output=text' : '') endfunction call ale#linter#Define('cpp', { diff --git a/test/command_callback/test_cpp_clangcheck_command_callbacks.vader b/test/command_callback/test_cpp_clangcheck_command_callbacks.vader index 34b87fc..9e9f7f6 100644 --- a/test/command_callback/test_cpp_clangcheck_command_callbacks.vader +++ b/test/command_callback/test_cpp_clangcheck_command_callbacks.vader @@ -28,7 +28,7 @@ Execute(The executable should be used in the command): AssertEqual \ ale#Escape('clang-check') \ . ' -analyze %s' - \ . ' -extra-arg -Xanalyzer -extra-arg -analyzer-output=text', + \ . ' -extra-arg -Xclang -extra-arg -analyzer-output=text', \ ale_linters#cpp#clangcheck#GetCommand(bufnr('')) let b:ale_cpp_clangcheck_executable = 'foobar' @@ -38,7 +38,7 @@ Execute(The executable should be used in the command): AssertEqual \ ale#Escape('foobar') \ . ' -analyze %s' - \ . ' -extra-arg -Xanalyzer -extra-arg -analyzer-output=text', + \ . ' -extra-arg -Xclang -extra-arg -analyzer-output=text', \ ale_linters#cpp#clangcheck#GetCommand(bufnr('')) Execute(The options should be configurable): @@ -46,8 +46,9 @@ Execute(The options should be configurable): AssertEqual \ ale#Escape('clang-check') - \ . ' -analyze %s --something' - \ . ' -extra-arg -Xanalyzer -extra-arg -analyzer-output=text', + \ . ' -analyze %s' + \ . ' -extra-arg -Xclang -extra-arg -analyzer-output=text', + \ . ' --something' \ ale_linters#cpp#clangcheck#GetCommand(bufnr('')) Execute(The build directory should be used when set): From eecbacb742f0e884e2f47f0aee57caf9cb2dd683 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Sun, 7 Jan 2018 17:53:01 +0100 Subject: [PATCH 02/69] Removed unneeded `SetDirectory` call in proto handler test. The test already handled arbitrary paths reasonably well, but setting the directory interfered via leakage with others tests for some reason. This patch removes the call to `SetDirectory` in the fixture setup and the subsequent cleanup in the teardown as they are not required. --- test/command_callback/test_proto_command_callback.vader | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/command_callback/test_proto_command_callback.vader b/test/command_callback/test_proto_command_callback.vader index 2fd7775..79c1cf8 100644 --- a/test/command_callback/test_proto_command_callback.vader +++ b/test/command_callback/test_proto_command_callback.vader @@ -1,11 +1,9 @@ Before: - call ale#test#SetDirectory('/testplugin/test/command_callback') call ale#test#SetFilename('test.proto') After: Restore - call ale#test#RestoreDirectory() call ale#linter#Reset() Execute(The default command should be correct): From b5a5cdf920a9875650b021c8116ac02b739a9e9e Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Sat, 6 Jan 2018 20:56:28 +0100 Subject: [PATCH 03/69] Make it possible to inject flags of protoc invocation. Typically proto files depend on and make use of proto definitions in other files. When invoking protoc user can supply paths to inspect for dependencies. This patch makes it possible to configure flags passed to protoc. This makes it e.g., possible to change include paths of the linter's protoc invocation. --- ale_linters/proto/protoc_gen_lint.vim | 14 +++++++++++--- doc/ale-proto.txt | 9 +++++++++ .../test_proto_command_callback.vader | 9 +++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ale_linters/proto/protoc_gen_lint.vim b/ale_linters/proto/protoc_gen_lint.vim index 9d5ceac..c8b5c33 100644 --- a/ale_linters/proto/protoc_gen_lint.vim +++ b/ale_linters/proto/protoc_gen_lint.vim @@ -1,12 +1,20 @@ " Author: Jeff Willette " Description: run the protoc-gen-lint plugin for the protoc binary +call ale#Set('proto_protoc_gen_lint_options', '') + function! ale_linters#proto#protoc_gen_lint#GetCommand(buffer) abort let l:dirname = expand('#' . a:buffer . ':p:h') - return 'protoc' - \ . ' -I ' . ale#Escape(l:dirname) - \ . ' --lint_out=. ' . '%s' + let l:options = ['-I ' . ale#Escape(l:dirname)] + + if !empty(ale#Var(a:buffer, 'proto_protoc_gen_lint_options')) + let l:options += [ale#Var(a:buffer, 'proto_protoc_gen_lint_options')] + endif + + let l:options += ['--lint_out=. ' . '%s'] + + return 'protoc' . ' ' . join(l:options) endfunction call ale#linter#Define('proto', { diff --git a/doc/ale-proto.txt b/doc/ale-proto.txt index 6a25638..734e23d 100644 --- a/doc/ale-proto.txt +++ b/doc/ale-proto.txt @@ -20,5 +20,14 @@ protoc-gen-lint *ale-proto-protoc-gen-lint* The linter is a plugin for the `protoc` binary. As long as the binary resides in the system path, `protoc` will find it. +g:ale_proto_protoc_gen_lint_options *g:ale_proto_protoc_gen_lint_options* + + Type: |String| + Default: `''` + + This variable can be changed to modify flags given to protoc. Note that the + directory of the linted file is always passed as an include path with '-I' + before any user-supplied options. + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/test/command_callback/test_proto_command_callback.vader b/test/command_callback/test_proto_command_callback.vader index 79c1cf8..76050c6 100644 --- a/test/command_callback/test_proto_command_callback.vader +++ b/test/command_callback/test_proto_command_callback.vader @@ -4,9 +4,18 @@ Before: After: Restore + unlet! b:ale_proto_protoc_gen_lint_options + call ale#linter#Reset() Execute(The default command should be correct): AssertEqual \ 'protoc' . ' -I ' . ale#Escape(getcwd()) . ' --lint_out=. ' . '%s', \ ale_linters#proto#protoc_gen_lint#GetCommand(bufnr('')) + +Execute(The callback should include any additional options): + let b:ale_proto_protoc_gen_lint_options = '--some-option' + + AssertEqual + \ 'protoc' . ' -I ' . ale#Escape(getcwd()) . ' --some-option --lint_out=. ' . '%s', + \ ale_linters#proto#protoc_gen_lint#GetCommand(bufnr('')) From ff388bbcd5374bb76507c2b6af1e1167c8189ea4 Mon Sep 17 00:00:00 2001 From: Kevin Tindall Date: Sun, 7 Jan 2018 11:41:06 -0600 Subject: [PATCH 04/69] test for ghc options --- .../test_haskell_ghc_command_callbacks.vader | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/command_callback/test_haskell_ghc_command_callbacks.vader diff --git a/test/command_callback/test_haskell_ghc_command_callbacks.vader b/test/command_callback/test_haskell_ghc_command_callbacks.vader new file mode 100644 index 0000000..edaf2b9 --- /dev/null +++ b/test/command_callback/test_haskell_ghc_command_callbacks.vader @@ -0,0 +1,23 @@ +Before: + Save g:ale_haskell_ghc_options + + unlet! g:ale_haskell_ghc_options + unlet! b:ale_haskell_ghc_options + + runtime ale_linters/haskell/ghc.vim + +After: + Restore + unlet! b:ale_haskell_ghc_options + call ale#linter#Reset() + +Execute(The options should be used in the command): + AssertEqual + \ 'ghc -fno-code -v0 %t', + \ ale_linters#haskell#ghc#GetCommand(bufnr('')) + + let b:ale_haskell_ghc_options = 'foobar' + + AssertEqual + \ 'ghc foobar %t', + \ ale_linters#haskell#ghc#GetCommand(bufnr('')) From 68d4a2216ca8edb7396f88352cfe807fa771ca7e Mon Sep 17 00:00:00 2001 From: w0rp Date: Mon, 8 Jan 2018 13:28:01 +0000 Subject: [PATCH 05/69] Fix a syntax error in a test --- .../test_cpp_clangcheck_command_callbacks.vader | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/command_callback/test_cpp_clangcheck_command_callbacks.vader b/test/command_callback/test_cpp_clangcheck_command_callbacks.vader index 9e9f7f6..f708c52 100644 --- a/test/command_callback/test_cpp_clangcheck_command_callbacks.vader +++ b/test/command_callback/test_cpp_clangcheck_command_callbacks.vader @@ -47,8 +47,8 @@ Execute(The options should be configurable): AssertEqual \ ale#Escape('clang-check') \ . ' -analyze %s' - \ . ' -extra-arg -Xclang -extra-arg -analyzer-output=text', - \ . ' --something' + \ . ' -extra-arg -Xclang -extra-arg -analyzer-output=text' + \ . ' --something', \ ale_linters#cpp#clangcheck#GetCommand(bufnr('')) Execute(The build directory should be used when set): From 112fcf7dd57a077f70ae39bb03d192f5c832aa2e Mon Sep 17 00:00:00 2001 From: "jiangzhi.xie" Date: Mon, 8 Jan 2018 23:19:17 +0800 Subject: [PATCH 06/69] Add a luac linter for Lua --- README.md | 2 +- ale_linters/lua/luac.vim | 40 +++++++++++++++++++ doc/ale-lua.txt | 9 +++++ doc/ale.txt | 3 +- .../test_luac_command_callback.vader | 16 ++++++++ test/handler/test_luac_handler.vader | 36 +++++++++++++++++ ...dler.vader => test_luacheck_handler.vader} | 0 7 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 ale_linters/lua/luac.vim create mode 100644 test/command_callback/test_luac_command_callback.vader create mode 100644 test/handler/test_luac_handler.vader rename test/handler/{test_lua_handler.vader => test_luacheck_handler.vader} (100%) diff --git a/README.md b/README.md index 55be933..c393e49 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ formatting. | LaTeX | [alex](https://github.com/wooorm/alex) !!, [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck), [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [vale](https://github.com/ValeLint/vale), [write-good](https://github.com/btford/write-good) | | Less | [lessc](https://www.npmjs.com/package/less), [prettier](https://github.com/prettier/prettier), [stylelint](https://github.com/stylelint/stylelint) | | LLVM | [llc](https://llvm.org/docs/CommandGuide/llc.html) | -| Lua | [luacheck](https://github.com/mpeterv/luacheck) | +| Lua | [luac](https://www.lua.org/manual/5.1/luac.html), [luacheck](https://github.com/mpeterv/luacheck) | | Mail | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale) | | Make | [checkmake](https://github.com/mrtazz/checkmake) | | Markdown | [alex](https://github.com/wooorm/alex) !!, [mdl](https://github.com/mivok/markdownlint), [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [remark-lint](https://github.com/wooorm/remark-lint) !!, [vale](https://github.com/ValeLint/vale), [write-good](https://github.com/btford/write-good) | diff --git a/ale_linters/lua/luac.vim b/ale_linters/lua/luac.vim new file mode 100644 index 0000000..4a6bb40 --- /dev/null +++ b/ale_linters/lua/luac.vim @@ -0,0 +1,40 @@ +" Author: Jon Xie https://github.com/xiejiangzhi +" Description: luac linter for lua files + +call ale#Set('lua_luac_executable', 'luac') + +function! ale_linters#lua#luac#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'lua_luac_executable') +endfunction + +function! ale_linters#lua#luac#GetCommand(buffer) abort + let l:executable = ale_linters#lua#luac#GetExecutable(a:buffer) + return ale#Escape(l:executable) . ' -p - ' +endfunction + +function! ale_linters#lua#luac#Handle(buffer, lines) abort + " Matches patterns line the following: + " + " luac: stdin:5: '=' expected near ')' + " luac: stdin:8: ')' expected (to close '(' at line 6) near '123' + let l:pattern = '\v^.*:(\d+): (.+)$' + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + call add(l:output, { + \ 'lnum': l:match[1] + 0, + \ 'type': 'E', + \ 'text': l:match[2], + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('lua', { +\ 'name': 'luac', +\ 'executable_callback': 'ale_linters#lua#luac#GetExecutable', +\ 'command_callback': 'ale_linters#lua#luac#GetCommand', +\ 'output_stream': 'stderr', +\ 'callback': 'ale_linters#lua#luac#Handle', +\}) diff --git a/doc/ale-lua.txt b/doc/ale-lua.txt index 74d6b94..b6fab37 100644 --- a/doc/ale-lua.txt +++ b/doc/ale-lua.txt @@ -1,6 +1,15 @@ =============================================================================== ALE Lua Integration *ale-lua-options* +=============================================================================== +luac *ale-lua-luac* + +g:ale_lua_luac_executable *g:ale_lua_luac_executable* + *b:ale_lua_luac_executable* + Type: |String| + Default: `'luac'` + + This variable can be changed to change the path to luac. =============================================================================== luacheck *ale-lua-luacheck* diff --git a/doc/ale.txt b/doc/ale.txt index 25c1abe..6cebbce 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -125,6 +125,7 @@ CONTENTS *ale-contents* llvm..................................|ale-llvm-options| llc.................................|ale-llvm-llc| lua...................................|ale-lua-options| + luac................................|ale-lua-luac| luacheck............................|ale-lua-luacheck| markdown..............................|ale-markdown-options| write-good..........................|ale-markdown-write-good| @@ -323,7 +324,7 @@ Notes: * LaTeX (tex): `alex`!!, `chktex`, `lacheck`, `proselint`, `redpen`, `vale`, `write-good` * Less: `lessc`, `prettier`, `stylelint` * LLVM: `llc` -* Lua: `luacheck` +* Lua: `luac`, `luacheck` * Mail: `alex`!!, `proselint`, `vale` * Make: `checkmake` * Markdown: `alex`!!, `mdl`, `proselint`, `redpen`, `remark-lint`, `vale`, `write-good` diff --git a/test/command_callback/test_luac_command_callback.vader b/test/command_callback/test_luac_command_callback.vader new file mode 100644 index 0000000..f9eb4d3 --- /dev/null +++ b/test/command_callback/test_luac_command_callback.vader @@ -0,0 +1,16 @@ +Before: + runtime ale_linters/lua/luac.vim + +After: + call ale#linter#Reset() + +Execute(The default command should be correct): + AssertEqual ale#Escape('luac') . ' -p -', + \ join(split(ale_linters#lua#luac#GetCommand(1))) + +Execute(The luac executable should be configurable): + let g:ale_lua_luac_executable = 'luac.sh' + + AssertEqual 'luac.sh', ale_linters#lua#luac#GetExecutable(1) + AssertEqual ale#Escape('luac.sh') . ' -p -', + \ join(split(ale_linters#lua#luac#GetCommand(1))) diff --git a/test/handler/test_luac_handler.vader b/test/handler/test_luac_handler.vader new file mode 100644 index 0000000..3a2e769 --- /dev/null +++ b/test/handler/test_luac_handler.vader @@ -0,0 +1,36 @@ +Before: + Save g:ale_warn_about_trailing_whitespace + + let g:ale_warn_about_trailing_whitespace = 1 + + runtime ale_linters/lua/luac.vim + +After: + Restore + call ale#linter#Reset() + +Execute(The luac handler should parse lines correctly): + AssertEqual + \ [ + \ { + \ 'lnum': 1, + \ 'text': 'line contains trailing whitespace', + \ 'type': 'E', + \ }, + \ { + \ 'lnum': 3, + \ 'text': 'unexpected symbol near ''-''', + \ 'type': 'E', + \ }, + \ { + \ 'lnum': 5, + \ 'text': '''='' expected near '')''', + \ 'type': 'E', + \ }, + \ ], + \ ale_linters#lua#luac#Handle(347, [ + \ 'luac /file/path/here.lua:1: line contains trailing whitespace', + \ 'luac /file/path/here.lua:3: unexpected symbol near ''-''', + \ 'luac /file/path/here.lua:5: ''='' expected near '')''', + \ ]) + diff --git a/test/handler/test_lua_handler.vader b/test/handler/test_luacheck_handler.vader similarity index 100% rename from test/handler/test_lua_handler.vader rename to test/handler/test_luacheck_handler.vader From 547716eabb3a436f2de623555fb488d3496ccbd4 Mon Sep 17 00:00:00 2001 From: "jiangzhi.xie" Date: Mon, 8 Jan 2018 23:39:04 +0800 Subject: [PATCH 07/69] Fix the doc style for ale-lua --- doc/ale-lua.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/ale-lua.txt b/doc/ale-lua.txt index b6fab37..f1286f8 100644 --- a/doc/ale-lua.txt +++ b/doc/ale-lua.txt @@ -2,10 +2,10 @@ ALE Lua Integration *ale-lua-options* =============================================================================== -luac *ale-lua-luac* +luac *ale-lua-luac* -g:ale_lua_luac_executable *g:ale_lua_luac_executable* - *b:ale_lua_luac_executable* +g:ale_lua_luac_executable *g:ale_lua_luac_executable* + *b:ale_lua_luac_executable* Type: |String| Default: `'luac'` From 29acafdaf4f59861aeff64c5f56a584e40260c5e Mon Sep 17 00:00:00 2001 From: sharils Date: Tue, 26 Dec 2017 22:13:05 +0800 Subject: [PATCH 08/69] Work around hot-reloading issue See https://github.com/phoenixframework/phoenix/issues/1165 for more detail --- ale_linters/elixir/credo.vim | 2 +- ale_linters/elixir/dogma.vim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ale_linters/elixir/credo.vim b/ale_linters/elixir/credo.vim index 3699dd2..af2ff48 100644 --- a/ale_linters/elixir/credo.vim +++ b/ale_linters/elixir/credo.vim @@ -32,6 +32,6 @@ endfunction call ale#linter#Define('elixir', { \ 'name': 'credo', \ 'executable': 'mix', -\ 'command': 'mix credo suggest --format=flycheck --read-from-stdin %s', +\ 'command': 'mix help credo && mix credo suggest --format=flycheck --read-from-stdin %s', \ 'callback': 'ale_linters#elixir#credo#Handle', \}) diff --git a/ale_linters/elixir/dogma.vim b/ale_linters/elixir/dogma.vim index b4f32b0..71cf4f4 100644 --- a/ale_linters/elixir/dogma.vim +++ b/ale_linters/elixir/dogma.vim @@ -32,7 +32,7 @@ endfunction call ale#linter#Define('elixir', { \ 'name': 'dogma', \ 'executable': 'mix', -\ 'command': 'mix dogma %s --format=flycheck', +\ 'command': 'mix help dogma && mix dogma %s --format=flycheck', \ 'lint_file': 1, \ 'callback': 'ale_linters#elixir#dogma#Handle', \}) From 2ef45ab7457566a10354b7833cbdf5137118cebf Mon Sep 17 00:00:00 2001 From: Ivan Petkov Date: Tue, 9 Jan 2018 19:18:18 -0800 Subject: [PATCH 09/69] Teach ALE about cargo features and add some configuration options * When working on rust/cargo projects of varying sizes, it may be useful to either build all possible features (i.e. lint all possible conditionally compiled code), or even turn off other features for a quicker edit-lint cycle (e.g. for large projects with large build times) * Added a g:ale_rust_cargo_default_feature_behavior flag for instructing cargo to not build any features at all (via `--no-default-features`), building default features (via no extra flags), or building all possible features (via `--all-features`) * Also added a g:ale_rust_cargo_include_features flag for including arbitrary features to be checked by cargo. When coupled with g:ale_rust_cargo_default_feature_behavior this allows for full customization of what features are checked and which ones are ignored --- ale_linters/rust/cargo.vim | 22 ++++++++- doc/ale-rust.txt | 30 ++++++++++++ .../test_cargo_command_callbacks.vader | 48 +++++++++++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) diff --git a/ale_linters/rust/cargo.vim b/ale_linters/rust/cargo.vim index a0e123a..09f41bb 100644 --- a/ale_linters/rust/cargo.vim +++ b/ale_linters/rust/cargo.vim @@ -1,8 +1,11 @@ -" Author: Daniel Schemala +" Author: Daniel Schemala , +" Ivan Petkov " Description: rustc invoked by cargo for rust files call ale#Set('rust_cargo_use_check', 1) call ale#Set('rust_cargo_check_all_targets', 0) +call ale#Set('rust_cargo_default_feature_behavior', 'default') +call ale#Set('rust_cargo_include_features', '') function! ale_linters#rust#cargo#GetCargoExecutable(bufnr) abort if ale#path#FindNearestFile(a:bufnr, 'Cargo.toml') isnot# '' @@ -29,10 +32,27 @@ function! ale_linters#rust#cargo#GetCommand(buffer, version_output) abort \ && ale#Var(a:buffer, 'rust_cargo_check_all_targets') \ && ale#semver#GTE(l:version, [0, 22, 0]) + let l:include_features = ale#Var(a:buffer, 'rust_cargo_include_features') + if !empty(l:include_features) + let l:include_features = ' --features ' . ale#Escape(l:include_features) + endif + + let l:default_feature_behavior = ale#Var(a:buffer, 'rust_cargo_default_feature_behavior') + if l:default_feature_behavior is# 'all' + let l:include_features = '' + let l:default_feature = ' --all-features' + elseif l:default_feature_behavior is# 'none' + let l:default_feature = ' --no-default-features' + else + let l:default_feature = '' + endif + return 'cargo ' \ . (l:use_check ? 'check' : 'build') \ . (l:use_all_targets ? ' --all-targets' : '') \ . ' --frozen --message-format=json -q' + \ . l:default_feature + \ . l:include_features endfunction call ale#linter#Define('rust', { diff --git a/doc/ale-rust.txt b/doc/ale-rust.txt index 535f21d..dad9ae6 100644 --- a/doc/ale-rust.txt +++ b/doc/ale-rust.txt @@ -59,6 +59,36 @@ g:ale_rust_cargo_check_all_targets *g:ale_rust_cargo_check_all_targets* is used. See |g:ale_rust_cargo_use_check|, +g:ale_rust_cargo_default_feature_behavior + *g:ale_rust_cargo_default_feature_behavior* + *b:ale_rust_cargo_default_feature_behavior* + Type: |String| + Default: `default` + + When set to `none`, ALE will set the `--no-default-features` option when + invoking `cargo`. Only the features specified in + |g:ale_rust_cargo_include_features| will be included when performing the + lint check. + + When set to `default`, ALE will instruct `cargo` to build all default + features specified in the project's `Cargo.toml` file, in addition to + including any additional features defined in + |g:ale_rust_cargo_include_features|. + + When set to `all`, ALE will set the `--all-features` option when + invoking `cargo`, which will include all features defined in the project's + `Cargo.toml` file when performing the lint check. + + +g:ale_rust_cargo_include_features *g:ale_rust_cargo_include_features* + *b:ale_rust_cargo_include_features* + Type: |String| + Default: `''` + + When defined, ALE will set the `--features` option when invoking `cargo` to + perform the lint check. See |g:ale_rust_cargo_default_feature_behavior|. + + =============================================================================== rls *ale-rust-rls* diff --git a/test/command_callback/test_cargo_command_callbacks.vader b/test/command_callback/test_cargo_command_callbacks.vader index 65ea5a8..9c06f27 100644 --- a/test/command_callback/test_cargo_command_callbacks.vader +++ b/test/command_callback/test_cargo_command_callbacks.vader @@ -1,9 +1,13 @@ Before: Save g:ale_rust_cargo_use_check Save g:ale_rust_cargo_check_all_targets + Save g:ale_rust_cargo_default_feature_behavior + Save g:ale_rust_cargo_include_features unlet! g:ale_rust_cargo_use_check unlet! g:ale_cargo_check_all_targets + unlet! g:ale_rust_cargo_default_feature_behavior + unlet! g:ale_rust_cargo_include_features runtime ale_linters/rust/cargo.vim call ale#test#SetDirectory('/testplugin/test/command_callback') @@ -114,3 +118,47 @@ Execute(--all-targets should be used when g:ale_rust_cargo_check_all_targets is \ ale_linters#rust#cargo#GetCommand(bufnr(''), []) AssertEqual '', ale_linters#rust#cargo#VersionCheck(bufnr('')) + +Execute(--no-default-features should be used when g:ale_rust_cargo_default_feature_behavior is none): + let g:ale_rust_cargo_default_feature_behavior = 'none' + + AssertEqual + \ 'cargo check' . g:suffix . ' --no-default-features', + \ ale_linters#rust#cargo#GetCommand(bufnr(''), [ + \ 'cargo 0.22.0 (3423351a5 2017-10-06)', + \ ]) + +Execute(g:ale_rust_cargo_include_features added when g:ale_rust_cargo_default_feature_behavior is none): + let g:ale_rust_cargo_default_feature_behavior = 'none' + let g:ale_rust_cargo_include_features = 'foo bar' + + AssertEqual + \ 'cargo check' . g:suffix . ' --no-default-features --features ' . + \ (fnamemodify(&shell, ':t') is? 'cmd.exe' ? '"foo bar"' : "'foo bar'"), + \ ale_linters#rust#cargo#GetCommand(bufnr(''), [ + \ 'cargo 0.22.0 (3423351a5 2017-10-06)', + \ ]) + +Execute(g:ale_rust_cargo_include_features added and escaped): + let g:ale_rust_cargo_default_feature_behavior = 'default' + let g:ale_rust_cargo_include_features = "foo bar baz" + + AssertEqual + \ 'cargo check' . g:suffix . ' --features ' . + \ (fnamemodify(&shell, ':t') is? 'cmd.exe' ? '"foo bar baz"' : "'foo bar baz'"), + \ ale_linters#rust#cargo#GetCommand(bufnr(''), [ + \ 'cargo 0.22.0 (3423351a5 2017-10-06)', + \ ]) + +Execute(--all-features should be used when g:ale_rust_cargo_default_feature_behavior is all): + let g:ale_rust_cargo_default_feature_behavior = 'all' + + " When all features are enabled we should ignore extra features to add + " since it won't do anything + let g:ale_rust_cargo_include_features = 'foo bar' + + AssertEqual + \ 'cargo check' . g:suffix . ' --all-features', + \ ale_linters#rust#cargo#GetCommand(bufnr(''), [ + \ 'cargo 0.22.0 (3423351a5 2017-10-06)', + \ ]) From ba1540a5452fe4523ed91b99f1469f4e86112a6b Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 12 Jan 2018 08:55:24 +0000 Subject: [PATCH 10/69] Show only the master status for AppVeyor --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 55be933..451d485 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Asynchronous Lint Engine [![Travis CI Build Status](https://travis-ci.org/w0rp/ale.svg?branch=master)](https://travis-ci.org/w0rp/ale) [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/w0rp/ale?svg=true)](https://ci.appveyor.com/project/w0rp/ale) +# Asynchronous Lint Engine [![Travis CI Build Status](https://travis-ci.org/w0rp/ale.svg?branch=master)](https://travis-ci.org/w0rp/ale) [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/r0ef1xu8xjmik58d/branch/master?svg=true)](https://ci.appveyor.com/project/w0rp/ale) ![ALE Logo by Mark Grealish - https://www.bhalash.com/](img/logo.jpg?raw=true) From 13c839cf16e6dfb8deab30666748b7ae6c8f9aa0 Mon Sep 17 00:00:00 2001 From: rhysd Date: Mon, 15 Jan 2018 11:22:09 +0900 Subject: [PATCH 11/69] Enable prettier to format markdown files --- README.md | 2 +- autoload/ale/fix/registry.vim | 2 +- doc/ale-markdown.txt | 6 ++++++ doc/ale.txt | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 451d485..5ee74db 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ formatting. | Lua | [luacheck](https://github.com/mpeterv/luacheck) | | Mail | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale) | | Make | [checkmake](https://github.com/mrtazz/checkmake) | -| Markdown | [alex](https://github.com/wooorm/alex) !!, [mdl](https://github.com/mivok/markdownlint), [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [remark-lint](https://github.com/wooorm/remark-lint) !!, [vale](https://github.com/ValeLint/vale), [write-good](https://github.com/btford/write-good) | +| Markdown | [alex](https://github.com/wooorm/alex) !!, [mdl](https://github.com/mivok/markdownlint), [prettier](https://github.com/prettier/prettier), [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [remark-lint](https://github.com/wooorm/remark-lint) !!, [vale](https://github.com/ValeLint/vale), [write-good](https://github.com/btford/write-good) | | MATLAB | [mlint](https://www.mathworks.com/help/matlab/ref/mlint.html) | | Nim | [nim check](https://nim-lang.org/docs/nimc.html) !! | | nix | [nix-instantiate](http://nixos.org/nix/manual/#sec-nix-instantiate) | diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 53df7cc..4b69240 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -45,7 +45,7 @@ let s:default_registry = { \ }, \ 'prettier': { \ 'function': 'ale#fixers#prettier#Fix', -\ 'suggested_filetypes': ['javascript', 'typescript', 'json', 'css', 'scss', 'less'], +\ 'suggested_filetypes': ['javascript', 'typescript', 'json', 'css', 'scss', 'less', 'markdown'], \ 'description': 'Apply prettier to a file.', \ }, \ 'prettier_eslint': { diff --git a/doc/ale-markdown.txt b/doc/ale-markdown.txt index 3ce9619..b59f018 100644 --- a/doc/ale-markdown.txt +++ b/doc/ale-markdown.txt @@ -2,6 +2,12 @@ ALE Markdown Integration *ale-markdown-options* +=============================================================================== +prettier *ale-markdown-prettier* + +See |ale-javascript-prettier| for information about the available options. + + =============================================================================== write-good *ale-markdown-write-good* diff --git a/doc/ale.txt b/doc/ale.txt index 25c1abe..61d6eee 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -127,6 +127,7 @@ CONTENTS *ale-contents* lua...................................|ale-lua-options| luacheck............................|ale-lua-luacheck| markdown..............................|ale-markdown-options| + prettier............................|ale-markdown-prettier| write-good..........................|ale-markdown-write-good| nroff.................................|ale-nroff-options| write-good..........................|ale-nroff-write-good| @@ -326,7 +327,7 @@ Notes: * Lua: `luacheck` * Mail: `alex`!!, `proselint`, `vale` * Make: `checkmake` -* Markdown: `alex`!!, `mdl`, `proselint`, `redpen`, `remark-lint`, `vale`, `write-good` +* Markdown: `alex`!!, `mdl`, `prettier`, `proselint`, `redpen`, `remark-lint`, `vale`, `write-good` * MATLAB: `mlint` * Nim: `nim check`!! * nix: `nix-instantiate` From aa29c91cdc9c5dc737e93c1f91080aa174363bef Mon Sep 17 00:00:00 2001 From: Eddie Lebow Date: Sun, 12 Nov 2017 00:53:02 -0500 Subject: [PATCH 12/69] [eruby] Add erubi linter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Erubi is yet another parser for eRuby. This is the default parser in Rails as of version 5.1. It supports some additional syntax with similar behavior to Rails' extensions to the language, though incompatible. Rails currently still recommends their own syntax, so GetCommand still has to do the translation introduced in https://github.com/w0rp/ale/pull/1114 . Erubi does not supply an executable—It is intended to be invoked only from within a Ruby program. In this case, a one-liner on the command line. --- README.md | 2 +- ale_linters/eruby/erubi.vim | 35 +++++++++++++++++++ doc/ale-eruby.txt | 12 +++---- doc/ale.txt | 2 +- .../test_erubi_command_callback.vader | 31 ++++++++++++++++ 5 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 ale_linters/eruby/erubi.vim create mode 100644 test/command_callback/test_erubi_command_callback.vader diff --git a/README.md b/README.md index 7382789..598c3cb 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ formatting. | Dockerfile | [hadolint](https://github.com/lukasmartinelli/hadolint) | | Elixir | [credo](https://github.com/rrrene/credo), [dogma](https://github.com/lpil/dogma) !! | | Elm | [elm-format](https://github.com/avh4/elm-format), [elm-make](https://github.com/elm-lang/elm-make) | -| Erb | [erb](https://github.com/jeremyevans/erubi), [erubis](https://github.com/kwatch/erubis) | +| Erb | [erb](https://apidock.com/ruby/ERB), [erubi](https://github.com/jeremyevans/erubi), [erubis](https://github.com/kwatch/erubis) | | Erlang | [erlc](http://erlang.org/doc/man/erlc.html), [SyntaxErl](https://github.com/ten0s/syntaxerl) | | Fortran | [gcc](https://gcc.gnu.org/) | | FusionScript | [fusion-lint](https://github.com/RyanSquared/fusionscript) | diff --git a/ale_linters/eruby/erubi.vim b/ale_linters/eruby/erubi.vim new file mode 100644 index 0000000..6f2d3ac --- /dev/null +++ b/ale_linters/eruby/erubi.vim @@ -0,0 +1,35 @@ +" Author: Eddie Lebow https://github.com/elebow +" Description: eruby checker using `erubi` + +function! ale_linters#eruby#erubi#CheckErubi(buffer) abort + return 'ruby -r erubi/capture_end -e ' . ale#Escape('""') +endfunction + +function! ale_linters#eruby#erubi#GetCommand(buffer, check_erubi_output) abort + let l:rails_root = ale#ruby#FindRailsRoot(a:buffer) + + if (!empty(a:check_erubi_output)) + " The empty command in CheckErubi returns nothing if erubi runs and + " emits an error if erubi is not present + return '' + endif + + if empty(l:rails_root) + return 'ruby -r erubi/capture_end -e ' . ale#Escape('puts Erubi::CaptureEndEngine.new($stdin.read).src') . '< %t | ruby -c' + endif + + " Rails-flavored eRuby does not comply with the standard as understood by + " Erubi, so we'll have to do some substitution. This does not reduce the + " effectiveness of the linter---the translated code is still evaluated. + return 'ruby -r erubi/capture_end -e ' . ale#Escape('puts Erubi::CaptureEndEngine.new($stdin.read.gsub(%{<%=},%{<%}), nil, %{-}).src') . '< %t | ruby -c' +endfunction + +call ale#linter#Define('eruby', { +\ 'name': 'erubi', +\ 'executable': 'ruby', +\ 'command_chain': [ +\ {'callback': 'ale_linters#eruby#erubi#CheckErubi'}, +\ {'callback': 'ale_linters#eruby#erubi#GetCommand', 'output_stream': 'stderr'}, +\ ], +\ 'callback': 'ale#handlers#ruby#HandleSyntaxErrors', +\}) diff --git a/doc/ale-eruby.txt b/doc/ale-eruby.txt index bfbe9ad..a0f6f4f 100644 --- a/doc/ale-eruby.txt +++ b/doc/ale-eruby.txt @@ -1,17 +1,15 @@ =============================================================================== ALE Eruby Integration *ale-eruby-options* -There are two linters for `eruby` files: +There are three linters for `eruby` files: - `erb` - `erubis` +- `erubi` -If you don't know which one your project uses, it's probably `erb`. -To selectively enable one or the other, see |g:ale_linters|. - -(Note that ALE already disables linters if the executable for that linter is -not found; thus, there's probably no need to disable one of these if you're -using the other one.) +`erb` is in the Ruby standard library and is mostly universal. `erubis` is the +default parser in Rails between 3.0 and 5.1. `erubi` is the default in Rails +5.1 and later. To selectively enable a subset, see |g:ale_linters|. =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index 6399111..be57768 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -286,7 +286,7 @@ Notes: * Dockerfile: `hadolint` * Elixir: `credo`, `dogma`!! * Elm: `elm-format, elm-make` -* Erb: `erb`, `erubis` +* Erb: `erb`, `erubi`, `erubis` * Erlang: `erlc`, `SyntaxErl` * Fortran: `gcc` * FusionScript: `fusion-lint` diff --git a/test/command_callback/test_erubi_command_callback.vader b/test/command_callback/test_erubi_command_callback.vader new file mode 100644 index 0000000..1953d76 --- /dev/null +++ b/test/command_callback/test_erubi_command_callback.vader @@ -0,0 +1,31 @@ +Before: + runtime ale_linters/eruby/erubi.vim + call ale#test#SetDirectory('/testplugin/test/command_callback') + +After: + call ale#linter#Reset() + call ale#test#RestoreDirectory() + +Execute(Executable should not contain any filter code by default): + call ale#test#SetFilename('../ruby_fixtures/not_a_rails_app/file.rb') + + AssertEqual + \ 'ruby -r erubi/capture_end -e ' . ale#Escape('puts Erubi::CaptureEndEngine.new($stdin.read).src') . '< %t | ruby -c', + \ ale_linters#eruby#erubi#GetCommand(bufnr(''), []) + +Execute(Executable should filter invalid eRuby when inside a Rails project): + call ale#test#SetFilename('../ruby_fixtures/valid_rails_app/app/views/my_great_view.html.erb') + + AssertEqual + \ 'ruby -r erubi/capture_end -e ' . ale#Escape('puts Erubi::CaptureEndEngine.new($stdin.read.gsub(%{<%=},%{<%}), nil, %{-}).src') . '< %t | ruby -c', + \ ale_linters#eruby#erubi#GetCommand(bufnr(''), []) + +Execute(Command should be blank if the first command in the chain return output): + let output_lines = [ + \ "/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- erubi/capture_end (LoadError)", + \ " from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'", + \] + + AssertEqual + \ '', + \ ale_linters#eruby#erubi#GetCommand(bufnr(''), output_lines) From 045c92ed655214ef7503c2d592e41eb0ba4bf041 Mon Sep 17 00:00:00 2001 From: w0rp Date: Wed, 17 Jan 2018 18:08:17 +0000 Subject: [PATCH 13/69] Fix #1298 - Escape commands for PowerShell --- autoload/ale/job.vim | 2 +- test/smoke_test.vader | 62 +++++++++++++++++++++++++++++++++ test/test_history_saving.vader | 4 +-- test/test_prepare_command.vader | 4 +-- 4 files changed, 67 insertions(+), 5 deletions(-) diff --git a/autoload/ale/job.vim b/autoload/ale/job.vim index 9cebcf5..2909dab 100644 --- a/autoload/ale/job.vim +++ b/autoload/ale/job.vim @@ -205,7 +205,7 @@ function! ale#job#PrepareCommand(buffer, command) abort " but we'll do this explicitly, so we use the same exact command for both " versions. if has('win32') - return 'cmd /c ' . l:command + return 'cmd /s/c "' . l:command . '"' endif if &shell =~? 'fish$' diff --git a/test/smoke_test.vader b/test/smoke_test.vader index 7635cbd..f6d0be5 100644 --- a/test/smoke_test.vader +++ b/test/smoke_test.vader @@ -1,6 +1,7 @@ Before: Save g:ale_set_lists_synchronously Save g:ale_buffer_info + Save &shell let g:ale_buffer_info = {} let g:ale_set_lists_synchronously = 1 @@ -59,6 +60,67 @@ Execute(Linters should run with the default options): \ 'valid': 1, \ }], getloclist(0) +Execute(Linters should run in PowerShell too): + if has('win32') + set shell=powershell + + AssertEqual 'foobar', &filetype + + " Replace the callback to handle two lines. + function! TestCallback(buffer, output) + " Windows adds extra spaces to the text from echo. + return [ + \ { + \ 'lnum': 1, + \ 'col': 3, + \ 'text': substitute(a:output[0], ' *$', '', ''), + \ }, + \ { + \ 'lnum': 2, + \ 'col': 3, + \ 'text': substitute(a:output[1], ' *$', '', ''), + \ }, + \] + endfunction + + " Recreate the command string to use &&, which PowerShell does not support. + call ale#linter#Reset() + call ale#linter#Define('foobar', { + \ 'name': 'testlinter', + \ 'callback': 'TestCallback', + \ 'executable': 'cmd', + \ 'command': 'echo foo && echo bar', + \}) + + call ale#Lint() + call ale#engine#WaitForJobs(2000) + + AssertEqual [ + \ { + \ 'bufnr': bufnr('%'), + \ 'lnum': 1, + \ 'vcol': 0, + \ 'col': 3, + \ 'text': 'foo', + \ 'type': 'E', + \ 'nr': -1, + \ 'pattern': '', + \ 'valid': 1, + \ }, + \ { + \ 'bufnr': bufnr('%'), + \ 'lnum': 2, + \ 'vcol': 0, + \ 'col': 3, + \ 'text': 'bar', + \ 'type': 'E', + \ 'nr': -1, + \ 'pattern': '', + \ 'valid': 1, + \ }, + \], getloclist(0) + endif + Execute(Previous errors should be removed when linters change): call ale#Lint() call ale#engine#WaitForJobs(2000) diff --git a/test/test_history_saving.vader b/test/test_history_saving.vader index 020ceb5..7dabcd9 100644 --- a/test/test_history_saving.vader +++ b/test/test_history_saving.vader @@ -76,7 +76,7 @@ Execute(History should be set when commands are run): AssertEqual sort(['status', 'exit_code', 'job_id', 'command']), sort(keys(g:history[0])) if has('win32') - AssertEqual 'cmd /c echo command history test', g:history[0].command + AssertEqual 'cmd /s/c "echo command history test"', g:history[0].command else AssertEqual ['/bin/sh', '-c', '/bin/sh -c ''echo command history test'''], g:history[0].command endif @@ -151,7 +151,7 @@ Execute(The history should be updated when fixers are run): AssertEqual ['finished'], map(copy(b:ale_history), 'v:val.status') if has('win32') - AssertEqual 'cmd /c echo foo ', split(b:ale_history[0].command, '<')[0] + AssertEqual 'cmd /s/c "echo foo ', split(b:ale_history[0].command, '<')[0] else AssertEqual '/bin/sh -c echo foo ', split(join(b:ale_history[0].command), '<')[0] endif diff --git a/test/test_prepare_command.vader b/test/test_prepare_command.vader index 16772e8..ed9272a 100644 --- a/test/test_prepare_command.vader +++ b/test/test_prepare_command.vader @@ -30,10 +30,10 @@ Execute(Other shells should be used when set): AssertEqual ['/bin/bash', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar') endif -Execute(cmd /c as a string should be used on Windows): +Execute(cmd /s/c as a string should be used on Windows): if has('win32') let &shell = 'who cares' let &shellcmdflag = 'whatever' - AssertEqual 'cmd /c foobar', ale#job#PrepareCommand(bufnr(''), 'foobar') + AssertEqual 'cmd /s/c "foobar"', ale#job#PrepareCommand(bufnr(''), 'foobar') endif From eddda2f8b599a52e92c99795f42c0c4ba8e15f7c Mon Sep 17 00:00:00 2001 From: w0rp Date: Wed, 17 Jan 2018 18:11:20 +0000 Subject: [PATCH 14/69] Fix a command wrapper test on Windows --- test/test_wrap_comand.vader | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_wrap_comand.vader b/test/test_wrap_comand.vader index 8c1569b..7ddb06a 100644 --- a/test/test_wrap_comand.vader +++ b/test/test_wrap_comand.vader @@ -5,7 +5,7 @@ Before: function! TestCommand(expected_part, input) abort let l:expected = has('win32') - \ ? 'cmd /c ' . a:expected_part + \ ? 'cmd /s/c "' . a:expected_part . '"' \ : split(&shell) + split(&shellcmdflag) + [a:expected_part] AssertEqual l:expected, ale#job#PrepareCommand(bufnr(''), a:input) From 042dec059a3da01477cbc76e9893973dd374872d Mon Sep 17 00:00:00 2001 From: Rafael Lerm Date: Fri, 19 Jan 2018 14:40:55 -0200 Subject: [PATCH 15/69] Send didSave message to LSP-based linters (#1295) * Also send didSave to LSP linters. * Add tests for messages sent to LSP linters. --- autoload/ale/engine.vim | 7 ++ test/lsp/test_lsp_communication.vader | 97 +++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 test/lsp/test_lsp_communication.vader diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 70b5a3b..c415e7c 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -703,6 +703,13 @@ function! s:CheckWithLSP(buffer, linter) abort \ : ale#lsp#message#DidChange(a:buffer) let l:request_id = ale#lsp#Send(l:id, l:change_message, l:root) + " If this was a file save event, also notify the server of that. + let l:is_save = getbufvar(a:buffer, 'ale_save_event_fired', 0) + if l:is_save != 0 + let l:save_message = ale#lsp#message#DidSave(a:buffer) + let l:request_id = ale#lsp#Send(l:id, l:save_message, l:root) + endif + if l:request_id != 0 if index(l:info.active_linter_list, a:linter.name) < 0 call add(l:info.active_linter_list, a:linter.name) diff --git a/test/lsp/test_lsp_communication.vader b/test/lsp/test_lsp_communication.vader new file mode 100644 index 0000000..7a4c67e --- /dev/null +++ b/test/lsp/test_lsp_communication.vader @@ -0,0 +1,97 @@ +Before: + Save g:ale_lint_on_save + Save g:ale_enabled + Save g:ale_linters + Save g:ale_run_synchronously + + call ale#test#SetDirectory('/testplugin/test/completion') + call ale#test#SetFilename('dummy.txt') + + runtime autoload/ale/lsp.vim + + let g:ale_lint_on_save = 1 + let b:ale_enabled = 1 + let g:ale_lsp_next_message_id = 1 + let g:ale_run_synchronously = 1 + let g:message_list = [] + let g:Callback = '' + + call ale#linter#Define('foobar', { + \ 'name': 'dummy_linter', + \ 'lsp': 'stdio', + \ 'command': 'cat - > /dev/null', + \ 'executable': has('win32') ? 'cmd' : 'echo', + \ 'language_callback': {buffer -> 'foobar'}, + \ 'project_root_callback': {buffer -> expand('.')}, + \ }) + let g:ale_linters = {'foobar': ['dummy_linter']} + + function! ale#linter#StartLSP(buffer, linter, callback) abort + let g:Callback = a:callback + + return { + \ 'connection_id': 347, + \ 'project_root': '/foo/bar', + \} + endfunction + + " Replace the Send function for LSP, so we can monitor calls to it. + function! ale#lsp#Send(conn_id, message, ...) abort + call add(g:message_list, a:message) + endfunction + +After: + Restore + + unlet! b:ale_enabled + unlet! b:ale_linters + unlet! g:Callback + unlet! g:message_list + + call ale#test#RestoreDirectory() + call ale#linter#Reset() + + " Stop any timers we left behind. + " This stops the tests from failing randomly. + call ale#completion#StopTimer() + + runtime autoload/ale/completion.vim + runtime autoload/ale/lsp.vim + +Given foobar (Some imaginary filetype): + + +Execute(Server should be notified on save): + call ale#events#SaveEvent(bufnr('')) + + AssertEqual + \ [ + \ [1, 'textDocument/didChange', { + \ 'textDocument': { + \ 'uri': ale#path#ToURI(expand('%:p')), + \ 'version': g:ale_lsp_next_version_id - 1, + \ }, + \ 'contentChanges': [{'text': join(getline(1, '$'), "\n") . "\n"}], + \ }], + \ [1, 'textDocument/didSave', { + \ 'textDocument': { + \ 'uri': ale#path#ToURI(expand('%:p')), + \ }, + \ }], + \ ], + \ g:message_list + +Execute(Server should be notified on change): + call ale#events#FileChangedEvent(bufnr('')) + + AssertEqual + \ [ + \ [1, 'textDocument/didChange', { + \ 'textDocument': { + \ 'uri': ale#path#ToURI(expand('%:p')), + \ 'version': g:ale_lsp_next_version_id - 1, + \ }, + \ 'contentChanges': [{'text': join(getline(1, '$'), "\n") . "\n"}], + \ }], + \ ], + \ g:message_list From a5ec4143d2ed0527649d4143e244b62b9f879661 Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 19 Jan 2018 16:50:04 +0000 Subject: [PATCH 16/69] Fix the didSave tests so they work in NeoVim 0.1.7, and do not send the message for tsserver --- autoload/ale/engine.vim | 4 ++-- ...munication.vader => test_did_save_event.vader} | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) rename test/lsp/{test_lsp_communication.vader => test_did_save_event.vader} (88%) diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index c415e7c..8c3d4c7 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -704,8 +704,8 @@ function! s:CheckWithLSP(buffer, linter) abort let l:request_id = ale#lsp#Send(l:id, l:change_message, l:root) " If this was a file save event, also notify the server of that. - let l:is_save = getbufvar(a:buffer, 'ale_save_event_fired', 0) - if l:is_save != 0 + if a:linter.lsp isnot# 'tsserver' + \&& getbufvar(a:buffer, 'ale_save_event_fired', 0) let l:save_message = ale#lsp#message#DidSave(a:buffer) let l:request_id = ale#lsp#Send(l:id, l:save_message, l:root) endif diff --git a/test/lsp/test_lsp_communication.vader b/test/lsp/test_did_save_event.vader similarity index 88% rename from test/lsp/test_lsp_communication.vader rename to test/lsp/test_did_save_event.vader index 7a4c67e..042a3ce 100644 --- a/test/lsp/test_lsp_communication.vader +++ b/test/lsp/test_did_save_event.vader @@ -16,13 +16,21 @@ Before: let g:message_list = [] let g:Callback = '' + function! LanguageCallback() abort + return 'foobar' + endfunction + + function! ProjectRootCallback() abort + return expand('.') + endfunction + call ale#linter#Define('foobar', { \ 'name': 'dummy_linter', \ 'lsp': 'stdio', \ 'command': 'cat - > /dev/null', \ 'executable': has('win32') ? 'cmd' : 'echo', - \ 'language_callback': {buffer -> 'foobar'}, - \ 'project_root_callback': {buffer -> expand('.')}, + \ 'language_callback': 'LanguageCallback', + \ 'project_root_callback': 'ProjectRootCallback', \ }) let g:ale_linters = {'foobar': ['dummy_linter']} @@ -48,6 +56,9 @@ After: unlet! g:Callback unlet! g:message_list + delfunction LanguageCallback + delfunction ProjectRootCallback + call ale#test#RestoreDirectory() call ale#linter#Reset() From 7cd25181b29dd0484a11fefc03d2239564fcba06 Mon Sep 17 00:00:00 2001 From: Christoffer Aasted <402927+dezza@users.noreply.github.com> Date: Sat, 20 Jan 2018 03:20:13 +0100 Subject: [PATCH 17/69] Fix #1246 - Newer ESLint outputs to stderr I think Vader test still applies for this one. --- ale_linters/javascript/eslint.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/ale_linters/javascript/eslint.vim b/ale_linters/javascript/eslint.vim index 785b8bb..23e1694 100644 --- a/ale_linters/javascript/eslint.vim +++ b/ale_linters/javascript/eslint.vim @@ -3,6 +3,7 @@ call ale#linter#Define('javascript', { \ 'name': 'eslint', +\ 'output_stream': 'both', \ 'executable_callback': 'ale#handlers#eslint#GetExecutable', \ 'command_callback': 'ale#handlers#eslint#GetCommand', \ 'callback': 'ale#handlers#eslint#Handle', From 038789f0ed42cfffbd442a6a399cb2395591821d Mon Sep 17 00:00:00 2001 From: Fran Casas Date: Mon, 22 Jan 2018 13:21:07 +0100 Subject: [PATCH 18/69] Add Elixir linter for dialyxir (#1257) * Add Elixir linter for dialyxir * Update doc/ale.txt with dialyxir * Keep elixir tools alphabetically ordered in README * Add a missing entry for dialyxir to the main documentation file. --- README.md | 2 +- ale_linters/elixir/dialyxir.vim | 34 +++++++++++++++++++++++++++++++++ doc/ale-elixir.txt | 15 +++++++++++++++ doc/ale.txt | 3 ++- 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 ale_linters/elixir/dialyxir.vim diff --git a/README.md b/README.md index 29095df..c42f4bf 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ formatting. | Dafny | [dafny](https://rise4fun.com/Dafny) !! | | Dart | [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) !!, [language_server](https://github.com/natebosch/dart_language_server) | | Dockerfile | [hadolint](https://github.com/lukasmartinelli/hadolint) | -| Elixir | [credo](https://github.com/rrrene/credo), [dogma](https://github.com/lpil/dogma) !! | +| Elixir | [credo](https://github.com/rrrene/credo), [dialyxir](https://github.com/jeremyjh/dialyxir), [dogma](https://github.com/lpil/dogma) !!| | Elm | [elm-format](https://github.com/avh4/elm-format), [elm-make](https://github.com/elm-lang/elm-make) | | Erb | [erb](https://github.com/jeremyevans/erubi), [erubis](https://github.com/kwatch/erubis) | | Erlang | [erlc](http://erlang.org/doc/man/erlc.html), [SyntaxErl](https://github.com/ten0s/syntaxerl) | diff --git a/ale_linters/elixir/dialyxir.vim b/ale_linters/elixir/dialyxir.vim new file mode 100644 index 0000000..5ef3a04 --- /dev/null +++ b/ale_linters/elixir/dialyxir.vim @@ -0,0 +1,34 @@ +" Author: Fran C. - https://github.com/franciscoj +" Description: Add dialyzer support for elixir through dialyxir +" https://github.com/jeremyjh/dialyxir + +function! ale_linters#elixir#dialyxir#Handle(buffer, lines) abort + " Matches patterns line the following: + " + " lib/filename.ex:19: Function fname/1 has no local return + let l:pattern = '\v(.+):(\d+): (.+)$' + let l:output = [] + let l:type = 'W' + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + if bufname(a:buffer) == l:match[1] + call add(l:output, { + \ 'bufnr': a:buffer, + \ 'lnum': l:match[2] + 0, + \ 'col': 0, + \ 'type': l:type, + \ 'text': l:match[3], + \}) + endif + endfor + + return l:output +endfunction + +call ale#linter#Define('elixir', { +\ 'name': 'dialyxir', +\ 'executable': 'mix', +\ 'command': 'mix dialyzer', +\ 'callback': 'ale_linters#elixir#dialyxir#Handle', +\}) + diff --git a/doc/ale-elixir.txt b/doc/ale-elixir.txt index a5318c0..b7d4922 100644 --- a/doc/ale-elixir.txt +++ b/doc/ale-elixir.txt @@ -13,5 +13,20 @@ g:ale_elixir_mix_options *g:ale_elixir_mix_options* This variable can be changed to specify the mix executable. +=============================================================================== +dialyxir *ale-elixir-dialyxir* + +Dialyzer, a DIscrepancy AnaLYZer for ERlang programs. +http://erlang.org/doc/man/dialyzer.html + +It can be used with elixir through dialyxir +https://github.com/jeremyjh/dialyxir + +Options for dialyzer are not configurable by ale, but they are instead +configured on your project's `mix.exs`. + +See https://github.com/jeremyjh/dialyxir#with-explaining-stuff for more +information. + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index b99c800..4776568 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -57,6 +57,7 @@ CONTENTS *ale-contents* hadolint............................|ale-dockerfile-hadolint| elixir................................|ale-elixir-options| mix.................................|ale-elixir-mix| + dialyxir............................|ale-elixir-dialyxir| elm...................................|ale-elm-options| elm-format..........................|ale-elm-elm-format| elm-make............................|ale-elm-elm-make| @@ -301,7 +302,7 @@ Notes: * Dafny: `dafny`!! * Dart: `dartanalyzer`!!, `language_server` * Dockerfile: `hadolint` -* Elixir: `credo`, `dogma`!! +* Elixir: `credo`, `dialyxir`, `dogma`!! * Elm: `elm-format, elm-make` * Erb: `erb`, `erubis` * Erlang: `erlc`, `SyntaxErl` From dd413a4732ed52e33ec318c7c15a30cf413c87a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Tue, 23 Jan 2018 22:46:59 +0100 Subject: [PATCH 19/69] Improving hadolint checker - Displaying dockerfile parse errors instead of silently failing - Adding error detail with link to the docs --- ale_linters/dockerfile/hadolint.vim | 30 ++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/ale_linters/dockerfile/hadolint.vim b/ale_linters/dockerfile/hadolint.vim index 5550d69..6e1c737 100644 --- a/ale_linters/dockerfile/hadolint.vim +++ b/ale_linters/dockerfile/hadolint.vim @@ -7,26 +7,46 @@ call ale#Set('dockerfile_hadolint_docker_image', 'lukasmartinelli/hadolint') function! ale_linters#dockerfile#hadolint#Handle(buffer, lines) abort " Matches patterns line the following: " - " stdin:19: F: Pipe chain should start with a raw value. - let l:pattern = '\v^/dev/stdin:?(\d+)? (\S+) (.+)$' + " /dev/stdin:19 DL3001 Pipe chain should start with a raw value. + " /dev/stdin:19:3 unexpected thing + let l:pattern = '\v^/dev/stdin:(\d+):?(\d+)? ((DL|SC)(\d+) )?(.+)$' let l:output = [] for l:match in ale#util#GetMatches(a:lines, l:pattern) let l:lnum = 0 + let l:colnum = 0 if l:match[1] isnot# '' let l:lnum = l:match[1] + 0 endif + if l:match[2] isnot# '' + let l:colnum = l:match[2] + 0 + endif + let l:type = 'W' - let l:text = l:match[3] + let l:text = l:match[6] + let l:detail = l:match[6] + let l:domain = 'https://github.com/hadolint/hadolint/wiki/' + + if l:match[4] is# 'SC' + let l:domain = 'https://github.com/koalaman/shellcheck/wiki/' + endif + + if l:match[5] isnot# '' + let l:code = l:match[4] . l:match[5] + let l:link = ' ( ' . l:domain . l:code . ' )' + let l:detail = l:code . l:link . "\n\n" . l:detail + else + let l:type = 'E' + endif call add(l:output, { \ 'lnum': l:lnum, - \ 'col': 0, + \ 'col': l:colnum, \ 'type': l:type, \ 'text': l:text, - \ 'nr': l:match[2], + \ 'detail': l:detail \}) endfor From d562d531024a2a2210fdf08594639a0b068bacce Mon Sep 17 00:00:00 2001 From: Rafael Rinaldi Date: Wed, 24 Jan 2018 10:12:29 +0000 Subject: [PATCH 20/69] Add jq as a JSON fixer --- README.md | 2 +- autoload/ale/fix/registry.vim | 5 +++++ autoload/ale/fixers/jq.vim | 18 ++++++++++++++++++ doc/ale-json.txt | 27 +++++++++++++++++++++++++++ doc/ale.txt | 3 ++- 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 autoload/ale/fixers/jq.vim diff --git a/README.md b/README.md index c42f4bf..6ac88cc 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ formatting. | Idris | [idris](http://www.idris-lang.org/) | | Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html), [google-java-format](https://github.com/google/google-java-format) | | JavaScript | [eslint](http://eslint.org/), [flow](https://flowtype.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [prettier](https://github.com/prettier/prettier), [prettier-eslint](https://github.com/prettier/prettier-eslint), [prettier-standard](https://github.com/sheerun/prettier-standard), [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo) -| JSON | [jsonlint](http://zaa.ch/jsonlint/), [prettier](https://github.com/prettier/prettier) | +| JSON | [jsonlint](http://zaa.ch/jsonlint/), [jq](https://stedolan.github.io/jq/), [prettier](https://github.com/prettier/prettier) | | Kotlin | [kotlinc](https://kotlinlang.org) !!, [ktlint](https://ktlint.github.io) !! see `:help ale-integration-kotlin` for configuration instructions | | LaTeX | [alex](https://github.com/wooorm/alex) !!, [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck), [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [vale](https://github.com/ValeLint/vale), [write-good](https://github.com/btford/write-good) | | Less | [lessc](https://www.npmjs.com/package/less), [prettier](https://github.com/prettier/prettier), [stylelint](https://github.com/stylelint/stylelint) | diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 4b69240..2e8e6e0 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -159,6 +159,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['java'], \ 'description': 'Fix Java files with google-java-format.', \ }, +\ 'jq': { +\ 'function': 'ale#fixers#jq#Fix', +\ 'suggested_filetypes': ['json'], +\ 'description': 'Fix JSON files with jq.', +\ }, \} " Reset the function registry to the default entries. diff --git a/autoload/ale/fixers/jq.vim b/autoload/ale/fixers/jq.vim new file mode 100644 index 0000000..4604b24 --- /dev/null +++ b/autoload/ale/fixers/jq.vim @@ -0,0 +1,18 @@ +call ale#Set('json_jq_executable', 'jq') +call ale#Set('json_jq_use_global', 0) +call ale#Set('json_jq_options', '') + +function! ale#fixers#jq#GetExecutable(buffer) abort + return ale#node#FindExecutable(a:buffer, 'jq', [ + \ 'jq', + \]) +endfunction + +function! ale#fixers#jq#Fix(buffer) abort + let l:options = ale#Var(a:buffer, 'json_jq_options') + + return { + \ 'command': ale#Escape(ale#fixers#jq#GetExecutable(a:buffer)) + \ . ' . ' . l:options, + \} +endfunction diff --git a/doc/ale-json.txt b/doc/ale-json.txt index 1d052d5..92c4609 100644 --- a/doc/ale-json.txt +++ b/doc/ale-json.txt @@ -8,6 +8,33 @@ jsonlint *ale-json-jsonlint* There are no options available. +=============================================================================== +jq *ale-json-jq* + +g:ale_json_jq_executable *g:ale_json_jq_executable* + *b:ale_json_jq_executable* + Type: |String| + Default: `'jq'` + + See |ale-integrations-local-executables| + + +g:ale_json_jq_use_global *g:ale_json_jq_use_global* + *b:ale_json_jq_use_global* + Type: |Number| + Default: `0` + + See |ale-integrations-local-executables| + + +g:ale_json_jq_options *g:ale_json_jq_options* + *b:ale_json_jq_options* + Type: |String| + Default: `''` + + This option can be changed to pass extra options to `jq`. + + =============================================================================== prettier *ale-json-prettier* diff --git a/doc/ale.txt b/doc/ale.txt index 4776568..f25e884 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -113,6 +113,7 @@ CONTENTS *ale-contents* xo..................................|ale-javascript-xo| json..................................|ale-json-options| jsonlint............................|ale-json-jsonlint| + jq..................................|ale-json-jq| prettier............................|ale-json-prettier| kotlin................................|ale-kotlin-options| kotlinc.............................|ale-kotlin-kotlinc| @@ -321,7 +322,7 @@ Notes: * Idris: `idris` * Java: `checkstyle`, `javac`, `google-java-format` * JavaScript: `eslint`, `flow`, `jscs`, `jshint`, `prettier`, `prettier-eslint`, `prettier-standard`, `standard`, `xo` -* JSON: `jsonlint`, `prettier` +* JSON: `jsonlint`, `jq`, `prettier` * Kotlin: `kotlinc`, `ktlint` * LaTeX (tex): `alex`!!, `chktex`, `lacheck`, `proselint`, `redpen`, `vale`, `write-good` * Less: `lessc`, `prettier`, `stylelint` From b28a6ddbe4cf573ea993288a6ad4db569d535adf Mon Sep 17 00:00:00 2001 From: rhysd Date: Wed, 24 Jan 2018 10:36:02 +0000 Subject: [PATCH 21/69] Support fixing JSON files with fixjson --- README.md | 2 +- autoload/ale/fix/registry.vim | 5 ++ autoload/ale/fixers/fixjson.vim | 20 ++++++++ doc/ale-json.txt | 39 +++++++++++++++ doc/ale.txt | 3 +- test/fixers/test_fixjson_fixer_callback.vader | 50 +++++++++++++++++++ test/json_files/testfile.json | 1 + 7 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 autoload/ale/fixers/fixjson.vim create mode 100644 test/fixers/test_fixjson_fixer_callback.vader create mode 100644 test/json_files/testfile.json diff --git a/README.md b/README.md index 6ac88cc..ff46a40 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ formatting. | Idris | [idris](http://www.idris-lang.org/) | | Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html), [google-java-format](https://github.com/google/google-java-format) | | JavaScript | [eslint](http://eslint.org/), [flow](https://flowtype.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [prettier](https://github.com/prettier/prettier), [prettier-eslint](https://github.com/prettier/prettier-eslint), [prettier-standard](https://github.com/sheerun/prettier-standard), [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo) -| JSON | [jsonlint](http://zaa.ch/jsonlint/), [jq](https://stedolan.github.io/jq/), [prettier](https://github.com/prettier/prettier) | +| JSON | [fixjson](https://github.com/rhysd/fixjson), [jsonlint](http://zaa.ch/jsonlint/), [jq](https://stedolan.github.io/jq/), [prettier](https://github.com/prettier/prettier) | | Kotlin | [kotlinc](https://kotlinlang.org) !!, [ktlint](https://ktlint.github.io) !! see `:help ale-integration-kotlin` for configuration instructions | | LaTeX | [alex](https://github.com/wooorm/alex) !!, [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck), [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [vale](https://github.com/ValeLint/vale), [write-good](https://github.com/btford/write-good) | | Less | [lessc](https://www.npmjs.com/package/less), [prettier](https://github.com/prettier/prettier), [stylelint](https://github.com/stylelint/stylelint) | diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 2e8e6e0..2d0b4a5 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -159,6 +159,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['java'], \ 'description': 'Fix Java files with google-java-format.', \ }, +\ 'fixjson': { +\ 'function': 'ale#fixers#fixjson#Fix', +\ 'suggested_filetypes': ['json'], +\ 'description': 'Fix JSON files with fixjson.', +\ }, \ 'jq': { \ 'function': 'ale#fixers#jq#Fix', \ 'suggested_filetypes': ['json'], diff --git a/autoload/ale/fixers/fixjson.vim b/autoload/ale/fixers/fixjson.vim new file mode 100644 index 0000000..84728f2 --- /dev/null +++ b/autoload/ale/fixers/fixjson.vim @@ -0,0 +1,20 @@ +" Author: rhysd +" Description: Integration of fixjson with ALE. + +call ale#Set('json_fixjson_executable', 'fixjson') +call ale#Set('json_fixjson_options', '') + +function! ale#fixers#fixjson#Fix(buffer) abort + let l:executable = ale#Escape(ale#Var(a:buffer, 'json_fixjson_executable')) + let l:filename = ale#Escape(bufname(a:buffer)) + let l:command = l:executable . ' --stdin-filename ' . l:filename + + let l:options = ale#Var(a:buffer, 'json_fixjson_options') + if l:options isnot# '' + let l:command .= ' ' . l:options + endif + + return { + \ 'command': l:command + \} +endfunction diff --git a/doc/ale-json.txt b/doc/ale-json.txt index 92c4609..b8e13cd 100644 --- a/doc/ale-json.txt +++ b/doc/ale-json.txt @@ -2,6 +2,45 @@ ALE JSON Integration *ale-json-options* +=============================================================================== +fixjson *ale-json-fixjson* + +fixjson is a JSON file fixer/formatter for humans using (relaxed) JSON5. +It provides: + +- Pretty-prints JSON input +- Fixes various failures while humans writing JSON + - Fixes trailing commas objects or arrays + - Fixes missing commas for elements of objects or arrays + - Adds quotes to keys in objects + - Newlines in strings + - Hex numbers + - Fixes single quotes to double quotes + +You can install it using npm: +> + $ npm install -g fixjson +< +ALE provides fixjson integration as a fixer. See |ale-fix|. + +g:ale_json_fixjson_executable *g:ale_json_fixjson_executable* + *b:ale_json_fixjson_executable* + + Type: |String| + Default: `'fixjson'` + + The executable that will be run for fixjson. + +g:ale_json_fixjson_options *g:ale_json_fixjson_options* + *b:ale_json_fixjson_options* + + Type: |String| + Default: `''` + + This variable can add extra options to the command executed for running + fixjson. + + =============================================================================== jsonlint *ale-json-jsonlint* diff --git a/doc/ale.txt b/doc/ale.txt index f25e884..ddda902 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -112,6 +112,7 @@ CONTENTS *ale-contents* standard............................|ale-javascript-standard| xo..................................|ale-javascript-xo| json..................................|ale-json-options| + fixjson.............................|ale-json-fixjson| jsonlint............................|ale-json-jsonlint| jq..................................|ale-json-jq| prettier............................|ale-json-prettier| @@ -322,7 +323,7 @@ Notes: * Idris: `idris` * Java: `checkstyle`, `javac`, `google-java-format` * JavaScript: `eslint`, `flow`, `jscs`, `jshint`, `prettier`, `prettier-eslint`, `prettier-standard`, `standard`, `xo` -* JSON: `jsonlint`, `jq`, `prettier` +* JSON: `fixjson`, `jsonlint`, `jq`, `prettier` * Kotlin: `kotlinc`, `ktlint` * LaTeX (tex): `alex`!!, `chktex`, `lacheck`, `proselint`, `redpen`, `vale`, `write-good` * Less: `lessc`, `prettier`, `stylelint` diff --git a/test/fixers/test_fixjson_fixer_callback.vader b/test/fixers/test_fixjson_fixer_callback.vader new file mode 100644 index 0000000..1a3bdcf --- /dev/null +++ b/test/fixers/test_fixjson_fixer_callback.vader @@ -0,0 +1,50 @@ +Before: + Save g:ale_json_fixjson_executable + Save g:ale_json_fixjson_options + + let g:ale_json_fixjson_executable = '/path/to/fixjson' + let g:ale_json_fixjson_options = '' + + call ale#test#SetDirectory('/testplugin/test/fixers') + +After: + Restore + +Execute(The fixjson callback should return the correct default command): + AssertEqual + \ { + \ 'command': ale#Escape('/path/to/fixjson') + \ . ' --stdin-filename ' + \ . ale#Escape(bufname(bufnr(''))) + \ }, + \ ale#fixers#fixjson#Fix(bufnr('')) + +Execute(The fixjson callback should set the buffer name as file name): + call ale#test#SetFilename('../json_files/testfile.json') + + AssertEqual + \ { + \ 'command': ale#Escape('/path/to/fixjson') + \ . ' --stdin-filename ' + \ . ale#Escape(bufname(bufnr(''))) + \ }, + \ ale#fixers#fixjson#Fix(bufnr('')) + + AssertNotEqual + \ stridx( + \ ale#fixers#fixjson#Fix(bufnr('')).command, + \ 'testfile.json', + \ ), + \ -1 + +Execute(The fixjson callback should include additional options): + let g:ale_json_fixjson_options = '-i 2' + + AssertEqual + \ { + \ 'command': ale#Escape('/path/to/fixjson') + \ . ' --stdin-filename ' + \ . ale#Escape(bufname(bufnr(''))) + \ . ' -i 2' + \ }, + \ ale#fixers#fixjson#Fix(bufnr('')) diff --git a/test/json_files/testfile.json b/test/json_files/testfile.json new file mode 100644 index 0000000..fe317eb --- /dev/null +++ b/test/json_files/testfile.json @@ -0,0 +1 @@ +{"answer":42} From be47e37bbcaf99220a617f6a1e067852f1be74e3 Mon Sep 17 00:00:00 2001 From: butlerx Date: Fri, 5 Jan 2018 12:02:05 +0000 Subject: [PATCH 22/69] add prettier support for graphql --- README.md | 2 +- autoload/ale/fix/registry.vim | 2 +- doc/ale-graphql.txt | 5 +++++ doc/ale.txt | 3 ++- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f058df2..df25337 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ formatting. | Git Commit Messages | [gitlint](https://github.com/jorisroovers/gitlint) | | GLSL | [glslang](https://github.com/KhronosGroup/glslang), [glslls](https://github.com/svenstaro/glsl-language-server) | | Go | [gofmt](https://golang.org/cmd/gofmt/), [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports), [go vet](https://golang.org/cmd/vet/), [golint](https://godoc.org/github.com/golang/lint), [gotype](https://godoc.org/golang.org/x/tools/cmd/gotype), [gometalinter](https://github.com/alecthomas/gometalinter) !!, [go build](https://golang.org/cmd/go/) !!, [gosimple](https://github.com/dominikh/go-tools/tree/master/cmd/gosimple) !!, [staticcheck](https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck) !! | -| GraphQL | [eslint](http://eslint.org/), [gqlint](https://github.com/happylinks/gqlint) | +| GraphQL | [eslint](http://eslint.org/), [gqlint](https://github.com/happylinks/gqlint), [prettier](https://github.com/prettier/prettier) | | Haml | [haml-lint](https://github.com/brigade/haml-lint) | | Handlebars | [ember-template-lint](https://github.com/rwjblue/ember-template-lint) | | Haskell | [brittany](https://github.com/lspitzner/brittany), [ghc](https://www.haskell.org/ghc/), [stack-ghc](https://haskellstack.org/), [stack-build](https://haskellstack.org/) !!, [ghc-mod](https://github.com/DanielG/ghc-mod), [stack-ghc-mod](https://github.com/DanielG/ghc-mod), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools), [hfmt](https://github.com/danstiner/hfmt) | diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 2d0b4a5..e456884 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -45,7 +45,7 @@ let s:default_registry = { \ }, \ 'prettier': { \ 'function': 'ale#fixers#prettier#Fix', -\ 'suggested_filetypes': ['javascript', 'typescript', 'json', 'css', 'scss', 'less', 'markdown'], +\ 'suggested_filetypes': ['javascript', 'typescript', 'json', 'css', 'scss', 'less', 'markdown', 'graphql'], \ 'description': 'Apply prettier to a file.', \ }, \ 'prettier_eslint': { diff --git a/doc/ale-graphql.txt b/doc/ale-graphql.txt index de41276..603694b 100644 --- a/doc/ale-graphql.txt +++ b/doc/ale-graphql.txt @@ -13,5 +13,10 @@ You will need the GraphQL ESLint plugin installed for this to work. =============================================================================== gqlint *ale-graphql-gqlint* +=============================================================================== +prettier *ale-graphql-prettier* + +See |ale-javascript-prettier| for information about the available options. + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index e0002f7..26d2d0a 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -82,6 +82,7 @@ CONTENTS *ale-contents* graphql...............................|ale-graphql-options| eslint..............................|ale-graphql-eslint| gqlint..............................|ale-graphql-gqlint| + prettier............................|ale-graphql-prettier| handlebars............................|ale-handlebars-options| ember-template-lint.................|ale-handlebars-embertemplatelint| haskell...............................|ale-haskell-options| @@ -315,7 +316,7 @@ Notes: * Git Commit Messages: `gitlint` * GLSL: glslang, `glslls` * Go: `gofmt`, `goimports`, `go vet`, `golint`, `gotype`, `gometalinter`!!, `go build`!!, `gosimple`!!, `staticcheck`!! -* GraphQL: `eslint`, `gqlint` +* GraphQL: `eslint`, `gqlint`, `prettier` * Haml: `haml-lint` * Handlebars: `ember-template-lint` * Haskell: `brittany`, `ghc`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `hfmt` From ef898fa3033c10a6176995aba4ccb4567c85e601 Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 25 Jan 2018 03:45:07 +0900 Subject: [PATCH 23/69] fixjson: Add support for local installation --- autoload/ale/fixers/fixjson.vim | 9 ++++++++- doc/ale-json.txt | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/autoload/ale/fixers/fixjson.vim b/autoload/ale/fixers/fixjson.vim index 84728f2..43eb063 100644 --- a/autoload/ale/fixers/fixjson.vim +++ b/autoload/ale/fixers/fixjson.vim @@ -3,9 +3,16 @@ call ale#Set('json_fixjson_executable', 'fixjson') call ale#Set('json_fixjson_options', '') +call ale#Set('json_fixjson_use_global', 0) + +function! ale#fixers#fixjson#GetExecutable(buffer) abort + return ale#node#FindExecutable(a:buffer, 'json_fixjson', [ + \ 'node_modules/.bin/fixjson', + \]) +endfunction function! ale#fixers#fixjson#Fix(buffer) abort - let l:executable = ale#Escape(ale#Var(a:buffer, 'json_fixjson_executable')) + let l:executable = ale#Escape(ale#fixers#fixjson#GetExecutable(a:buffer)) let l:filename = ale#Escape(bufname(a:buffer)) let l:command = l:executable . ' --stdin-filename ' . l:filename diff --git a/doc/ale-json.txt b/doc/ale-json.txt index b8e13cd..6377833 100644 --- a/doc/ale-json.txt +++ b/doc/ale-json.txt @@ -40,6 +40,14 @@ g:ale_json_fixjson_options *g:ale_json_fixjson_options* This variable can add extra options to the command executed for running fixjson. +g:ale_json_fixjson_use_global *g:ale_json_fixjson_use_global* + *b:ale_json_fixjson_use_global* + + Type: |Number| + Default: `0` + + See |ale-integrations-local-executables| + =============================================================================== jsonlint *ale-json-jsonlint* From 34e6368610c83a0e3a82dda301d798c7f2f9219d Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 25 Jan 2018 14:54:33 +0000 Subject: [PATCH 24/69] #1316 Mention that the quickfix list option shouldn't be used with :cfdo --- doc/ale.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/ale.txt b/doc/ale.txt index e0002f7..9b8cae4 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1307,6 +1307,11 @@ g:ale_set_quickfix *g:ale_set_quickfix* Problems from every buffer ALE has checked will be included in the quickfix list, which can be checked with |:copen|. Problems will be de-duplicated. + This feature should not be used in combination with tools for searching for + matches and commands like |:cfdo|, as ALE will replace the quickfix list + pretty frequently. If you wish to use such tools, you should populate the + loclist instead. + g:ale_set_signs *g:ale_set_signs* From 9dad25778fa3c848d9ce010979323e91d00a3819 Mon Sep 17 00:00:00 2001 From: butlerx Date: Sat, 27 Jan 2018 11:40:40 +0000 Subject: [PATCH 25/69] add po support with proselint, writegood, msgfmt and alex --- README.md | 1 + ale_linters/po/alex.vim | 11 +++++++++++ ale_linters/po/msgfmt.vim | 10 ++++++++++ ale_linters/po/proselint.vim | 9 +++++++++ ale_linters/po/write-good.vim | 9 +++++++++ doc/ale-po.txt | 12 ++++++++++++ doc/ale.txt | 3 +++ 7 files changed, 55 insertions(+) create mode 100644 ale_linters/po/alex.vim create mode 100644 ale_linters/po/msgfmt.vim create mode 100644 ale_linters/po/proselint.vim create mode 100644 ale_linters/po/write-good.vim create mode 100644 doc/ale-po.txt diff --git a/README.md b/README.md index f058df2..112c8e1 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ formatting. | OCaml | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-ocaml-merlin` for configuration instructions, [ols](https://github.com/freebroccolo/ocaml-language-server) | | Perl | [perl -c](https://perl.org/), [perl-critic](https://metacpan.org/pod/Perl::Critic) | | PHP | [hack](http://hacklang.org/), [hackfmt](https://github.com/facebook/flow/tree/master/hack/hackfmt), [langserver](https://github.com/felixfbecker/php-language-server), [phan](https://github.com/phan/phan) see `:help ale-php-phan` to instructions, [php -l](https://secure.php.net/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer), [phpmd](https://phpmd.org), [phpstan](https://github.com/phpstan/phpstan), [phpcbf](https://github.com/squizlabs/PHP_CodeSniffer) | +| PO | [alex](https://github.com/wooorm/alex) !!, [msgfmt](https://www.gnu.org/software/gettext/manual/html_node/msgfmt-Invocation.html), [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | | Pod | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | | proto | [protoc-gen-lint](https://github.com/ckaznocha/protoc-gen-lint) | | Pug | [pug-lint](https://github.com/pugjs/pug-lint) | diff --git a/ale_linters/po/alex.vim b/ale_linters/po/alex.vim new file mode 100644 index 0000000..411d835 --- /dev/null +++ b/ale_linters/po/alex.vim @@ -0,0 +1,11 @@ +" Author: Cian Butler https://github.com/butlerx +" Description: alex for PO files + +call ale#linter#Define('po', { +\ 'name': 'alex', +\ 'executable': 'alex', +\ 'command': 'alex %s -t', +\ 'output_stream': 'stderr', +\ 'callback': 'ale#handlers#alex#Handle', +\ 'lint_file': 1, +\}) diff --git a/ale_linters/po/msgfmt.vim b/ale_linters/po/msgfmt.vim new file mode 100644 index 0000000..60c25d3 --- /dev/null +++ b/ale_linters/po/msgfmt.vim @@ -0,0 +1,10 @@ +" Author: Cian Butler https://github.com/butlerx +" Description: msgfmt for PO files + +call ale#linter#Define('po', { +\ 'name': 'msgfmt', +\ 'executable': 'msgfmt', +\ 'output_stream': 'stderr', +\ 'command': 'msgfmt --statistics %t', +\ 'callback': 'ale#handlers#unix#HandleAsWarning', +\}) diff --git a/ale_linters/po/proselint.vim b/ale_linters/po/proselint.vim new file mode 100644 index 0000000..ce13250 --- /dev/null +++ b/ale_linters/po/proselint.vim @@ -0,0 +1,9 @@ +" Author: Cian Butler https://github.com/butlerx +" Description: proselint for PO files + +call ale#linter#Define('po', { +\ 'name': 'proselint', +\ 'executable': 'proselint', +\ 'command': 'proselint %t', +\ 'callback': 'ale#handlers#unix#HandleAsWarning', +\}) diff --git a/ale_linters/po/write-good.vim b/ale_linters/po/write-good.vim new file mode 100644 index 0000000..5a01cb6 --- /dev/null +++ b/ale_linters/po/write-good.vim @@ -0,0 +1,9 @@ +" Author: Cian Butler https://github.com/butlerx +" Description: write-good for PO files + +call ale#linter#Define('po', { +\ 'name': 'write-good', +\ 'executable_callback': 'ale#handlers#writegood#GetExecutable', +\ 'command_callback': 'ale#handlers#writegood#GetCommand', +\ 'callback': 'ale#handlers#writegood#Handle', +\}) diff --git a/doc/ale-po.txt b/doc/ale-po.txt new file mode 100644 index 0000000..1e03b7b --- /dev/null +++ b/doc/ale-po.txt @@ -0,0 +1,12 @@ +=============================================================================== +ALE PO Integration *ale-po-options* + + +=============================================================================== +write-good *ale-po-write-good* + +See |ale-write-good-options| + + +=============================================================================== +vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index e0002f7..ce6e6d5 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -154,6 +154,8 @@ CONTENTS *ale-contents* phpcs...............................|ale-php-phpcs| phpmd...............................|ale-php-phpmd| phpstan.............................|ale-php-phpstan| + po....................................|ale-po-options| + write-good..........................|ale-po-write-good| pod...................................|ale-pod-options| write-good..........................|ale-pod-write-good| proto.................................|ale-proto-options| @@ -341,6 +343,7 @@ Notes: * OCaml: `merlin` (see |ale-ocaml-merlin|), `ols` * Perl: `perl -c`, `perl-critic` * PHP: `hack`, `hackfmt`, `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf` +* PO: `alex`!!, `msgfmt`, `proselint`, `write-good` * Pod: `alex`!!, `proselint`, `write-good` * proto: `protoc-gen-lint` * Pug: `pug-lint` From ea60fcea393da1b84dfd62ac1ff10dba6d2dccd2 Mon Sep 17 00:00:00 2001 From: Kent Sibilev Date: Sat, 27 Jan 2018 16:15:29 -0500 Subject: [PATCH 26/69] fixed rust errors parsing use correct column values instead of absolute byte positions --- autoload/ale/handlers/rust.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/ale/handlers/rust.vim b/autoload/ale/handlers/rust.vim index 395b915..537bc73 100644 --- a/autoload/ale/handlers/rust.vim +++ b/autoload/ale/handlers/rust.vim @@ -51,8 +51,8 @@ function! ale#handlers#rust#HandleRustErrors(buffer, lines) abort call add(l:output, { \ 'lnum': l:span.line_start, \ 'end_lnum': l:span.line_end, - \ 'col': l:span.byte_start, - \ 'end_col': l:span.byte_end, + \ 'col': l:span.column_start, + \ 'end_col': l:span.column_end, \ 'text': empty(l:span.label) ? l:error.message : printf('%s: %s', l:error.message, l:span.label), \ 'type': toupper(l:error.level[0]), \}) From 7ef55a86152c3e17e13702f0d9753d7fc9c4d256 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 28 Jan 2018 11:51:20 +0000 Subject: [PATCH 27/69] #1303 jq isn't a Node program --- autoload/ale/fixers/jq.vim | 5 +---- doc/ale-json.txt | 10 +--------- test/fixers/test_jq_fixer_callback.vader | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 test/fixers/test_jq_fixer_callback.vader diff --git a/autoload/ale/fixers/jq.vim b/autoload/ale/fixers/jq.vim index 4604b24..b0a43fe 100644 --- a/autoload/ale/fixers/jq.vim +++ b/autoload/ale/fixers/jq.vim @@ -1,11 +1,8 @@ call ale#Set('json_jq_executable', 'jq') -call ale#Set('json_jq_use_global', 0) call ale#Set('json_jq_options', '') function! ale#fixers#jq#GetExecutable(buffer) abort - return ale#node#FindExecutable(a:buffer, 'jq', [ - \ 'jq', - \]) + return ale#Var(a:buffer, 'json_jq_executable') endfunction function! ale#fixers#jq#Fix(buffer) abort diff --git a/doc/ale-json.txt b/doc/ale-json.txt index 6377833..1e97abc 100644 --- a/doc/ale-json.txt +++ b/doc/ale-json.txt @@ -63,15 +63,7 @@ g:ale_json_jq_executable *g:ale_json_jq_executable* Type: |String| Default: `'jq'` - See |ale-integrations-local-executables| - - -g:ale_json_jq_use_global *g:ale_json_jq_use_global* - *b:ale_json_jq_use_global* - Type: |Number| - Default: `0` - - See |ale-integrations-local-executables| + This option can be changed to change the path for `jq`. g:ale_json_jq_options *g:ale_json_jq_options* diff --git a/test/fixers/test_jq_fixer_callback.vader b/test/fixers/test_jq_fixer_callback.vader new file mode 100644 index 0000000..2e32bf8 --- /dev/null +++ b/test/fixers/test_jq_fixer_callback.vader @@ -0,0 +1,14 @@ +Before: + Save g:ale_json_jq_executable + Save g:ale_json_jq_options + +After: + Restore + +Execute(The jq fixer should use the options you set): + let g:ale_json_jq_executable = 'foo' + let g:ale_json_jq_options = '--bar' + + AssertEqual + \ {'command': ale#Escape('foo') . ' . --bar'}, + \ ale#fixers#jq#Fix(bufnr('')) From 65fc5d11c77527bbf19a94da919fb37b5a02924b Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 28 Jan 2018 12:44:42 +0000 Subject: [PATCH 28/69] Fix #1038 - Automatically detect and use htmlhint configuration files --- ale_linters/html/htmlhint.vim | 21 ++++-- doc/ale-html.txt | 2 +- .../htmlhint_paths/node_modules/.bin/htmlhint | 0 .../htmlhint_paths/with_config/.htmlhintrc | 0 .../test_htmlhint_command_callback.vader | 71 +++++++++++++++++++ 5 files changed, 89 insertions(+), 5 deletions(-) create mode 100755 test/command_callback/htmlhint_paths/node_modules/.bin/htmlhint create mode 100644 test/command_callback/htmlhint_paths/with_config/.htmlhintrc create mode 100644 test/command_callback/test_htmlhint_command_callback.vader diff --git a/ale_linters/html/htmlhint.vim b/ale_linters/html/htmlhint.vim index e142d22..88a83f1 100644 --- a/ale_linters/html/htmlhint.vim +++ b/ale_linters/html/htmlhint.vim @@ -1,7 +1,7 @@ " Author: KabbAmine , deathmaz <00maz1987@gmail.com>, diartyz " Description: HTMLHint for checking html files -call ale#Set('html_htmlhint_options', '--format=unix') +call ale#Set('html_htmlhint_options', '') call ale#Set('html_htmlhint_executable', 'htmlhint') call ale#Set('html_htmlhint_use_global', 0) @@ -12,9 +12,22 @@ function! ale_linters#html#htmlhint#GetExecutable(buffer) abort endfunction function! ale_linters#html#htmlhint#GetCommand(buffer) abort - return ale_linters#html#htmlhint#GetExecutable(a:buffer) - \ . ' ' . ale#Var(a:buffer, 'html_htmlhint_options') - \ . ' %t' + let l:options = ale#Var(a:buffer, 'html_htmlhint_options') + let l:config = l:options !~# '--config' + \ ? ale#path#FindNearestFile(a:buffer, '.htmlhintrc') + \ : '' + + if !empty(l:config) + let l:options .= ' --config ' . ale#Escape(l:config) + endif + + if !empty(l:options) + let l:options = substitute(l:options, '--format=unix', '', '') + endif + + return ale#Escape(ale_linters#html#htmlhint#GetExecutable(a:buffer)) + \ . (!empty(l:options) ? ' ' . l:options : '') + \ . ' --format=unix %t' endfunction call ale#linter#Define('html', { diff --git a/doc/ale-html.txt b/doc/ale-html.txt index c5d5afa..416e932 100644 --- a/doc/ale-html.txt +++ b/doc/ale-html.txt @@ -16,7 +16,7 @@ g:ale_html_htmlhint_executable *g:ale_html_htmlhint_executable* g:ale_html_htmlhint_options *g:ale_html_htmlhint_options* *b:ale_html_htmlhint_options* Type: |String| - Default: `'--format=unix'` + Default: `''` This variable can be changed to modify flags given to HTMLHint. diff --git a/test/command_callback/htmlhint_paths/node_modules/.bin/htmlhint b/test/command_callback/htmlhint_paths/node_modules/.bin/htmlhint new file mode 100755 index 0000000..e69de29 diff --git a/test/command_callback/htmlhint_paths/with_config/.htmlhintrc b/test/command_callback/htmlhint_paths/with_config/.htmlhintrc new file mode 100644 index 0000000..e69de29 diff --git a/test/command_callback/test_htmlhint_command_callback.vader b/test/command_callback/test_htmlhint_command_callback.vader new file mode 100644 index 0000000..5bb21a6 --- /dev/null +++ b/test/command_callback/test_htmlhint_command_callback.vader @@ -0,0 +1,71 @@ +Before: + Save g:ale_html_htmlhint_options + Save g:ale_html_htmlhint_executable + Save g:ale_html_htmlhint_use_global + + unlet! g:ale_html_htmlhint_options + unlet! g:ale_html_htmlhint_executable + unlet! g:ale_html_htmlhint_use_global + + runtime ale_linters/html/htmlhint.vim + call ale#test#SetDirectory('/testplugin/test/command_callback') + call ale#test#SetFilename('htmlhint_paths/test.html') + + let g:node_executable = ale#path#Simplify( + \ g:dir + \ . '/htmlhint_paths/node_modules/.bin/htmlhint' + \) + let g:config_path = ale#path#Simplify( + \ g:dir + \ . '/htmlhint_paths/with_config/.htmlhintrc' + \) + +After: + Restore + + unlet! g:node_executable + unlet! g:config_path + + call ale#test#RestoreDirectory() + call ale#linter#Reset() + +Execute(The default command should be correct): + AssertEqual + \ ale#Escape(g:node_executable) . ' --format=unix %t', + \ ale_linters#html#htmlhint#GetCommand(bufnr('')) + +Execute(The global executable should be uesd if the option is set): + let g:ale_html_htmlhint_executable = 'foo' + let g:ale_html_htmlhint_use_global = 1 + + AssertEqual + \ ale#Escape('foo') . ' --format=unix %t', + \ ale_linters#html#htmlhint#GetCommand(bufnr('')) + +" This is so old configurations which might include this still work. +Execute(--format=unix should be removed from the options if added): + let g:ale_html_htmlhint_options = '--format=unix' + + AssertEqual + \ ale#Escape(g:node_executable) . ' --format=unix %t', + \ ale_linters#html#htmlhint#GetCommand(bufnr('')) + +Execute(The configuration file should be automatically detected): + call ale#test#SetFilename('htmlhint_paths/with_config/test.html') + + AssertEqual + \ ale#Escape(g:node_executable) + \ . ' --config ' . ale#Escape(g:config_path) + \ . ' --format=unix %t', + \ ale_linters#html#htmlhint#GetCommand(bufnr('')) + +" This is so old configurations which might include the config will work. +Execute(The configuration file should be configurable through the options variable): + call ale#test#SetFilename('htmlhint_paths/with_config/test.html') + let g:ale_html_htmlhint_options = '--config=/foo/bar/.htmlhintrc' + + AssertEqual + \ ale#Escape(g:node_executable) + \ . ' --config=/foo/bar/.htmlhintrc' + \ . ' --format=unix %t', + \ ale_linters#html#htmlhint#GetCommand(bufnr('')) From 863fb60695764a41a6fd8139544938f343f61278 Mon Sep 17 00:00:00 2001 From: Kent Sibilev Date: Sun, 28 Jan 2018 18:35:46 -0500 Subject: [PATCH 29/69] updated rust handler test case --- test/handler/test_rust_handler.vader | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/handler/test_rust_handler.vader b/test/handler/test_rust_handler.vader index 05bd1e9..e3ab3e8 100644 --- a/test/handler/test_rust_handler.vader +++ b/test/handler/test_rust_handler.vader @@ -7,16 +7,16 @@ Execute(The Rust handler should handle rustc output): \ 'lnum': 15, \ 'end_lnum': 15, \ 'type': 'E', - \ 'col': 418, - \ 'end_col': 421, + \ 'col': 5, + \ 'end_col': 8, \ 'text': 'expected one of `.`, `;`, `?`, `}`, or an operator, found `for`', \ }, \ { \ 'lnum': 13, \ 'end_lnum': 13, \ 'type': 'E', - \ 'col': 407, - \ 'end_col': 410, + \ 'col': 7, + \ 'end_col': 10, \ 'text': 'no method named `wat` found for type `std::string::String` in the current scope', \ }, \ ], @@ -83,16 +83,16 @@ Execute(The Rust handler should handle cargo output): \ 'lnum': 15, \ 'end_lnum': 15, \ 'type': 'E', - \ 'col': 11505, - \ 'end_col': 11508, + \ 'col': 5, + \ 'end_col': 8, \ 'text': 'expected one of `.`, `;`, `?`, `}`, or an operator, found `for`', \ }, \ { \ 'lnum': 13, \ 'end_lnum': 13, \ 'type': 'E', - \ 'col': 11494, - \ 'end_col': 11497, + \ 'col': 7, + \ 'end_col': 10, \ 'text': 'no method named `wat` found for type `std::string::String` in the current scope', \ }, \ ], @@ -157,8 +157,8 @@ Execute(The Rust handler should should errors from expansion spans): \ 'lnum': 4, \ 'end_lnum': 4, \ 'type': 'E', - \ 'col': 52, - \ 'end_col': 54, + \ 'col': 21, + \ 'end_col': 23, \ 'text': 'mismatched types: expected bool, found integral variable', \ }, \ ], @@ -207,8 +207,8 @@ Execute(The Rust handler should show detailed errors): \ 'lnum': 4, \ 'end_lnum': 4, \ 'type': 'E', - \ 'col': 52, - \ 'end_col': 54, + \ 'col': 21, + \ 'end_col': 23, \ 'text': 'mismatched types: expected bool, found integral variable', \ }, \ ], From 4df87eaaddfceaddd625294c0e601aebf2f68a85 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Mon, 29 Jan 2018 22:21:50 +0100 Subject: [PATCH 30/69] Added tests for hadolint --- README.md | 2 +- ale_linters/dockerfile/hadolint.vim | 2 +- doc/ale-dockerfile.txt | 6 +++--- test/test_dockerfile_hadolint_linter.vader | 23 +++++++++++++++++++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c42f4bf..bd7a705 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ formatting. | D | [dmd](https://dlang.org/dmd-linux.html) | | Dafny | [dafny](https://rise4fun.com/Dafny) !! | | Dart | [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) !!, [language_server](https://github.com/natebosch/dart_language_server) | -| Dockerfile | [hadolint](https://github.com/lukasmartinelli/hadolint) | +| Dockerfile | [hadolint](https://github.com/hadolint/hadolint) | | Elixir | [credo](https://github.com/rrrene/credo), [dialyxir](https://github.com/jeremyjh/dialyxir), [dogma](https://github.com/lpil/dogma) !!| | Elm | [elm-format](https://github.com/avh4/elm-format), [elm-make](https://github.com/elm-lang/elm-make) | | Erb | [erb](https://github.com/jeremyevans/erubi), [erubis](https://github.com/kwatch/erubis) | diff --git a/ale_linters/dockerfile/hadolint.vim b/ale_linters/dockerfile/hadolint.vim index 6e1c737..7772afb 100644 --- a/ale_linters/dockerfile/hadolint.vim +++ b/ale_linters/dockerfile/hadolint.vim @@ -2,7 +2,7 @@ " always, yes, never call ale#Set('dockerfile_hadolint_use_docker', 'never') -call ale#Set('dockerfile_hadolint_docker_image', 'lukasmartinelli/hadolint') +call ale#Set('dockerfile_hadolint_docker_image', 'hadolint/hadolint') function! ale_linters#dockerfile#hadolint#Handle(buffer, lines) abort " Matches patterns line the following: diff --git a/doc/ale-dockerfile.txt b/doc/ale-dockerfile.txt index 288addb..805cc47 100644 --- a/doc/ale-dockerfile.txt +++ b/doc/ale-dockerfile.txt @@ -5,7 +5,7 @@ ALE Dockerfile Integration *ale-dockerfile-options* =============================================================================== hadolint *ale-dockerfile-hadolint* - hadolint can be found at: https://github.com/lukasmartinelli/hadolint + hadolint can be found at: https://github.com/hadolint/hadolint g:ale_dockerfile_hadolint_use_docker *g:ale_dockerfile_hadolint_use_docker* @@ -25,12 +25,12 @@ g:ale_dockerfile_hadolint_use_docker *g:ale_dockerfile_hadolint_use_docker* g:ale_dockerfile_hadolint_image *g:ale_dockerfile_hadolint_image* *b:ale_dockerfile_hadolint_image* Type: |String| - Default: `'lukasmartinelli/hadolint'` + Default: `'hadolint/hadolint'` This variable controls the docker image used to run hadolint. The default is hadolint's author's build, and can be found at: - https://hub.docker.com/r/lukasmartinelli/hadolint/ + https://hub.docker.com/r/hadolint/hadolint/ =============================================================================== diff --git a/test/test_dockerfile_hadolint_linter.vader b/test/test_dockerfile_hadolint_linter.vader index 7262c5b..3edbb2b 100644 --- a/test/test_dockerfile_hadolint_linter.vader +++ b/test/test_dockerfile_hadolint_linter.vader @@ -55,7 +55,7 @@ Execute(command is correct when using docker): let b:ale_dockerfile_hadolint_use_docker = 'always' AssertEqual - \ "docker run --rm -i lukasmartinelli/hadolint", + \ "docker run --rm -i hadolint/hadolint", \ ale_linters#dockerfile#hadolint#GetCommand(bufnr('')) @@ -66,4 +66,25 @@ Execute(command is correct when not docker): \ "hadolint -", \ ale_linters#dockerfile#hadolint#GetCommand(bufnr('')) +Execute(test warnings from hadolint): + AssertEqual + \ [{'lnum': 10, 'col': 0, 'type': 'W', 'text': 'Using latest is prone to errors', 'detail': "DL3007 ( https://github.com/hadolint/hadolint/wiki/DL3007 )\n\nUsing latest is prone to errors"}], + \ ale_linters#dockerfile#hadolint#Handle(bufnr(''), [ + \ '/dev/stdin:10 DL3007 Using latest is prone to errors', + \ ]) + +Execute(test warnings from shellcheck): + AssertEqual + \ [{'lnum': 3, 'col': 0, 'type': 'W', 'text': 'bar is referenced but not assigned.', 'detail': "SC2154 ( https://github.com/koalaman/shellcheck/wiki/SC2154 )\n\nbar is referenced but not assigned."}], + \ ale_linters#dockerfile#hadolint#Handle(bufnr(''), [ + \ '/dev/stdin:3 SC2154 bar is referenced but not assigned.', + \ ]) + +Execute(test errors from dockerfile parser): + AssertEqual + \ [{'lnum': 3, 'col': 4, 'type': 'E', 'text': 'unexpected "A" expecting at least one space after ''RUN''', 'detail': 'unexpected "A" expecting at least one space after ''RUN'''}], + \ ale_linters#dockerfile#hadolint#Handle(bufnr(''), [ + \ "/dev/stdin:3:4 unexpected \"A\" expecting at least one space after 'RUN'", + \ ]) + " fin... From bb095df25e7fb6e3090061572bf9b1c472ac550f Mon Sep 17 00:00:00 2001 From: Michael Quinn Date: Mon, 29 Jan 2018 20:18:14 -0800 Subject: [PATCH 31/69] Call lintr library before linting This solves namespace issues related to the objects used to set linting options. --- ale_linters/r/lintr.vim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ale_linters/r/lintr.vim b/ale_linters/r/lintr.vim index 86b591c..9db63c7 100644 --- a/ale_linters/r/lintr.vim +++ b/ale_linters/r/lintr.vim @@ -1,14 +1,17 @@ " Author: Michel Lang , w0rp " Description: This file adds support for checking R code with lintr. -let g:ale_r_lintr_options = -\ get(g:, 'ale_r_lintr_options', 'lintr::with_defaults()') +let g:ale_r_lintr_options = get(g:, 'ale_r_lintr_options', 'with_defaults()') " A reasonable alternative default: -" \ get(g:, 'ale_r_lintr_options', 'lintr::with_defaults(object_usage_linter = NULL)') +" get(g:, 'ale_r_lintr_options', 'with_defaults(object_usage_linter = NULL)') function! ale_linters#r#lintr#GetCommand(buffer) abort + let l:cmd_string = 'suppressPackageStartupMessages(library(lintr));' + \ . 'lint(cache = FALSE, commandArgs(TRUE),' + \ . ale#Var(a:buffer, 'r_lintr_options') . ')' return ale#path#BufferCdString(a:buffer) - \ . 'Rscript -e ' . ale#Escape('lintr::lint(commandArgs(TRUE)[1], eval(parse(text = commandArgs(TRUE)[2])))') . ' %t' . ' ' . ale#Escape(ale#Var(a:buffer, 'r_lintr_options')) + \ . 'Rscript -e ' + \ . ale#Escape(l:cmd_string) . ' %t' endfunction call ale#linter#Define('r', { @@ -18,3 +21,4 @@ call ale#linter#Define('r', { \ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \ 'output_stream': 'both', \}) + From 23db293bdfda820dcff2464d2c4e533f52eb86be Mon Sep 17 00:00:00 2001 From: blyoa Date: Thu, 1 Feb 2018 01:29:01 +0900 Subject: [PATCH 32/69] Add prettier fixer support to vue --- README.md | 1 + autoload/ale/fix/registry.vim | 2 +- doc/ale-vue.txt | 11 +++++++++++ doc/ale.txt | 3 +++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 doc/ale-vue.txt diff --git a/README.md b/README.md index eed06cf..b09a643 100644 --- a/README.md +++ b/README.md @@ -162,6 +162,7 @@ formatting. | Verilog | [iverilog](https://github.com/steveicarus/iverilog), [verilator](http://www.veripool.org/projects/verilator/wiki/Intro) | | Vim | [vint](https://github.com/Kuniwak/vint) | | Vim help^ | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | +| Vue | [prettier](https://github.com/prettier/prettier) | | XHTML | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | | XML | [xmllint](http://xmlsoft.org/xmllint.html) | | YAML | [swaglint](https://github.com/byCedric/swaglint), [yamllint](https://yamllint.readthedocs.io/) | diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index e456884..29e263a 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -45,7 +45,7 @@ let s:default_registry = { \ }, \ 'prettier': { \ 'function': 'ale#fixers#prettier#Fix', -\ 'suggested_filetypes': ['javascript', 'typescript', 'json', 'css', 'scss', 'less', 'markdown', 'graphql'], +\ 'suggested_filetypes': ['javascript', 'typescript', 'json', 'css', 'scss', 'less', 'markdown', 'graphql', 'vue'], \ 'description': 'Apply prettier to a file.', \ }, \ 'prettier_eslint': { diff --git a/doc/ale-vue.txt b/doc/ale-vue.txt new file mode 100644 index 0000000..937b603 --- /dev/null +++ b/doc/ale-vue.txt @@ -0,0 +1,11 @@ +=============================================================================== +ALE Vue Integration *ale-vue-options* + + +=============================================================================== +prettier *ale-vue-prettier* + +See |ale-javascript-prettier| for information about the available options. + +=============================================================================== + vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index 417db58..2644ebc 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -239,6 +239,8 @@ CONTENTS *ale-contents* vint................................|ale-vim-vint| vim help..............................|ale-vim-help-options| write-good..........................|ale-vim-help-write-good| + vue...................................|ale-vue-options| + prettier............................|ale-vue-prettier| xhtml.................................|ale-xhtml-options| write-good..........................|ale-xhtml-write-good| xml...................................|ale-xml-options| @@ -375,6 +377,7 @@ Notes: * Verilog: `iverilog`, `verilator` * Vim: `vint` * Vim help^: `alex`!!, `proselint`, `write-good` +* Vue: `prettier` * XHTML: `alex`!!, `proselint`, `write-good` * XML: `xmllint` * YAML: `swaglint`, `yamllint` From b13f290390ba62180f731fef6cea58d6fef8bc3e Mon Sep 17 00:00:00 2001 From: Michael Quinn Date: Wed, 31 Jan 2018 18:06:35 -0800 Subject: [PATCH 33/69] Update formatting and tests. --- ale_linters/r/lintr.vim | 6 +++--- .../test_lintr_command_callback.vader | 16 +++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ale_linters/r/lintr.vim b/ale_linters/r/lintr.vim index 9db63c7..e163905 100644 --- a/ale_linters/r/lintr.vim +++ b/ale_linters/r/lintr.vim @@ -7,8 +7,9 @@ let g:ale_r_lintr_options = get(g:, 'ale_r_lintr_options', 'with_defaults()') function! ale_linters#r#lintr#GetCommand(buffer) abort let l:cmd_string = 'suppressPackageStartupMessages(library(lintr));' - \ . 'lint(cache = FALSE, commandArgs(TRUE),' - \ . ale#Var(a:buffer, 'r_lintr_options') . ')' + \ . 'lint(cache = FALSE, commandArgs(TRUE),' + \ . ale#Var(a:buffer, 'r_lintr_options') . ')' + return ale#path#BufferCdString(a:buffer) \ . 'Rscript -e ' \ . ale#Escape(l:cmd_string) . ' %t' @@ -21,4 +22,3 @@ call ale#linter#Define('r', { \ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \ 'output_stream': 'both', \}) - diff --git a/test/command_callback/test_lintr_command_callback.vader b/test/command_callback/test_lintr_command_callback.vader index 3199b49..256618c 100644 --- a/test/command_callback/test_lintr_command_callback.vader +++ b/test/command_callback/test_lintr_command_callback.vader @@ -17,18 +17,20 @@ Execute(The default lintr command should be correct): AssertEqual \ 'cd ' . ale#Escape(getcwd()) . ' && ' \ . 'Rscript -e ' - \ . ale#Escape('lintr::lint(commandArgs(TRUE)[1], eval(parse(text = commandArgs(TRUE)[2])))') - \ . ' %t ' - \ . ale#Escape('lintr::with_defaults()'), + \ . ale#Escape('suppressPackageStartupMessages(library(lintr));' + \ . 'lint(cache = FALSE, commandArgs(TRUE),' + \ . 'with_defaults())') + \ . ' %t', \ ale_linters#r#lintr#GetCommand(bufnr('')) Execute(The lintr options should be configurable): - let b:ale_r_lintr_options = 'lintr::with_defaults(object_usage_linter = NULL)' + let b:ale_r_lintr_options = 'with_defaults(object_usage_linter = NULL)' AssertEqual \ 'cd ' . ale#Escape(getcwd()) . ' && ' \ . 'Rscript -e ' - \ . ale#Escape('lintr::lint(commandArgs(TRUE)[1], eval(parse(text = commandArgs(TRUE)[2])))') - \ . ' %t ' - \ . ale#Escape('lintr::with_defaults(object_usage_linter = NULL)'), + \ . ale#Escape('suppressPackageStartupMessages(library(lintr));' + \ . 'lint(cache = FALSE, commandArgs(TRUE),' + \ . 'with_defaults(object_usage_linter = NULL))') + \ . ' %t', \ ale_linters#r#lintr#GetCommand(bufnr('')) From 0f822b063cb9553c9e00bc63d0184ba8577e6248 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 4 Feb 2018 13:16:44 +0000 Subject: [PATCH 34/69] Fix #1330 - Find isort configs better by changing the working directory --- autoload/ale/fixers/isort.vim | 8 ++------ test/fixers/test_isort_fixer_callback.vader | 5 ++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/autoload/ale/fixers/isort.vim b/autoload/ale/fixers/isort.vim index 00d968f..b631822 100644 --- a/autoload/ale/fixers/isort.vim +++ b/autoload/ale/fixers/isort.vim @@ -15,12 +15,8 @@ function! ale#fixers#isort#Fix(buffer) abort return 0 endif - let l:config = ale#path#FindNearestFile(a:buffer, '.isort.cfg') - let l:config_options = !empty(l:config) - \ ? ' --settings-path ' . ale#Escape(l:config) - \ : '' - return { - \ 'command': ale#Escape(l:executable) . l:config_options . ' -', + \ 'command': ale#path#BufferCdString(a:buffer) + \ . ale#Escape(l:executable) . ' -', \} endfunction diff --git a/test/fixers/test_isort_fixer_callback.vader b/test/fixers/test_isort_fixer_callback.vader index 503057b..7c2b515 100644 --- a/test/fixers/test_isort_fixer_callback.vader +++ b/test/fixers/test_isort_fixer_callback.vader @@ -25,5 +25,8 @@ Execute(The isort callback should return the correct default values): silent execute 'file ' . fnameescape(g:dir . '/python_paths/with_virtualenv/subdir/foo/bar.py') AssertEqual - \ {'command': ale#Escape(ale#path#Simplify(g:dir . '/python_paths/with_virtualenv/env/' . b:bin_dir . '/isort')) . ' -' }, + \ { + \ 'command': 'cd ' . ale#Escape(ale#path#Simplify(g:dir . '/python_paths/with_virtualenv/subdir/foo')) . ' && ' + \ . ale#Escape(ale#path#Simplify(g:dir . '/python_paths/with_virtualenv/env/' . b:bin_dir . '/isort')) . ' -', + \ }, \ ale#fixers#isort#Fix(bufnr('')) From 33b3331b0499e502f01730af60fb0e9b5a30951f Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 4 Feb 2018 13:55:09 +0000 Subject: [PATCH 35/69] #1206 Add support for setting options for gobuild, and escape paths better --- ale_linters/go/gobuild.vim | 21 ++++++-- doc/ale-go.txt | 12 +++++ doc/ale.txt | 1 + .../test_gobuild_command_callback.vader | 52 +++++++++++++++++++ 4 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 test/command_callback/test_gobuild_command_callback.vader diff --git a/ale_linters/go/gobuild.vim b/ale_linters/go/gobuild.vim index 783b9e0..068877a 100644 --- a/ale_linters/go/gobuild.vim +++ b/ale_linters/go/gobuild.vim @@ -1,9 +1,14 @@ " Author: Joshua Rubin , Ben Reedy , " Jeff Willette " Description: go build for Go files - " inspired by work from dzhou121 +call ale#Set('go_gobuild_options', '') + +function! ale_linters#go#gobuild#ResetEnv() abort + unlet! s:go_env +endfunction + function! ale_linters#go#gobuild#GoEnv(buffer) abort if exists('s:go_env') return '' @@ -13,6 +18,8 @@ function! ale_linters#go#gobuild#GoEnv(buffer) abort endfunction function! ale_linters#go#gobuild#GetCommand(buffer, goenv_output) abort + let l:options = ale#Var(a:buffer, 'go_gobuild_options') + if !exists('s:go_env') let s:go_env = { \ 'GOPATH': a:goenv_output[0], @@ -20,10 +27,16 @@ function! ale_linters#go#gobuild#GetCommand(buffer, goenv_output) abort \} endif + let l:gopath_env_command = has('win32') + \ ? 'set GOPATH=' . ale#Escape(s:go_env.GOPATH) . ' && ' + \ : 'GOPATH=' . ale#Escape(s:go_env.GOPATH) . ' ' + " Run go test in local directory with relative path - return 'GOPATH=' . s:go_env.GOPATH - \ . ' cd ' . fnamemodify(bufname(a:buffer), ':.:h') - \ . ' && go test -c -o /dev/null ./' + return l:gopath_env_command + \ . ale#path#BufferCdString(a:buffer) + \ . 'go test' + \ . (!empty(l:options) ? ' ' . l:options : '') + \ . ' -c -o /dev/null ./' endfunction function! ale_linters#go#gobuild#GetMatches(lines) abort diff --git a/doc/ale-go.txt b/doc/ale-go.txt index c5a6887..502f237 100644 --- a/doc/ale-go.txt +++ b/doc/ale-go.txt @@ -20,6 +20,18 @@ the benefit of running a number of linters, more than ALE would by default, while ensuring it doesn't run any linters known to be slow or resource intensive. +=============================================================================== +gobuild *ale-go-gobuild* + +g:ale_go_gobuild_options *g:ale_go_gobuild_options* + *b:ale_go_gobuild_options* + Type: |String| + Default: `''` + + This variable can be set to pass additional options to the gobuild linter. + They are injected directly after "go test". + + =============================================================================== gofmt *ale-go-gofmt* diff --git a/doc/ale.txt b/doc/ale.txt index 2644ebc..6ace9d5 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -77,6 +77,7 @@ CONTENTS *ale-contents* glslang.............................|ale-glsl-glslang| glslls..............................|ale-glsl-glslls| go....................................|ale-go-options| + gobuild.............................|ale-go-gobuild| gofmt...............................|ale-go-gofmt| gometalinter........................|ale-go-gometalinter| graphql...............................|ale-graphql-options| diff --git a/test/command_callback/test_gobuild_command_callback.vader b/test/command_callback/test_gobuild_command_callback.vader new file mode 100644 index 0000000..240f29c --- /dev/null +++ b/test/command_callback/test_gobuild_command_callback.vader @@ -0,0 +1,52 @@ +Before: + Save g:ale_go_gobuild_options + + unlet! g:ale_go_gobuild_options + + let g:env_prefix = has('win32') + \ ? 'set GOPATH=' . ale#Escape('/foo/bar') . ' && ' + \ : 'GOPATH=' . ale#Escape('/foo/bar') . ' ' + + runtime ale_linters/go/gobuild.vim + + call ale#test#SetDirectory('/testplugin/test/command_callback') + + call ale_linters#go#gobuild#ResetEnv() + +After: + Restore + + unlet! g:env_prefix + + call ale#linter#Reset() + call ale#test#RestoreDirectory() + +Execute(The default gobuild command should be correct): + AssertEqual + \ ale_linters#go#gobuild#GetCommand(bufnr(''), ['/foo/bar', '/foo/baz']), + \ g:env_prefix . 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' + \ . 'go test -c -o /dev/null ./' + +Execute(The command for getting GOPATH should be correct): + AssertEqual ale_linters#go#gobuild#GoEnv(bufnr('')), 'go env GOPATH GOROOT' + + call ale_linters#go#gobuild#GetCommand(bufnr(''), ['/foo/bar', '/foo/baz']) + + " We shouldn't run `go env` many times after we've got it. + AssertEqual ale_linters#go#gobuild#GoEnv(bufnr('')), '' + +Execute(The GOPATH output should be used after it has been read once): + call ale_linters#go#gobuild#GetCommand(bufnr(''), ['/foo/bar', '/foo/baz']) + + AssertEqual + \ ale_linters#go#gobuild#GetCommand(bufnr(''), []), + \ g:env_prefix . 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' + \ . 'go test -c -o /dev/null ./' + +Execute(Extra options should be supported): + let g:ale_go_gobuild_options = '--foo-bar' + + AssertEqual + \ ale_linters#go#gobuild#GetCommand(bufnr(''), ['/foo/bar', '/foo/baz']), + \ g:env_prefix . 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' + \ . 'go test --foo-bar -c -o /dev/null ./' From dda132c1a2818390cafd674e5db0e3b6ce802965 Mon Sep 17 00:00:00 2001 From: Fenner Macrae <13209544+fennerm@users.noreply.github.com> Date: Sun, 4 Feb 2018 10:57:52 -0800 Subject: [PATCH 36/69] Add lint_package support to lintr --- ale_linters/r/lintr.vim | 14 ++++++++++++-- doc/ale-r.txt | 9 +++++++++ .../test_lintr_command_callback.vader | 12 ++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/ale_linters/r/lintr.vim b/ale_linters/r/lintr.vim index e163905..006bf47 100644 --- a/ale_linters/r/lintr.vim +++ b/ale_linters/r/lintr.vim @@ -1,13 +1,23 @@ -" Author: Michel Lang , w0rp +" Author: Michel Lang , w0rp , +" Fenner Macrae " Description: This file adds support for checking R code with lintr. let g:ale_r_lintr_options = get(g:, 'ale_r_lintr_options', 'with_defaults()') " A reasonable alternative default: " get(g:, 'ale_r_lintr_options', 'with_defaults(object_usage_linter = NULL)') + +let g:ale_r_lintr_lint_package = get(g:, 'ale_r_lintr_lint_package', 0) + function! ale_linters#r#lintr#GetCommand(buffer) abort + if ale#Var(a:buffer, 'r_lintr_lint_package') + let l:lint_cmd = 'lint_package' + else + let l:lint_cmd = 'lint' + endif + let l:cmd_string = 'suppressPackageStartupMessages(library(lintr));' - \ . 'lint(cache = FALSE, commandArgs(TRUE),' + \ . l:lint_cmd . '(cache = FALSE, commandArgs(TRUE),' \ . ale#Var(a:buffer, 'r_lintr_options') . ')' return ale#path#BufferCdString(a:buffer) diff --git a/doc/ale-r.txt b/doc/ale-r.txt index 6372f80..f85f48f 100644 --- a/doc/ale-r.txt +++ b/doc/ale-r.txt @@ -16,5 +16,14 @@ g:ale_r_lintr_options *g:ale_r_lintr_options* options. Consult the lintr documentation for more information. +g:ale_r_lintr_lint_package *g:ale_r_lintr_lint_package* + *b:ale_r_lintr_lint_package* + Type: |Number| + Default: `0` + + When set to `1`, the file will be checked with `lintr::lint_package` instead + of `lintr::lint`. This prevents erroneous namespace warnings when linting + package files. + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/test/command_callback/test_lintr_command_callback.vader b/test/command_callback/test_lintr_command_callback.vader index 256618c..33259e0 100644 --- a/test/command_callback/test_lintr_command_callback.vader +++ b/test/command_callback/test_lintr_command_callback.vader @@ -34,3 +34,15 @@ Execute(The lintr options should be configurable): \ . 'with_defaults(object_usage_linter = NULL))') \ . ' %t', \ ale_linters#r#lintr#GetCommand(bufnr('')) + +Execute(If the lint_package flag is set, lintr::lint_package should be called): + let b:ale_r_lintr_lint_package = 1 + + AssertEqual + \ 'cd ' . ale#Escape(getcwd()) . ' && ' + \ . 'Rscript -e ' + \ . ale#Escape('suppressPackageStartupMessages(library(lintr));' + \ . 'lint_package(cache = FALSE, commandArgs(TRUE),' + \ . 'with_defaults())') + \ . ' %t', + \ ale_linters#r#lintr#GetCommand(bufnr('')) From 5dc884b24dff08e48287134f903b8ff5e93b33cb Mon Sep 17 00:00:00 2001 From: Fenner Macrae <13209544+fennerm@users.noreply.github.com> Date: Mon, 5 Feb 2018 09:54:15 -0800 Subject: [PATCH 37/69] Fixed lintr::lint_package command --- ale_linters/r/lintr.vim | 9 +++++---- test/command_callback/test_lintr_command_callback.vader | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ale_linters/r/lintr.vim b/ale_linters/r/lintr.vim index 006bf47..ac1d856 100644 --- a/ale_linters/r/lintr.vim +++ b/ale_linters/r/lintr.vim @@ -11,14 +11,15 @@ let g:ale_r_lintr_lint_package = get(g:, 'ale_r_lintr_lint_package', 0) function! ale_linters#r#lintr#GetCommand(buffer) abort if ale#Var(a:buffer, 'r_lintr_lint_package') - let l:lint_cmd = 'lint_package' + let l:lint_cmd = 'lint_package(cache = FALSE, linters = ' + \ . ale#Var(a:buffer, 'r_lintr_options') . ')' else - let l:lint_cmd = 'lint' + let l:lint_cmd = 'lint(cache = FALSE, commandArgs(TRUE), ' + \ . ale#Var(a:buffer, 'r_lintr_options') . ')' endif let l:cmd_string = 'suppressPackageStartupMessages(library(lintr));' - \ . l:lint_cmd . '(cache = FALSE, commandArgs(TRUE),' - \ . ale#Var(a:buffer, 'r_lintr_options') . ')' + \ . l:lint_cmd return ale#path#BufferCdString(a:buffer) \ . 'Rscript -e ' diff --git a/test/command_callback/test_lintr_command_callback.vader b/test/command_callback/test_lintr_command_callback.vader index 33259e0..e655328 100644 --- a/test/command_callback/test_lintr_command_callback.vader +++ b/test/command_callback/test_lintr_command_callback.vader @@ -18,7 +18,7 @@ Execute(The default lintr command should be correct): \ 'cd ' . ale#Escape(getcwd()) . ' && ' \ . 'Rscript -e ' \ . ale#Escape('suppressPackageStartupMessages(library(lintr));' - \ . 'lint(cache = FALSE, commandArgs(TRUE),' + \ . 'lint(cache = FALSE, commandArgs(TRUE), ' \ . 'with_defaults())') \ . ' %t', \ ale_linters#r#lintr#GetCommand(bufnr('')) @@ -30,7 +30,7 @@ Execute(The lintr options should be configurable): \ 'cd ' . ale#Escape(getcwd()) . ' && ' \ . 'Rscript -e ' \ . ale#Escape('suppressPackageStartupMessages(library(lintr));' - \ . 'lint(cache = FALSE, commandArgs(TRUE),' + \ . 'lint(cache = FALSE, commandArgs(TRUE), ' \ . 'with_defaults(object_usage_linter = NULL))') \ . ' %t', \ ale_linters#r#lintr#GetCommand(bufnr('')) @@ -42,7 +42,7 @@ Execute(If the lint_package flag is set, lintr::lint_package should be called): \ 'cd ' . ale#Escape(getcwd()) . ' && ' \ . 'Rscript -e ' \ . ale#Escape('suppressPackageStartupMessages(library(lintr));' - \ . 'lint_package(cache = FALSE, commandArgs(TRUE),' - \ . 'with_defaults())') + \ . 'lint_package(cache = FALSE, ' + \ . 'linters = with_defaults())') \ . ' %t', \ ale_linters#r#lintr#GetCommand(bufnr('')) From c2ab8853849d1fc64d448d6e65920c988ca9c0fa Mon Sep 17 00:00:00 2001 From: Fenner Macrae <13209544+fennerm@users.noreply.github.com> Date: Mon, 5 Feb 2018 11:33:23 -0800 Subject: [PATCH 38/69] Removed trailing whitespaces --- ale_linters/r/lintr.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ale_linters/r/lintr.vim b/ale_linters/r/lintr.vim index ac1d856..51e5c56 100644 --- a/ale_linters/r/lintr.vim +++ b/ale_linters/r/lintr.vim @@ -11,7 +11,7 @@ let g:ale_r_lintr_lint_package = get(g:, 'ale_r_lintr_lint_package', 0) function! ale_linters#r#lintr#GetCommand(buffer) abort if ale#Var(a:buffer, 'r_lintr_lint_package') - let l:lint_cmd = 'lint_package(cache = FALSE, linters = ' + let l:lint_cmd = 'lint_package(cache = FALSE, linters = ' \ . ale#Var(a:buffer, 'r_lintr_options') . ')' else let l:lint_cmd = 'lint(cache = FALSE, commandArgs(TRUE), ' @@ -19,7 +19,7 @@ function! ale_linters#r#lintr#GetCommand(buffer) abort endif let l:cmd_string = 'suppressPackageStartupMessages(library(lintr));' - \ . l:lint_cmd + \ . l:lint_cmd return ale#path#BufferCdString(a:buffer) \ . 'Rscript -e ' From 716b46e10d2abe54daa09e876d4b7a6b56024ad0 Mon Sep 17 00:00:00 2001 From: Kevin Tindall Date: Sat, 10 Feb 2018 13:04:43 -0600 Subject: [PATCH 39/69] functional pony linter --- README.md | 1 + ale_linters/pony/ponyc.vim | 21 ++++++++++++ autoload/ale/handlers/pony.vim | 34 +++++++++++++++++++ doc/ale-pony.txt | 25 ++++++++++++++ doc/ale.txt | 3 ++ .../test_pony_ponyc_command_callbacks.vader | 23 +++++++++++++ test/handler/test_pony_handler.vader | 21 ++++++++++++ 7 files changed, 128 insertions(+) create mode 100644 ale_linters/pony/ponyc.vim create mode 100644 autoload/ale/handlers/pony.vim create mode 100644 doc/ale-pony.txt create mode 100644 test/command_callback/test_pony_ponyc_command_callbacks.vader create mode 100644 test/handler/test_pony_handler.vader diff --git a/README.md b/README.md index b09a643..0a0e0d9 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ formatting. | PHP | [hack](http://hacklang.org/), [hackfmt](https://github.com/facebook/flow/tree/master/hack/hackfmt), [langserver](https://github.com/felixfbecker/php-language-server), [phan](https://github.com/phan/phan) see `:help ale-php-phan` to instructions, [php -l](https://secure.php.net/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer), [phpmd](https://phpmd.org), [phpstan](https://github.com/phpstan/phpstan), [phpcbf](https://github.com/squizlabs/PHP_CodeSniffer) | | PO | [alex](https://github.com/wooorm/alex) !!, [msgfmt](https://www.gnu.org/software/gettext/manual/html_node/msgfmt-Invocation.html), [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | | Pod | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | +| Pony | [ponyc](https://github.com/ponylang/ponyc) | | proto | [protoc-gen-lint](https://github.com/ckaznocha/protoc-gen-lint) | | Pug | [pug-lint](https://github.com/pugjs/pug-lint) | | Puppet | [puppet](https://puppet.com), [puppet-lint](https://puppet-lint.com) | diff --git a/ale_linters/pony/ponyc.vim b/ale_linters/pony/ponyc.vim new file mode 100644 index 0000000..4120df5 --- /dev/null +++ b/ale_linters/pony/ponyc.vim @@ -0,0 +1,21 @@ +" Description: ponyc linter for pony files + +call ale#Set('pony_ponyc_executable', 'ponyc') +call ale#Set('pony_ponyc_options', '--pass paint') + +function! ale_linters#pony#ponyc#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'pony_ponyc_executable') +endfunction + +function! ale_linters#pony#ponyc#GetCommand(buffer) abort + return ale_linters#pony#ponyc#GetExecutable(a:buffer) + \ . ' ' . ale#Var(a:buffer, 'pony_ponyc_options') +endfunction + +call ale#linter#Define('pony', { +\ 'name': 'ponyc', +\ 'output_stream': 'stderr', +\ 'executable_callback': 'ale_linters#pony#ponyc#GetExecutable', +\ 'command_callback': 'ale_linters#pony#ponyc#GetCommand', +\ 'callback': 'ale#handlers#pony#HandlePonycFormat', +\}) diff --git a/autoload/ale/handlers/pony.vim b/autoload/ale/handlers/pony.vim new file mode 100644 index 0000000..0ac18e7 --- /dev/null +++ b/autoload/ale/handlers/pony.vim @@ -0,0 +1,34 @@ +scriptencoding utf-8 +" Description: This file defines a handler function which ought to work for +" any program which outputs errors in the format that ponyc uses. + +function! s:RemoveUnicodeQuotes(text) abort + let l:text = a:text + let l:text = substitute(l:text, '[`´‘’]', '''', 'g') + let l:text = substitute(l:text, '\v\\u2018([^\\]+)\\u2019', '''\1''', 'g') + let l:text = substitute(l:text, '[“”]', '"', 'g') + + return l:text +endfunction + +function! ale#handlers#pony#HandlePonycFormat(buffer, lines) abort + " Look for lines like the following. + " /home/code/pony/classes/Wombat.pony:22:30: can't lookup private fields from outside the type + + let l:pattern = '\v^([^:]+):(\d+):(\d+)?:? (.+)$' + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + let l:item = { + \ 'filename': l:match[1], + \ 'lnum': str2nr(l:match[2]), + \ 'col': str2nr(l:match[3]), + \ 'type': 'E', + \ 'text': s:RemoveUnicodeQuotes(l:match[4]), + \} + + call add(l:output, l:item) + endfor + + return l:output +endfunction diff --git a/doc/ale-pony.txt b/doc/ale-pony.txt new file mode 100644 index 0000000..3b32168 --- /dev/null +++ b/doc/ale-pony.txt @@ -0,0 +1,25 @@ +=============================================================================== +ALE Pony Integration *ale-pony-options* + + +=============================================================================== +ponyc *ale-pony-ponyc* + +g:ale_pony_ponyc_executable *g:ale_pony_ponyc_executable* + *b:ale_pony_ponyc_executable* + Type: |String| + Default: `'ponyc'` + + See |ale-integrations-local-executables| + + +g:ale_pony_ponyc_options *g:ale_pony_ponyc_options* + *b:ale_pony_ponyc_options* + Type: |String| + Default: `'--pass paint'` + + This variable can be set to pass options to ponyc. + + +=============================================================================== + vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index 6ace9d5..296d640 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -160,6 +160,8 @@ CONTENTS *ale-contents* write-good..........................|ale-po-write-good| pod...................................|ale-pod-options| write-good..........................|ale-pod-write-good| + pony..................................|ale-pony-options| + ponyc...............................|ale-pony-ponyc| proto.................................|ale-proto-options| protoc-gen-lint.....................|ale-proto-protoc-gen-lint| pug...................................|ale-pug-options| @@ -349,6 +351,7 @@ Notes: * PHP: `hack`, `hackfmt`, `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf` * PO: `alex`!!, `msgfmt`, `proselint`, `write-good` * Pod: `alex`!!, `proselint`, `write-good` +* Pony: `ponyc` * proto: `protoc-gen-lint` * Pug: `pug-lint` * Puppet: `puppet`, `puppet-lint` diff --git a/test/command_callback/test_pony_ponyc_command_callbacks.vader b/test/command_callback/test_pony_ponyc_command_callbacks.vader new file mode 100644 index 0000000..e48346e --- /dev/null +++ b/test/command_callback/test_pony_ponyc_command_callbacks.vader @@ -0,0 +1,23 @@ +Before: + Save g:ale_pony_ponyc_options + + unlet! g:ale_pony_ponyc_options + unlet! b:ale_pony_ponyc_options + + runtime ale_linters/pony/ponyc.vim + +After: + Restore + unlet! b:ale_pony_ponyc_options + call ale#linter#Reset() + +Execute(The options should be used in the command): + AssertEqual + \ 'ponyc --pass paint', + \ ale_linters#pony#ponyc#GetCommand(bufnr('')) + + let b:ale_pony_ponyc_options = 'foobar' + + AssertEqual + \ 'ponyc foobar', + \ ale_linters#pony#ponyc#GetCommand(bufnr('')) diff --git a/test/handler/test_pony_handler.vader b/test/handler/test_pony_handler.vader new file mode 100644 index 0000000..25a8254 --- /dev/null +++ b/test/handler/test_pony_handler.vader @@ -0,0 +1,21 @@ +Execute(The pony handler should handle ponyc output): + call ale#test#SetFilename('foo.pony') + + AssertEqual + \ [ + \ { + \ 'filename': '/home/projects/Wombat.pony', + \ 'lnum': 22, + \ 'type': 'E', + \ 'col': 30, + \ 'text': 'can''t lookup private fields from outside the type', + \ }, + \ ], + \ ale#handlers#pony#HandlePonycFormat(bufnr(''), [ + \ 'Building builtin -> /usr/lib/pony/0.21.3/packages/builtin', + \ 'Building . -> /home/projects', + \ 'Error:', + \ '/home/projects/Wombat.pony:22:30: can''t lookup private fields from outside the type', + \ ' env.out.print(defaultWombat._hunger_level)', + \ ' ^', + \ ]) From f979da54d417a0e390c686d9a02e63a2439cfc3f Mon Sep 17 00:00:00 2001 From: Dennis Falling Date: Mon, 12 Feb 2018 22:52:39 -0500 Subject: [PATCH 40/69] Fix reason help reference `ale-integration-reason-merlin` doesn't exist, changed to `ale-reasonml-ols` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b09a643..56a53a8 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ formatting. | Puppet | [puppet](https://puppet.com), [puppet-lint](https://puppet-lint.com) | | Python | [autopep8](https://github.com/hhatto/autopep8), [flake8](http://flake8.pycqa.org/en/latest/), [isort](https://github.com/timothycrosley/isort), [mypy](http://mypy-lang.org/), [prospector](http://github.com/landscapeio/prospector), [pycodestyle](https://github.com/PyCQA/pycodestyle), [pyls](https://github.com/palantir/python-language-server), [pylint](https://www.pylint.org/) !!, [yapf](https://github.com/google/yapf) | | R | [lintr](https://github.com/jimhester/lintr) | -| ReasonML | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-integration-reason-merlin` for configuration instructions, [ols](https://github.com/freebroccolo/ocaml-language-server), [refmt](https://github.com/reasonml/reason-cli) | +| ReasonML | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-reasonml-ols` for configuration instructions, [ols](https://github.com/freebroccolo/ocaml-language-server), [refmt](https://github.com/reasonml/reason-cli) | | reStructuredText | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [rstcheck](https://github.com/myint/rstcheck), [vale](https://github.com/ValeLint/vale), [write-good](https://github.com/btford/write-good) | | Re:VIEW | [redpen](http://redpen.cc/) | | RPM spec | [rpmlint](https://github.com/rpm-software-management/rpmlint) (disabled by default; see `:help ale-integration-spec`) | From 5972b9722370e95f48382fc1d696d17a9fa30c85 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 18 Feb 2018 09:44:04 +0000 Subject: [PATCH 41/69] #476 Make F401 a warning and E112 a syntax error --- ale_linters/python/flake8.vim | 11 +++++--- ale_linters/python/pycodestyle.vim | 4 +-- test/handler/test_flake8_handler.vader | 30 +++++++++++++++++++++ test/handler/test_pycodestyle_handler.vader | 15 +++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/ale_linters/python/flake8.vim b/ale_linters/python/flake8.vim index 400e60f..e7bbcfb 100644 --- a/ale_linters/python/flake8.vim +++ b/ale_linters/python/flake8.vim @@ -105,11 +105,16 @@ function! ale_linters#python#flake8#Handle(buffer, lines) abort \ 'type': 'W', \} - if l:code[:0] is# 'F' || l:code is# 'E999' - let l:item.type = 'E' + if l:code[:0] is# 'F' + if l:code isnot# 'F401' + let l:item.type = 'E' + endif elseif l:code[:0] is# 'E' let l:item.type = 'E' - let l:item.sub_type = 'style' + + if l:code isnot# 'E999' && l:code isnot# 'E112' + let l:item.sub_type = 'style' + endif elseif l:code[:0] is# 'W' let l:item.sub_type = 'style' endif diff --git a/ale_linters/python/pycodestyle.vim b/ale_linters/python/pycodestyle.vim index bbecdf0..19f05a5 100644 --- a/ale_linters/python/pycodestyle.vim +++ b/ale_linters/python/pycodestyle.vim @@ -44,8 +44,8 @@ function! ale_linters#python#pycodestyle#Handle(buffer, lines) abort \ 'code': l:match[4], \} - " E999 is not a style error, it's a syntax error. - if l:match[4] is# 'E999' + " E999 and E112 are syntax errors. + if l:match[4] is# 'E999' || l:match[4] is# 'E112' unlet l:item.sub_type endif diff --git a/test/handler/test_flake8_handler.vader b/test/handler/test_flake8_handler.vader index 492941c..efacdfb 100644 --- a/test/handler/test_flake8_handler.vader +++ b/test/handler/test_flake8_handler.vader @@ -214,3 +214,33 @@ Execute(Disabling trailing blank line warnings should work): \ ale_linters#python#flake8#Handle(bufnr(''), [ \ 'foo.py:6:1: W391 blank line at end of file', \ ]) + +Execute(F401 should be a warning): + AssertEqual + \ [ + \ { + \ 'lnum': 6, + \ 'col': 1, + \ 'code': 'F401', + \ 'type': 'W', + \ 'text': 'module imported but unused', + \ }, + \ ], + \ ale_linters#python#flake8#Handle(bufnr(''), [ + \ 'foo.py:6:1: F401 module imported but unused', + \ ]) + +Execute(E112 should be a syntax error): + AssertEqual + \ [ + \ { + \ 'lnum': 6, + \ 'col': 1, + \ 'code': 'E112', + \ 'type': 'E', + \ 'text': 'expected an indented block', + \ }, + \ ], + \ ale_linters#python#flake8#Handle(bufnr(''), [ + \ 'foo.py:6:1: E112 expected an indented block', + \ ]) diff --git a/test/handler/test_pycodestyle_handler.vader b/test/handler/test_pycodestyle_handler.vader index 0fd885d..3664455 100644 --- a/test/handler/test_pycodestyle_handler.vader +++ b/test/handler/test_pycodestyle_handler.vader @@ -137,3 +137,18 @@ Execute(Disabling trailing blank line warnings should work): \ ale_linters#python#pycodestyle#Handle(bufnr(''), [ \ 'foo.py:6:1: W391 blank line at end of file', \ ]) + +Execute(E112 should be a syntax error): + AssertEqual + \ [ + \ { + \ 'lnum': 6, + \ 'col': 1, + \ 'code': 'E112', + \ 'type': 'E', + \ 'text': 'expected an indented block', + \ }, + \ ], + \ ale_linters#python#pycodestyle#Handle(bufnr(''), [ + \ 'foo.py:6:1: E112 expected an indented block', + \ ]) From 5915a0ee39ba04a5a4118d5f71766912a6b87fe9 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 18 Feb 2018 10:06:40 +0000 Subject: [PATCH 42/69] Escape the ponyc executable --- ale_linters/pony/ponyc.vim | 2 +- test/command_callback/test_pony_ponyc_command_callbacks.vader | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ale_linters/pony/ponyc.vim b/ale_linters/pony/ponyc.vim index 4120df5..b332905 100644 --- a/ale_linters/pony/ponyc.vim +++ b/ale_linters/pony/ponyc.vim @@ -8,7 +8,7 @@ function! ale_linters#pony#ponyc#GetExecutable(buffer) abort endfunction function! ale_linters#pony#ponyc#GetCommand(buffer) abort - return ale_linters#pony#ponyc#GetExecutable(a:buffer) + return ale#Escape(ale_linters#pony#ponyc#GetExecutable(a:buffer)) \ . ' ' . ale#Var(a:buffer, 'pony_ponyc_options') endfunction diff --git a/test/command_callback/test_pony_ponyc_command_callbacks.vader b/test/command_callback/test_pony_ponyc_command_callbacks.vader index e48346e..7acbfa9 100644 --- a/test/command_callback/test_pony_ponyc_command_callbacks.vader +++ b/test/command_callback/test_pony_ponyc_command_callbacks.vader @@ -13,11 +13,11 @@ After: Execute(The options should be used in the command): AssertEqual - \ 'ponyc --pass paint', + \ ale#Escape('ponyc') . ' --pass paint', \ ale_linters#pony#ponyc#GetCommand(bufnr('')) let b:ale_pony_ponyc_options = 'foobar' AssertEqual - \ 'ponyc foobar', + \ ale#Escape('ponyc') . ' foobar', \ ale_linters#pony#ponyc#GetCommand(bufnr('')) From 89f8d3e456713846d1ebdd934027ae7a910cf5f8 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 18 Feb 2018 10:13:30 +0000 Subject: [PATCH 43/69] Fix #1336 - Print a friendly message when using invalid function names for fixers --- autoload/ale/fix.vim | 10 ++++++++-- test/fix/test_ale_fix.vader | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim index 62a4f9b..9111db3 100644 --- a/autoload/ale/fix.vim +++ b/autoload/ale/fix.vim @@ -392,7 +392,13 @@ function! s:GetCallbacks() abort endif endif - call add(l:corrected_list, ale#util#GetFunction(l:Item)) + try + call add(l:corrected_list, ale#util#GetFunction(l:Item)) + catch /E475/ + " Rethrow exceptions for failing to get a function so we can print + " a friendly message about it. + throw 'BADNAME ' . v:exception + endtry endfor return l:corrected_list @@ -427,7 +433,7 @@ function! ale#fix#Fix(...) abort try let l:callback_list = s:GetCallbacks() - catch /E700/ + catch /E700\|BADNAME/ let l:function_name = join(split(split(v:exception, ':')[3])) let l:echo_message = printf( \ 'There is no fixer named `%s`. Check :ALEFixSuggest', diff --git a/test/fix/test_ale_fix.vader b/test/fix/test_ale_fix.vader index 817c243..5b66c92 100644 --- a/test/fix/test_ale_fix.vader +++ b/test/fix/test_ale_fix.vader @@ -574,6 +574,16 @@ Execute(ALE should print a message telling you something isn't a valid fixer whe AssertEqual 'There is no fixer named `invalidname`. Check :ALEFixSuggest', GetLastMessage() +Execute(ALE should complain about invalid fixers with minuses in the name): + let g:ale_fixers.testft = ['foo-bar'] + ALEFix + + AssertEqual 'There is no fixer named `foo-bar`. Check :ALEFixSuggest', GetLastMessage() + +Execute(ALE should tolerate valid fixers with minuses in the name): + let g:ale_fixers.testft = ['prettier-standard'] + ALEFix + Execute(Test fixing with chained callbacks): let g:ale_fixers.testft = ['FirstChainCallback'] ALEFix From ab5257c3442f5d5b5236905a4c77f4f09a24d8b5 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Thu, 15 Feb 2018 12:23:36 +0100 Subject: [PATCH 44/69] This fixes issue #936 by linting the whole package --- ale_linters/go/staticcheck.vim | 24 ++++++++++- doc/ale-go.txt | 32 +++++++++++++++ doc/ale.txt | 1 + .../test_staticcheck_command_callback.vader | 41 +++++++++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 test/command_callback/test_staticcheck_command_callback.vader diff --git a/ale_linters/go/staticcheck.vim b/ale_linters/go/staticcheck.vim index 255fd17..ce9e6e3 100644 --- a/ale_linters/go/staticcheck.vim +++ b/ale_linters/go/staticcheck.vim @@ -1,10 +1,32 @@ " Author: Ben Reedy " Description: staticcheck for Go files +call ale#Set('go_staticcheck_options', '') +call ale#Set('go_staticcheck_lint_package', 0) + +function! ale_linters#go#staticcheck#GetCommand(buffer) abort + let l:filename = expand('#' . a:buffer . ':t') + let l:options = ale#Var(a:buffer, 'go_staticcheck_options') + let l:lint_package = ale#Var(a:buffer, 'go_staticcheck_lint_package') + + " BufferCdString is used so that we can be sure the paths output from + " staticcheck can be calculated to absolute paths in the Handler + if l:lint_package + return ale#path#BufferCdString(a:buffer) + \ . 'staticcheck' + \ . (!empty(l:options) ? ' ' . l:options : '') . ' .' + endif + + return ale#path#BufferCdString(a:buffer) + \ . 'staticcheck' + \ . (!empty(l:options) ? ' ' . l:options : '') + \ . ' ' . ale#Escape(l:filename) +endfunction + call ale#linter#Define('go', { \ 'name': 'staticcheck', \ 'executable': 'staticcheck', -\ 'command': 'staticcheck %s', +\ 'command_callback': 'ale_linters#go#staticcheck#GetCommand', \ 'callback': 'ale#handlers#unix#HandleAsWarning', \ 'output_stream': 'both', \ 'lint_file': 1, diff --git a/doc/ale-go.txt b/doc/ale-go.txt index 502f237..b80bd45 100644 --- a/doc/ale-go.txt +++ b/doc/ale-go.txt @@ -20,6 +20,7 @@ the benefit of running a number of linters, more than ALE would by default, while ensuring it doesn't run any linters known to be slow or resource intensive. + =============================================================================== gobuild *ale-go-gobuild* @@ -42,6 +43,7 @@ g:ale_go_gofmt_options *g:ale_go_gofmt_options* This variable can be set to pass additional options to the gofmt fixer. + =============================================================================== gometalinter *ale-go-gometalinter* @@ -71,5 +73,35 @@ g:ale_go_gometalinter_options *g:ale_go_gometalinter_options* number of linters known to be slow or consume a lot of resources. +g:ale_go_gometalinter_package *g:ale_go_gometalinter_package* + *b:ale_go_gometalinter_package* + Type: |Number| + Default: `0` + + When set to `1`, the whole Go package will be checked instead of only the + current file. + + +=============================================================================== +staticcheck *ale-go-staticcheck* + +g:ale_go_staticcheck_options *g:ale_go_staticcheck_options* + *b:ale_go_staticcheck_options* + Type: |String| + Default: `''` + + This variable can be set to pass additional options to the staticcheck + linter. + + +g:ale_go_staticcheck_package *g:ale_go_staticcheck_package* + *b:ale_go_staticcheck_package* + Type: |Number| + Default: `0` + + When set to `1`, the whole Go package will be checked instead of only the + current file. + + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index 6ace9d5..fa0e1c1 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -80,6 +80,7 @@ CONTENTS *ale-contents* gobuild.............................|ale-go-gobuild| gofmt...............................|ale-go-gofmt| gometalinter........................|ale-go-gometalinter| + staticcheck.........................|ale-go-staticcheck| graphql...............................|ale-graphql-options| eslint..............................|ale-graphql-eslint| gqlint..............................|ale-graphql-gqlint| diff --git a/test/command_callback/test_staticcheck_command_callback.vader b/test/command_callback/test_staticcheck_command_callback.vader new file mode 100644 index 0000000..e9628eb --- /dev/null +++ b/test/command_callback/test_staticcheck_command_callback.vader @@ -0,0 +1,41 @@ +Before: + Save b:ale_go_staticcheck_options + Save b:ale_go_staticcheck_lint_package + + let b:ale_go_staticcheck_options = '' + let b:ale_go_staticcheck_lint_package = 0 + + runtime ale_linters/go/staticcheck.vim + + call ale#test#SetDirectory('/testplugin/test/command_callback') + call ale#test#SetFilename('test.go') + +After: + Restore + + call ale#test#RestoreDirectory() + call ale#linter#Reset() + +Execute(The staticcheck callback should return the right defaults): + AssertEqual + \ 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' + \ . 'staticcheck ' + \ . ale#Escape(expand('%' . ':t')), + \ ale_linters#go#staticcheck#GetCommand(bufnr('')) + +Execute(The staticcheck callback should use configured options): + let b:ale_go_staticcheck_options = '-test' + + AssertEqual + \ 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' + \ . 'staticcheck ' + \ . '-test ' . ale#Escape(expand('%' . ':t')), + \ ale_linters#go#staticcheck#GetCommand(bufnr('')) + +Execute(The staticcheck `lint_package` option should use the correct command): + let b:ale_go_staticcheck_lint_package = 1 + + AssertEqual + \ 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' + \ . 'staticcheck .', + \ ale_linters#go#staticcheck#GetCommand(bufnr('')) From 8b304f77b7b8efd7a03d51e5b2533631dc646094 Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Fri, 23 Feb 2018 14:43:24 -0800 Subject: [PATCH 45/69] Add Unity project path to Unity example in docs For Ale to recognize the symbols in your project, you need to point it at where Unity builds your assemblies. Add this path to the example. --- doc/ale-cs.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/ale-cs.txt b/doc/ale-cs.txt index 237e848..3a02df6 100644 --- a/doc/ale-cs.txt +++ b/doc/ale-cs.txt @@ -94,6 +94,7 @@ g:ale_cs_mcsc_assemblies *g:ale_cs_mcsc_assemblies* " Compile C# programs with the Unity engine DLL file on Mac. let g:ale_cs_mcsc_assemblies = [ \ '/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll', + \ 'path-to-unityproject/obj/Debug', \] < From 4941bd8d0e5d64dea92892fe52c14d856518462c Mon Sep 17 00:00:00 2001 From: John Eikenberry Date: Sun, 25 Feb 2018 11:39:45 +0000 Subject: [PATCH 46/69] Fix #1358, fix #1369 - Lint the package on save for go vet instead --- ale_linters/go/govet.vim | 29 +++++++++++++++++-- .../test_govet_command_callback.vader | 16 ++++++++++ test/handler/test_govet_handler.vader | 28 ++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 test/command_callback/test_govet_command_callback.vader create mode 100644 test/handler/test_govet_handler.vader diff --git a/ale_linters/go/govet.vim b/ale_linters/go/govet.vim index f5bb47a..aae5969 100644 --- a/ale_linters/go/govet.vim +++ b/ale_linters/go/govet.vim @@ -1,10 +1,35 @@ " Author: neersighted " Description: go vet for Go files +" +" Author: John Eikenberry +" Description: updated to work with go1.10 + +function! ale_linters#go#govet#GetCommand(buffer) abort + return ale#path#BufferCdString(a:buffer) . ' go vet .' +endfunction + +function! ale_linters#go#govet#Handler(buffer, lines) abort + let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):?(\d+)?:? ?(.+)$' + let l:output = [] + let l:dir = expand('#' . a:buffer . ':p:h') + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + call add(l:output, { + \ 'filename': ale#path#GetAbsPath(l:dir, l:match[1]), + \ 'lnum': l:match[2] + 0, + \ 'col': l:match[3] + 0, + \ 'text': l:match[4], + \ 'type': 'E', + \}) + endfor + return l:output +endfunction call ale#linter#Define('go', { \ 'name': 'go vet', \ 'output_stream': 'stderr', \ 'executable': 'go', -\ 'command': 'go vet %t', -\ 'callback': 'ale#handlers#unix#HandleAsError', +\ 'command_callback': 'ale_linters#go#govet#GetCommand', +\ 'callback': 'ale_linters#go#govet#Handler', +\ 'lint_file': 1, \}) diff --git a/test/command_callback/test_govet_command_callback.vader b/test/command_callback/test_govet_command_callback.vader new file mode 100644 index 0000000..a9b2960 --- /dev/null +++ b/test/command_callback/test_govet_command_callback.vader @@ -0,0 +1,16 @@ +Before: + runtime ale_linters/go/govet.vim + + call ale#test#SetDirectory('/testplugin/test/command_callback') + +After: + Restore + + call ale#linter#Reset() + call ale#test#RestoreDirectory() + +Execute(The default command should be correct): + AssertEqual + \ 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' + \ . ' go vet .', + \ ale_linters#go#govet#GetCommand(bufnr('')) diff --git a/test/handler/test_govet_handler.vader b/test/handler/test_govet_handler.vader new file mode 100644 index 0000000..b4bfdc9 --- /dev/null +++ b/test/handler/test_govet_handler.vader @@ -0,0 +1,28 @@ +Before: + runtime ale_linters/go/govet.vim + +After: + call ale#linter#Reset() + +Execute(The govet handler should return the correct filenames): + AssertEqual + \ [ + \ { + \ 'lnum': 27, + \ 'col': 0, + \ 'text': 'some error', + \ 'type': 'E', + \ 'filename': ale#path#Simplify(expand('%:p:h') . '/test.go'), + \ }, + \ { + \ 'lnum': 27, + \ 'col': 5, + \ 'text': 'some error with a column', + \ 'type': 'E', + \ 'filename': ale#path#Simplify(expand('%:p:h') . '/other.go'), + \ }, + \ ], + \ ale_linters#go#govet#Handler(bufnr(''), [ + \ 'test.go:27: some error', + \ 'other.go:27:5: some error with a column', + \ ]) From b5209d31e85bdb5f2f1c7c1bdd9ee6fd42ca9574 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 25 Feb 2018 11:53:36 +0000 Subject: [PATCH 47/69] go vet can only check files now --- README.md | 2 +- doc/ale.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dca1db8..9fe00bc 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ formatting. | FusionScript | [fusion-lint](https://github.com/RyanSquared/fusionscript) | | Git Commit Messages | [gitlint](https://github.com/jorisroovers/gitlint) | | GLSL | [glslang](https://github.com/KhronosGroup/glslang), [glslls](https://github.com/svenstaro/glsl-language-server) | -| Go | [gofmt](https://golang.org/cmd/gofmt/), [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports), [go vet](https://golang.org/cmd/vet/), [golint](https://godoc.org/github.com/golang/lint), [gotype](https://godoc.org/golang.org/x/tools/cmd/gotype), [gometalinter](https://github.com/alecthomas/gometalinter) !!, [go build](https://golang.org/cmd/go/) !!, [gosimple](https://github.com/dominikh/go-tools/tree/master/cmd/gosimple) !!, [staticcheck](https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck) !! | +| Go | [gofmt](https://golang.org/cmd/gofmt/), [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports), [go vet](https://golang.org/cmd/vet/) !!, [golint](https://godoc.org/github.com/golang/lint), [gotype](https://godoc.org/golang.org/x/tools/cmd/gotype), [gometalinter](https://github.com/alecthomas/gometalinter) !!, [go build](https://golang.org/cmd/go/) !!, [gosimple](https://github.com/dominikh/go-tools/tree/master/cmd/gosimple) !!, [staticcheck](https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck) !! | | GraphQL | [eslint](http://eslint.org/), [gqlint](https://github.com/happylinks/gqlint), [prettier](https://github.com/prettier/prettier) | | Haml | [haml-lint](https://github.com/brigade/haml-lint) | | Handlebars | [ember-template-lint](https://github.com/rwjblue/ember-template-lint) | diff --git a/doc/ale.txt b/doc/ale.txt index 296d640..ae0f97d 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -322,7 +322,7 @@ Notes: * FusionScript: `fusion-lint` * Git Commit Messages: `gitlint` * GLSL: glslang, `glslls` -* Go: `gofmt`, `goimports`, `go vet`, `golint`, `gotype`, `gometalinter`!!, `go build`!!, `gosimple`!!, `staticcheck`!! +* Go: `gofmt`, `goimports`, `go vet`!!, `golint`, `gotype`, `gometalinter`!!, `go build`!!, `gosimple`!!, `staticcheck`!! * GraphQL: `eslint`, `gqlint`, `prettier` * Haml: `haml-lint` * Handlebars: `ember-template-lint` From 0ddf16194d8f1b272127c5a6b2d84b5345757b17 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 25 Feb 2018 12:43:13 +0000 Subject: [PATCH 48/69] Fix #1306 - Tell users how to automatically close the loclist window in the documentation --- doc/ale.txt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/doc/ale.txt b/doc/ale.txt index ad4a960..999d2af 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -921,10 +921,10 @@ g:ale_keep_list_window_open *g:ale_keep_list_window_open* Type: |Number| Default: `0` - When set to `1`, this option will keep the loclist or quickfix windows - event after all warnings/errors have been removed for files. By default - the loclist or quicfix windows will be closed automatically when there - are no warnings or errors. + When set to `1`, this option will keep the loclist or quickfix windows event + after all warnings/errors have been removed for files. By default the + loclist or quickfix windows will be closed automatically when there are no + warnings or errors. See |g:ale_open_list| @@ -1215,10 +1215,19 @@ g:ale_open_list *g:ale_open_list* The window will be kept open until all warnings or errors are cleared, including those not set by ALE, unless |g:ale_keep_list_window_open| is set - to `1`, in which case the window will be kept open until closed manually. + to `1`, in which case the window will be kept open when no problems are + found. The window size can be configured with |g:ale_list_window_size|. + If you want to close the loclist window automatically when the buffer is + closed, you can set up the following |autocmd| command: > + + augroup CloseLoclistWindowGroup + autocmd! + autocmd QuitPre * if empty(&buftype) | lclose | endif + augroup END +< g:ale_pattern_options *g:ale_pattern_options* From 478a2883a6c75e888bce2b0e7c800d5d8990f29e Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 25 Feb 2018 12:57:54 +0000 Subject: [PATCH 49/69] #1363 Make ale#engine#IsCheckingBuffer part of the public API --- autoload/ale/engine.vim | 2 ++ doc/ale.txt | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 8c3d4c7..a21eecd 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -76,6 +76,8 @@ function! ale#engine#InitBufferInfo(buffer) abort return 0 endfunction +" This function is documented and part of the public API. +" " Return 1 if ALE is busy checking a given buffer function! ale#engine#IsCheckingBuffer(buffer) abort let l:info = get(g:ale_buffer_info, a:buffer, {}) diff --git a/doc/ale.txt b/doc/ale.txt index 999d2af..fd3e489 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1907,6 +1907,13 @@ ale#engine#GetLoclist(buffer) *ale#engine#GetLoclist()* be copied before applying |map()| or |filter()|. +ale#engine#IsCheckingBuffer(buffer) *ale#engine#IsCheckingBuffer()* + + Given a buffer number, returns `1` when ALE is busy checking that buffer. + + This function can be used for status lines, tab names, etc. + + ale#engine#ManageFile(buffer, filename) *ale#engine#ManageFile()* Given a buffer number for a buffer currently running some linting tasks From 82f8a04e18000bc3311340f820edfc98005e99a9 Mon Sep 17 00:00:00 2001 From: Christian-Gibbons Date: Sun, 25 Feb 2018 09:11:04 -0500 Subject: [PATCH 50/69] New linter: Flawfinder (#1361) * Flawfinder support added for C and C++ A minor modification to gcc handler was made to support flawfinder's single-line output format that does not have a space following the colon denoting the warning level. gcc handler still passes its Vader tests after this modification. * Documentation fixes * Revert documentation regression * Added Flawfinder to table of contents * Removed trailing whitespace * Follow ALE conventions better Added additional documentation and Vader tests --- README.md | 4 +- ale_linters/c/flawfinder.vim | 30 +++++++++++ ale_linters/cpp/flawfinder.vim | 30 +++++++++++ autoload/ale/handlers/gcc.vim | 2 +- doc/ale-c.txt | 27 ++++++++++ doc/ale-cpp.txt | 27 ++++++++++ doc/ale.txt | 6 ++- .../test_c_flawfinder_command_callbacks.vader | 51 +++++++++++++++++++ ...est_cpp_flawfinder_command_callbacks.vader | 51 +++++++++++++++++++ 9 files changed, 223 insertions(+), 5 deletions(-) create mode 100644 ale_linters/c/flawfinder.vim create mode 100644 ale_linters/cpp/flawfinder.vim create mode 100644 test/command_callback/test_c_flawfinder_command_callbacks.vader create mode 100644 test/command_callback/test_cpp_flawfinder_command_callbacks.vader diff --git a/README.md b/README.md index 9fe00bc..3857e32 100644 --- a/README.md +++ b/README.md @@ -79,8 +79,8 @@ formatting. | Awk | [gawk](https://www.gnu.org/software/gawk/)| | Bash | shell [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set), [shellcheck](https://www.shellcheck.net/), [shfmt](https://github.com/mvdan/sh) | | Bourne Shell | shell [-n flag](http://linux.die.net/man/1/sh), [shellcheck](https://www.shellcheck.net/), [shfmt](https://github.com/mvdan/sh) | -| C | [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint), [gcc](https://gcc.gnu.org/), [clang](http://clang.llvm.org/), [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html)| -| C++ (filetype cpp) | [clang](http://clang.llvm.org/), [clangcheck](http://clang.llvm.org/docs/ClangCheck.html) !!, [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html), [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint) !!, [gcc](https://gcc.gnu.org/) | +| C | [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint), [clang](http://clang.llvm.org/), [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html), [flawfinder](https://www.dwheeler.com/flawfinder/), [gcc](https://gcc.gnu.org/) | +| C++ (filetype cpp) | [clang](http://clang.llvm.org/), [clangcheck](http://clang.llvm.org/docs/ClangCheck.html) !!, [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html), [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint) !!, [flawfinder](https://www.dwheeler.com/flawfinder/), [gcc](https://gcc.gnu.org/) | | CUDA | [nvcc](http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html) | | 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/) | diff --git a/ale_linters/c/flawfinder.vim b/ale_linters/c/flawfinder.vim new file mode 100644 index 0000000..27f269f --- /dev/null +++ b/ale_linters/c/flawfinder.vim @@ -0,0 +1,30 @@ +" Author: Christian Gibbons +" Description: flawfinder linter for c files + +call ale#Set('c_flawfinder_executable', 'flawfinder') +call ale#Set('c_flawfinder_options', '') +call ale#Set('c_flawfinder_minlevel', 1) + +function! ale_linters#c#flawfinder#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'c_flawfinder_executable') +endfunction + +function! ale_linters#c#flawfinder#GetCommand(buffer) abort + + " Set the minimum vulnerability level for flawfinder to bother with + let l:minlevel = ' --minlevel=' . ale#Var(a:buffer, 'c_flawfinder_minlevel') + + return ale#Escape(ale_linters#c#flawfinder#GetExecutable(a:buffer)) + \ . ' -CDQS' + \ . ale#Var(a:buffer, 'c_flawfinder_options') + \ . l:minlevel + \ . ' %t' +endfunction + +call ale#linter#Define('c', { +\ 'name': 'flawfinder', +\ 'output_stream': 'stdout', +\ 'executable_callback': 'ale_linters#c#flawfinder#GetExecutable', +\ 'command_callback': 'ale_linters#c#flawfinder#GetCommand', +\ 'callback': 'ale#handlers#gcc#HandleGCCFormat', +\}) diff --git a/ale_linters/cpp/flawfinder.vim b/ale_linters/cpp/flawfinder.vim new file mode 100644 index 0000000..a19f596 --- /dev/null +++ b/ale_linters/cpp/flawfinder.vim @@ -0,0 +1,30 @@ +" Author: Christian Gibbons +" Description: flawfinder linter for c++ files + +call ale#Set('cpp_flawfinder_executable', 'flawfinder') +call ale#Set('cpp_flawfinder_options', '') +call ale#Set('cpp_flawfinder_minlevel', 1) + +function! ale_linters#cpp#flawfinder#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'cpp_flawfinder_executable') +endfunction + +function! ale_linters#cpp#flawfinder#GetCommand(buffer) abort + + " Set the minimum vulnerability level for flawfinder to bother with + let l:minlevel = ' --minlevel=' . ale#Var(a:buffer, 'cpp_flawfinder_minlevel') + + return ale#Escape(ale_linters#cpp#flawfinder#GetExecutable(a:buffer)) + \ . ' -CDQS' + \ . ale#Var(a:buffer, 'cpp_flawfinder_options') + \ . l:minlevel + \ . ' %t' +endfunction + +call ale#linter#Define('cpp', { +\ 'name': 'flawfinder', +\ 'output_stream': 'stdout', +\ 'executable_callback': 'ale_linters#cpp#flawfinder#GetExecutable', +\ 'command_callback': 'ale_linters#cpp#flawfinder#GetCommand', +\ 'callback': 'ale#handlers#gcc#HandleGCCFormat', +\}) diff --git a/autoload/ale/handlers/gcc.vim b/autoload/ale/handlers/gcc.vim index 9ec7b11..7f2078a 100644 --- a/autoload/ale/handlers/gcc.vim +++ b/autoload/ale/handlers/gcc.vim @@ -24,7 +24,7 @@ function! ale#handlers#gcc#HandleGCCFormat(buffer, lines) abort " :8:5: warning: conversion lacks type at end of format [-Wformat=] " :10:27: error: invalid operands to binary - (have ‘int’ and ‘char *’) " -:189:7: note: $/${} is unnecessary on arithmetic variables. [SC2004] - let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):(\d+)?:? ([^:]+): (.+)$' + let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):(\d+)?:? ([^:]+): ?(.+)$' let l:output = [] for l:match in ale#util#GetMatches(a:lines, l:pattern) diff --git a/doc/ale-c.txt b/doc/ale-c.txt index fc2c45c..62445de 100644 --- a/doc/ale-c.txt +++ b/doc/ale-c.txt @@ -143,6 +143,33 @@ g:ale_c_cppcheck_options *g:ale_c_cppcheck_options* This variable can be changed to modify flags given to cppcheck. +=============================================================================== +flawfinder *ale-c-flawfinder* + +g:ale_c_flawfinder_executable *g:ale_c_flawfinder_executable* + *g:ale_c_flawfinder_executable* + Type: |String| + Default: `'flawfinder'` + + This variable can be changed to use a different executable for flawfinder. + + +g:ale_c_flawfinder_minlevel *g:ale_c_flawfinder_minlevel* + *b:ale_c_flawfinder_minlevel* + Type: |Number| + Default: `1` + + This variable can be changed to ignore risks under the given risk threshold. + + +g:ale_c_flawfinder_options *g:ale-c-flawfinder* + *b:ale-c-flawfinder* + Type: |String| + Default: `''` + + This variable can be used to pass extra options into the flawfinder command. + + =============================================================================== gcc *ale-c-gcc* diff --git a/doc/ale-cpp.txt b/doc/ale-cpp.txt index cda5768..19ef589 100644 --- a/doc/ale-cpp.txt +++ b/doc/ale-cpp.txt @@ -153,6 +153,33 @@ g:ale_cpp_cpplint_options *g:ale_cpp_cpplint_options* This variable can be changed to modify flags given to cpplint. +=============================================================================== +flawfinder *ale-cpp-flawfinder* + +g:ale_cpp_flawfinder_executable *g:ale_cpp_flawfinder_executable* + *g:ale_cpp_flawfinder_executable* + Type: |String| + Default: `'flawfinder'` + + This variable can be changed to use a different executable for flawfinder. + + +g:ale_cpp_flawfinder_minlevel *g:ale_cpp_flawfinder_minlevel* + *b:ale_cpp_flawfinder_minlevel* + Type: |Number| + Default: `1` + + This variable can be changed to ignore risks under the given risk threshold. + + +g:ale_cpp_flawfinder_options *g:ale-cpp-flawfinder* + *b:ale-cpp-flawfinder* + Type: |String| + Default: `''` + + This variable can be used to pass extra options into the flawfinder command. + + =============================================================================== gcc *ale-cpp-gcc* diff --git a/doc/ale.txt b/doc/ale.txt index fd3e489..d2e050a 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -28,6 +28,7 @@ CONTENTS *ale-contents* clang-format........................|ale-c-clangformat| clangtidy...........................|ale-c-clangtidy| cppcheck............................|ale-c-cppcheck| + flawfinder..........................|ale-c-flawfinder| gcc.................................|ale-c-gcc| chef..................................|ale-chef-options| foodcritic..........................|ale-chef-foodcritic| @@ -42,6 +43,7 @@ CONTENTS *ale-contents* clangtidy...........................|ale-cpp-clangtidy| cppcheck............................|ale-cpp-cppcheck| cpplint.............................|ale-cpp-cpplint| + flawfinder..........................|ale-cpp-flawfinder| gcc.................................|ale-cpp-gcc| c#....................................|ale-cs-options| mcs.................................|ale-cs-mcs| @@ -298,8 +300,8 @@ Notes: * Awk: `gawk` * Bash: `shell` (-n flag), `shellcheck`, `shfmt` * Bourne Shell: `shell` (-n flag), `shellcheck`, `shfmt` -* C: `cppcheck`, `cpplint`!!, `gcc`, `clang`, `clangtidy`!!, `clang-format` -* C++ (filetype cpp): `clang`, `clangcheck`!!, `clangtidy`!!, `clang-format`, `cppcheck`, `cpplint`!!, `gcc` +* C: `cppcheck`, `cpplint`!!, `clang`, `clangtidy`!!, `clang-format`, `flawfinder`, `gcc` +* C++ (filetype cpp): `clang`, `clangcheck`!!, `clangtidy`!!, `clang-format`, `cppcheck`, `cpplint`!!, `flawfinder`, `gcc` * CUDA: `nvcc`!! * C#: `mcs`, `mcsc`!! * Chef: `foodcritic` diff --git a/test/command_callback/test_c_flawfinder_command_callbacks.vader b/test/command_callback/test_c_flawfinder_command_callbacks.vader new file mode 100644 index 0000000..38a602d --- /dev/null +++ b/test/command_callback/test_c_flawfinder_command_callbacks.vader @@ -0,0 +1,51 @@ +Before: + Save g:ale_c_flawfinder_executable + Save g:ale_c_flawfinder_options + Save g:ale_c_flawfinder_minlevel + + unlet! g:ale_c_flawfinder_executable + unlet! b:ale_c_flawfinder_executable + unlet! g:ale_c_flawfinder_options + unlet! b:ale_c_flawfinder_options + unlet! g:ale_c_flawfinder_minlevel + unlet! b:ale_c_flawfinder_minlevel + + runtime ale_linters/c/flawfinder.vim + +After: + unlet! b:ale_c_flawfinder_executable + unlet! b:ale_c_flawfinder_options + unlet! b:ale_c_flawfinder_minlevel + + Restore + call ale#linter#Reset() + +Execute(The flawfinder command should be correct): + AssertEqual + \ ale#Escape('flawfinder') + \ . ' -CDQS --minlevel=1 %t', + \ ale_linters#c#flawfinder#GetCommand(bufnr('')) + +Execute(The minlevel of flawfinder should be configurable): + let b:ale_c_flawfinder_minlevel = 8 + + AssertEqual + \ ale#Escape('flawfinder') + \ . ' -CDQS --minlevel=8 %t', + \ ale_linters#c#flawfinder#GetCommand(bufnr('')) + +Execute(Additional flawfinder options should be configurable): + let b:ale_c_flawfinder_options = ' --foobar' + + AssertEqual + \ ale#Escape('flawfinder') + \ . ' -CDQS --foobar --minlevel=1 %t', + \ ale_linters#c#flawfinder#GetCommand(bufnr('')) + +Execute(The flawfinder exectable should be configurable): + let b:ale_c_flawfinder_executable = 'foo/bar' + + AssertEqual + \ ale#Escape('foo/bar') + \ . ' -CDQS --minlevel=1 %t', + \ ale_linters#c#flawfinder#GetCommand(bufnr('')) diff --git a/test/command_callback/test_cpp_flawfinder_command_callbacks.vader b/test/command_callback/test_cpp_flawfinder_command_callbacks.vader new file mode 100644 index 0000000..8769ec9 --- /dev/null +++ b/test/command_callback/test_cpp_flawfinder_command_callbacks.vader @@ -0,0 +1,51 @@ +Before: + Save g:ale_cpp_flawfinder_executable + Save g:ale_cpp_flawfinder_options + Save g:ale_cpp_flawfinder_minlevel + + unlet! g:ale_cpp_flawfinder_executable + unlet! b:ale_cpp_flawfinder_executable + unlet! g:ale_cpp_flawfinder_options + unlet! b:ale_cpp_flawfinder_options + unlet! g:ale_cpp_flawfinder_minlevel + unlet! b:ale_cpp_flawfinder_minlevel + + runtime ale_linters/cpp/flawfinder.vim + +After: + unlet! b:ale_cpp_flawfinder_executable + unlet! b:ale_cpp_flawfinder_options + unlet! b:ale_cpp_flawfinder_minlevel + + Restore + call ale#linter#Reset() + +Execute(The flawfinder command should be correct): + AssertEqual + \ ale#Escape('flawfinder') + \ . ' -CDQS --minlevel=1 %t', + \ ale_linters#cpp#flawfinder#GetCommand(bufnr('')) + +Execute(The minlevel of flawfinder should be configurable): + let b:ale_cpp_flawfinder_minlevel = 8 + + AssertEqual + \ ale#Escape('flawfinder') + \ . ' -CDQS --minlevel=8 %t', + \ ale_linters#cpp#flawfinder#GetCommand(bufnr('')) + +Execute(Additional flawfinder options should be configurable): + let b:ale_cpp_flawfinder_options = ' --foobar' + + AssertEqual + \ ale#Escape('flawfinder') + \ . ' -CDQS --foobar --minlevel=1 %t', + \ ale_linters#cpp#flawfinder#GetCommand(bufnr('')) + +Execute(The flawfinder exectable should be configurable): + let b:ale_cpp_flawfinder_executable = 'foo/bar' + + AssertEqual + \ ale#Escape('foo/bar') + \ . ' -CDQS --minlevel=1 %t', + \ ale_linters#cpp#flawfinder#GetCommand(bufnr('')) From cfa3e6a92401021e7ea35fff5134cbd3c71524fe Mon Sep 17 00:00:00 2001 From: Koichi Shiraishi Date: Sun, 25 Feb 2018 23:31:38 +0900 Subject: [PATCH 51/69] doc/c: fix duplicate ale_c_flawfinder_executable help tag --- doc/ale-c.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ale-c.txt b/doc/ale-c.txt index 62445de..cf483fb 100644 --- a/doc/ale-c.txt +++ b/doc/ale-c.txt @@ -147,7 +147,7 @@ g:ale_c_cppcheck_options *g:ale_c_cppcheck_options* flawfinder *ale-c-flawfinder* g:ale_c_flawfinder_executable *g:ale_c_flawfinder_executable* - *g:ale_c_flawfinder_executable* + *b:ale_c_flawfinder_executable* Type: |String| Default: `'flawfinder'` From b15706d9a97b12db088cd7c2e1923ca257024ab1 Mon Sep 17 00:00:00 2001 From: Koichi Shiraishi Date: Mon, 26 Feb 2018 00:04:56 +0900 Subject: [PATCH 52/69] doc/cpp: fix duplicate ale_cpp_flawfinder_executable help tag both of 'g:' prefix. --- doc/ale-cpp.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ale-cpp.txt b/doc/ale-cpp.txt index 19ef589..315f293 100644 --- a/doc/ale-cpp.txt +++ b/doc/ale-cpp.txt @@ -157,7 +157,7 @@ g:ale_cpp_cpplint_options *g:ale_cpp_cpplint_options* flawfinder *ale-cpp-flawfinder* g:ale_cpp_flawfinder_executable *g:ale_cpp_flawfinder_executable* - *g:ale_cpp_flawfinder_executable* + *b:ale_cpp_flawfinder_executable* Type: |String| Default: `'flawfinder'` From 7e20d9c63996c9e189651bf687d921e5f20d12cf Mon Sep 17 00:00:00 2001 From: Josh Leeb-du Toit Date: Mon, 26 Feb 2018 14:46:51 +1100 Subject: [PATCH 53/69] Add options for markdown_mdl linter --- ale_linters/markdown/mdl.vim | 17 ++++++++++++++--- doc/ale-markdown.txt | 19 +++++++++++++++++++ doc/ale.txt | 1 + 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/ale_linters/markdown/mdl.vim b/ale_linters/markdown/mdl.vim index f239025..9bb2031 100644 --- a/ale_linters/markdown/mdl.vim +++ b/ale_linters/markdown/mdl.vim @@ -1,5 +1,8 @@ -" Author: Steve Dignam -" Description: Support for mdl, a markdown linter +" Author: Steve Dignam , Josh Leeb-du Toit +" Description: Support for mdl, a markdown linter. + +call ale#Set('markdown_mdl_executable', 'mdl') +call ale#Set('markdown_mdl_options', '') function! ale_linters#markdown#mdl#Handle(buffer, lines) abort " matches: '(stdin):173: MD004 Unordered list style' @@ -17,9 +20,17 @@ function! ale_linters#markdown#mdl#Handle(buffer, lines) abort return l:output endfunction +function! ale_linters#markdown#mdl#GetCommand(buffer) abort + let l:executable = ale#Var(a:buffer, 'markdown_mdl_executable') + let l:options = ale#Var(a:buffer, 'markdown_mdl_options') + + return l:executable . (!empty(l:options) ? ' ' . l:options : '') +endfunction + + call ale#linter#Define('markdown', { \ 'name': 'mdl', \ 'executable': 'mdl', -\ 'command': 'mdl', +\ 'command_callback': 'ale_linters#markdown#mdl#GetCommand', \ 'callback': 'ale_linters#markdown#mdl#Handle' \}) diff --git a/doc/ale-markdown.txt b/doc/ale-markdown.txt index b59f018..9a5290b 100644 --- a/doc/ale-markdown.txt +++ b/doc/ale-markdown.txt @@ -2,6 +2,25 @@ ALE Markdown Integration *ale-markdown-options* +=============================================================================== +mdl *ale-markdown-mdl* + +g:ale_markdown_mdl_executable *g:ale_markdown_mdl_executable* + *b:ale_markdown_mdl_executable* + Type: |String| + Default: `'mdl'` + + See |ale-integrations-local-executables| + + +g:ale_markdown_mdl_options *g:ale_markdown_mdl_options* + *b:ale_markdown_mdl_options* + Type: |String| + Default: `''` + + This variable can be set to pass additional options to mdl. + + =============================================================================== prettier *ale-markdown-prettier* diff --git a/doc/ale.txt b/doc/ale.txt index d2e050a..3acd118 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -136,6 +136,7 @@ CONTENTS *ale-contents* luac................................|ale-lua-luac| luacheck............................|ale-lua-luacheck| markdown..............................|ale-markdown-options| + mdl.................................|ale-markdown-mdl| prettier............................|ale-markdown-prettier| write-good..........................|ale-markdown-write-good| nroff.................................|ale-nroff-options| From f64db199f1c8e4379cc642f6df6de1f70af14a57 Mon Sep 17 00:00:00 2001 From: w0rp Date: Mon, 26 Feb 2018 17:04:54 +0000 Subject: [PATCH 54/69] Fix a typo in the documentation --- doc/ale.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ale.txt b/doc/ale.txt index d2e050a..4e1ae44 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1251,8 +1251,8 @@ g:ale_pattern_options *g:ale_pattern_options* See |b:ale_linters| and |b:ale_fixers| for information for those options. Filenames are matched with |match()|, and patterns depend on the |magic| - setting, unless prefixed with the special escape sequences like `'\v'`, - etc.The patterns can match any part of a filename. The absolute path of the + setting, unless prefixed with the special escape sequences like `'\v'`, etc. + The patterns can match any part of a filename. The absolute path of the filename will be used for matching, taken from `expand('%:p')`. The options for every match for the filename will be applied, with the From aea5de282ec6d7e8ed0a192c8c8eb0dbf6ff85b0 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Wed, 28 Feb 2018 10:26:44 -0500 Subject: [PATCH 55/69] Explain in more detail why perl checks are disabled by default --- doc/ale-perl.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/ale-perl.txt b/doc/ale-perl.txt index 414856b..0a4adff 100644 --- a/doc/ale-perl.txt +++ b/doc/ale-perl.txt @@ -3,6 +3,9 @@ ALE Perl Integration *ale-perl-options* ALE offers a few ways to check Perl code. Checking code with `perl` is disabled by default, as `perl` code cannot be checked without executing it. +Specifically, we use the `-c` flag to see if `perl` code compiles. This does +not execute all of the code in a file, but it does run `BEGIN` and `CHECK` +blocks. See `perl --help` and https://stackoverflow.com/a/12908487/406224 See |g:ale_linters|. From fbbb8c17d9634304fd6d10789e78d00c75b70e07 Mon Sep 17 00:00:00 2001 From: Julien Deniau Date: Thu, 1 Mar 2018 15:41:05 +0100 Subject: [PATCH 56/69] add php-cs-fixer to list of fixers --- README.md | 2 +- autoload/ale/fix/registry.vim | 5 ++ autoload/ale/fixers/php_cs_fixer.vim | 23 ++++++++++ doc/ale-php.txt | 17 +++++++ doc/ale.txt | 3 +- .../project-with-php-cs-fixer/test.php | 0 .../vendor/bin/php-cs-fixer | 0 .../project-without-php-cs-fixer/test.php | 0 test/fixers/test_php_cs_fixer.vader | 46 +++++++++++++++++++ 9 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 autoload/ale/fixers/php_cs_fixer.vim create mode 100644 test/command_callback/php_paths/project-with-php-cs-fixer/test.php create mode 100644 test/command_callback/php_paths/project-with-php-cs-fixer/vendor/bin/php-cs-fixer create mode 100644 test/command_callback/php_paths/project-without-php-cs-fixer/test.php create mode 100644 test/fixers/test_php_cs_fixer.vader diff --git a/README.md b/README.md index 3857e32..e964c65 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ formatting. | Objective-C++ | [clang](http://clang.llvm.org/) | | OCaml | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-ocaml-merlin` for configuration instructions, [ols](https://github.com/freebroccolo/ocaml-language-server) | | Perl | [perl -c](https://perl.org/), [perl-critic](https://metacpan.org/pod/Perl::Critic) | -| PHP | [hack](http://hacklang.org/), [hackfmt](https://github.com/facebook/flow/tree/master/hack/hackfmt), [langserver](https://github.com/felixfbecker/php-language-server), [phan](https://github.com/phan/phan) see `:help ale-php-phan` to instructions, [php -l](https://secure.php.net/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer), [phpmd](https://phpmd.org), [phpstan](https://github.com/phpstan/phpstan), [phpcbf](https://github.com/squizlabs/PHP_CodeSniffer) | +| PHP | [hack](http://hacklang.org/), [hackfmt](https://github.com/facebook/flow/tree/master/hack/hackfmt), [langserver](https://github.com/felixfbecker/php-language-server), [phan](https://github.com/phan/phan) see `:help ale-php-phan` to instructions, [php -l](https://secure.php.net/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer), [phpmd](https://phpmd.org), [phpstan](https://github.com/phpstan/phpstan), [phpcbf](https://github.com/squizlabs/PHP_CodeSniffer), [php-cs-fixer](http://cs.sensiolabs.org/) | | PO | [alex](https://github.com/wooorm/alex) !!, [msgfmt](https://www.gnu.org/software/gettext/manual/html_node/msgfmt-Invocation.html), [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | | Pod | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | | Pony | [ponyc](https://github.com/ponylang/ponyc) | diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 29e263a..3e407c5 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -104,6 +104,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['php'], \ 'description': 'Fix PHP files with phpcbf.', \ }, +\ 'php_cs_fixer': { +\ 'function': 'ale#fixers#php_cs_fixer#Fix', +\ 'suggested_filetypes': ['php'], +\ 'description': 'Fix PHP files with php-cs-fixer.', +\ }, \ 'clang-format': { \ 'function': 'ale#fixers#clangformat#Fix', \ 'suggested_filetypes': ['c', 'cpp'], diff --git a/autoload/ale/fixers/php_cs_fixer.vim b/autoload/ale/fixers/php_cs_fixer.vim new file mode 100644 index 0000000..56aa915 --- /dev/null +++ b/autoload/ale/fixers/php_cs_fixer.vim @@ -0,0 +1,23 @@ +" Author: Julien Deniau +" Description: Fixing files with php-cs-fixer. + +call ale#Set('php_cs_fixer_executable', 'php-cs-fixer') +call ale#Set('php_cs_fixer_use_global', 0) + +function! ale#fixers#php_cs_fixer#GetExecutable(buffer) abort + return ale#node#FindExecutable(a:buffer, 'php_cs_fixer', [ + \ 'vendor/bin/php-cs-fixer', + \ 'php-cs-fixer' + \]) +endfunction + +function! ale#fixers#php_cs_fixer#Fix(buffer) abort + let l:executable = ale#fixers#php_cs_fixer#GetExecutable(a:buffer) + return { + \ 'command': ale#Escape(l:executable) . ' fix %t', + \ 'read_temporary_file': 1, + \} +endfunction + + + diff --git a/doc/ale-php.txt b/doc/ale-php.txt index 455472f..7edfe23 100644 --- a/doc/ale-php.txt +++ b/doc/ale-php.txt @@ -166,5 +166,22 @@ g:ale_php_phpstan_configuration *g:ale_php_phpstan_configuration* This variable sets path to phpstan configuration file. +=============================================================================== +php-cs-fixer *ale-php-php-cs-fixer* + +g:ale_php_cs_fixer_executable *g:ale_php_cs_fixer_executable* + *b:ale_php_cs_fixer_executable* + Type: |String| + Default: `'php-cs-fixer'` + + This variable sets executable used for php-cs-fixer. + +g:ale_php_cs_fixer_use_global *g:ale_php_cs_fixer_use_global* + *b:ale_php_cs_fixer_use_global* + Type: |Boolean| + Default: `0` + + This variable force globally installed fixer. + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index 4e1ae44..76ad058 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -159,6 +159,7 @@ CONTENTS *ale-contents* phpcs...............................|ale-php-phpcs| phpmd...............................|ale-php-phpmd| phpstan.............................|ale-php-phpstan| + php-cs-fixer........................|ale-php-php-cs-fixer| po....................................|ale-po-options| write-good..........................|ale-po-write-good| pod...................................|ale-pod-options| @@ -351,7 +352,7 @@ Notes: * Objective-C++: `clang` * OCaml: `merlin` (see |ale-ocaml-merlin|), `ols` * Perl: `perl -c`, `perl-critic` -* PHP: `hack`, `hackfmt`, `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf` +* PHP: `hack`, `hackfmt`, `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf`, `php-cs-fixer` * PO: `alex`!!, `msgfmt`, `proselint`, `write-good` * Pod: `alex`!!, `proselint`, `write-good` * Pony: `ponyc` diff --git a/test/command_callback/php_paths/project-with-php-cs-fixer/test.php b/test/command_callback/php_paths/project-with-php-cs-fixer/test.php new file mode 100644 index 0000000..e69de29 diff --git a/test/command_callback/php_paths/project-with-php-cs-fixer/vendor/bin/php-cs-fixer b/test/command_callback/php_paths/project-with-php-cs-fixer/vendor/bin/php-cs-fixer new file mode 100644 index 0000000..e69de29 diff --git a/test/command_callback/php_paths/project-without-php-cs-fixer/test.php b/test/command_callback/php_paths/project-without-php-cs-fixer/test.php new file mode 100644 index 0000000..e69de29 diff --git a/test/fixers/test_php_cs_fixer.vader b/test/fixers/test_php_cs_fixer.vader new file mode 100644 index 0000000..b657967 --- /dev/null +++ b/test/fixers/test_php_cs_fixer.vader @@ -0,0 +1,46 @@ +Before: + Save g:ale_php_cs_fixer_executable + let g:ale_php_cs_fixer_executable = 'php-cs-fixer' + + call ale#test#SetDirectory('/testplugin/test/fixers') + silent cd .. + silent cd command_callback + let g:dir = getcwd() + +After: + Restore + + call ale#test#RestoreDirectory() + + +Execute(project with php-cs-fixer should use local by default): + call ale#test#SetFilename('php_paths/project-with-php-cs-fixer/test.php') + + AssertEqual + \ ale#path#Simplify(g:dir . '/php_paths/project-with-php-cs-fixer/vendor/bin/php-cs-fixer'), + \ ale#fixers#php_cs_fixer#GetExecutable(bufnr('')) + +Execute(use-global should override local detection): + let g:ale_php_cs_fixer_use_global = 1 + call ale#test#SetFilename('php_paths/project-with-php-cs-fixer/test.php') + + AssertEqual + \ 'php-cs-fixer', + \ ale#fixers#php_cs_fixer#GetExecutable(bufnr('')) + +Execute(project without php-cs-fixer should use global): + call ale#test#SetFilename('php_paths/project-without-php-cs-fixer/test.php') + + AssertEqual + \ 'php-cs-fixer', + \ ale#fixers#php_cs_fixer#GetExecutable(bufnr('')) + + + + +Execute(The php-cs-fixer callback should return the correct default values): + call ale#test#SetFilename('php_paths/project-without-php-cs-fixer/foo/test.php') + + AssertEqual + \ {'read_temporary_file': 1, 'command': ale#Escape('php-cs-fixer') . ' fix %t' }, + \ ale#fixers#php_cs_fixer#Fix(bufnr('')) From 2096562899aa0994a2c6d2c30320810001d98591 Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 2 Mar 2018 12:10:27 +0000 Subject: [PATCH 57/69] Make updating linter results slightly faster when the list is empty --- autoload/ale/engine.vim | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index a21eecd..9ef3ba3 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -145,35 +145,39 @@ function! s:GatherOutput(job_id, line) abort endfunction function! s:HandleLoclist(linter_name, buffer, loclist) abort - let l:buffer_info = get(g:ale_buffer_info, a:buffer, {}) + let l:info = get(g:ale_buffer_info, a:buffer, {}) - if empty(l:buffer_info) + if empty(l:info) return endif " Remove this linter from the list of active linters. " This may have already been done when the job exits. - call filter(l:buffer_info.active_linter_list, 'v:val isnot# a:linter_name') + call filter(l:info.active_linter_list, 'v:val isnot# a:linter_name') " Make some adjustments to the loclists to fix common problems, and also " to set default values for loclist items. let l:linter_loclist = ale#engine#FixLocList(a:buffer, a:linter_name, a:loclist) " Remove previous items for this linter. - call filter(g:ale_buffer_info[a:buffer].loclist, 'v:val.linter_name isnot# a:linter_name') - " Add the new items. - call extend(g:ale_buffer_info[a:buffer].loclist, l:linter_loclist) + call filter(l:info.loclist, 'v:val.linter_name isnot# a:linter_name') - " Sort the loclist again. - " We need a sorted list so we can run a binary search against it - " for efficient lookup of the messages in the cursor handler. - call sort(g:ale_buffer_info[a:buffer].loclist, 'ale#util#LocItemCompare') + " We don't need to add items or sort the list when this list is empty. + if !empty(l:linter_loclist) + " Add the new items. + call extend(l:info.loclist, l:linter_loclist) + + " Sort the loclist again. + " We need a sorted list so we can run a binary search against it + " for efficient lookup of the messages in the cursor handler. + call sort(l:info.loclist, 'ale#util#LocItemCompare') + endif if ale#ShouldDoNothing(a:buffer) return endif - call ale#engine#SetResults(a:buffer, g:ale_buffer_info[a:buffer].loclist) + call ale#engine#SetResults(a:buffer, l:info.loclist) endfunction function! s:HandleExit(job_id, exit_code) abort From acbe527e15f1f388b8dbc9889216e9368d98e6c6 Mon Sep 17 00:00:00 2001 From: Andrew Crites Date: Fri, 2 Mar 2018 15:22:29 -0500 Subject: [PATCH 58/69] Option to open lists vertically (#1381) * Add configuration option to open lists vertically * Add tests, clean up vertical list config * Vertical list option cleanup * Use is# for tests * Order properties in documentation alphabetically --- README.md | 3 +++ autoload/ale/debugging.vim | 1 + autoload/ale/list.vim | 9 +++++-- doc/ale.txt | 12 +++++++++ plugin/ale.vim | 3 +++ test/test_ale_info.vader | 1 + test/test_list_opening.vader | 51 ++++++++++++++++++++++++++++++++++++ 7 files changed, 78 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3857e32..bbf817d 100644 --- a/README.md +++ b/README.md @@ -577,6 +577,9 @@ let g:ale_open_list = 1 let g:ale_keep_list_window_open = 1 ``` +You can also set `let g:ale_list_vertical = 1` to open the windows vertically +instead of the default horizontally. + ### 5.xii. How can I check JSX files with both stylelint and eslint? diff --git a/autoload/ale/debugging.vim b/autoload/ale/debugging.vim index 9be1fbf..cb93ec1 100644 --- a/autoload/ale/debugging.vim +++ b/autoload/ale/debugging.vim @@ -29,6 +29,7 @@ let s:global_variable_list = [ \ 'ale_linters', \ 'ale_linters_explicit', \ 'ale_list_window_size', +\ 'ale_list_vertical', \ 'ale_loclist_msg_format', \ 'ale_max_buffer_history_size', \ 'ale_max_signs', diff --git a/autoload/ale/list.vim b/autoload/ale/list.vim index b1a8d4a..30b8f5c 100644 --- a/autoload/ale/list.vim +++ b/autoload/ale/list.vim @@ -97,12 +97,17 @@ function! s:SetListsImpl(timer_id, buffer, loclist) abort let l:reset_visual_selection = l:mode is? 'v' || l:mode is# "\" let l:reset_character_selection = l:mode is? 's' || l:mode is# "\" + " open windows vertically instead of default horizontally + let l:open_type = '' + if ale#Var(a:buffer, 'list_vertical') == 1 + let l:open_type = 'vert ' + endif if g:ale_set_quickfix if !ale#list#IsQuickfixOpen() - silent! execute 'copen ' . str2nr(ale#Var(a:buffer, 'list_window_size')) + silent! execute l:open_type . 'copen ' . str2nr(ale#Var(a:buffer, 'list_window_size')) endif elseif g:ale_set_loclist - silent! execute 'lopen ' . str2nr(ale#Var(a:buffer, 'list_window_size')) + silent! execute l:open_type . 'lopen ' . str2nr(ale#Var(a:buffer, 'list_window_size')) endif " If focus changed, restore it (jump to the last window). diff --git a/doc/ale.txt b/doc/ale.txt index 4e1ae44..16e4ba9 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1151,6 +1151,16 @@ g:ale_linters_explicit *g:ale_linters_explicit* as possible, unless otherwise specified. +g:ale_list_vertical *g:ale_list_vertical* + *b:ale_list_vertical* + Type: |Number| + Default: `0` + + When set to `1`, this will cause ALE to open any windows (loclist or + quickfix) vertically instead of horizontally (|vert| |lopen|) or (|vert| + |copen|) + + g:ale_loclist_msg_format *g:ale_loclist_msg_format* b:ale_loclist_msg_format *b:ale_loclist_msg_format* @@ -1222,6 +1232,8 @@ g:ale_open_list *g:ale_open_list* The window size can be configured with |g:ale_list_window_size|. + Windows can be opened vertically with |g:ale_list_vertical|. + If you want to close the loclist window automatically when the buffer is closed, you can set up the following |autocmd| command: > diff --git a/plugin/ale.vim b/plugin/ale.vim index d75d33b..1a473df 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -118,6 +118,9 @@ let g:ale_open_list = get(g:, 'ale_open_list', 0) " This flag dictates if ale keeps open loclist even if there is no error in loclist let g:ale_keep_list_window_open = get(g:, 'ale_keep_list_window_open', 0) +" This flag dictates that quickfix windows should be opened vertically +let g:ale_list_vertical = get(g:, 'ale_list_vertical', 0) + " The window size to set for the quickfix and loclist windows call ale#Set('list_window_size', 10) diff --git a/test/test_ale_info.vader b/test/test_ale_info.vader index e20125a..05c045b 100644 --- a/test/test_ale_info.vader +++ b/test/test_ale_info.vader @@ -66,6 +66,7 @@ Before: \ 'let g:ale_linters = {}', \ 'let g:ale_linters_explicit = 0', \ 'let g:ale_list_window_size = 10', + \ 'let g:ale_list_vertical = 0', \ 'let g:ale_loclist_msg_format = ''%code: %%s''', \ 'let g:ale_max_buffer_history_size = 20', \ 'let g:ale_max_signs = -1', diff --git a/test/test_list_opening.vader b/test/test_list_opening.vader index 63b30ef..a24e8de 100644 --- a/test/test_list_opening.vader +++ b/test/test_list_opening.vader @@ -5,6 +5,7 @@ Before: Save g:ale_open_list Save g:ale_keep_list_window_open Save g:ale_list_window_size + Save g:ale_list_vertical Save g:ale_buffer_info Save g:ale_set_lists_synchronously @@ -13,6 +14,7 @@ Before: let g:ale_open_list = 0 let g:ale_keep_list_window_open = 0 let g:ale_list_window_size = 10 + let g:ale_list_vertical = 0 let g:ale_set_lists_synchronously = 1 let g:loclist = [ @@ -33,16 +35,29 @@ Before: return 0 endfunction + " If the window is vertical, window size should match column size/width + function GetQuickfixIsVertical(cols) abort + for l:win in range(1, winnr('$')) + if getwinvar(l:win, '&buftype') is# 'quickfix' + return winwidth(l:win) == a:cols + endif + endfor + + return 0 + endfunction + After: Restore unlet! g:loclist + unlet! b:ale_list_vertical unlet! b:ale_list_window_size unlet! b:ale_open_list unlet! b:ale_keep_list_window_open unlet! b:ale_save_event_fired delfunction GetQuickfixHeight + delfunction GetQuickfixIsVertical " Close quickfix window after every execute block lcl @@ -98,6 +113,24 @@ Execute(The quickfix window height should be correct for the loclist with buffer AssertEqual 8, GetQuickfixHeight() +Execute(The quickfix window should be vertical for the loclist with appropriate variables): + let g:ale_open_list = 1 + let b:ale_list_window_size = 8 + let b:ale_list_vertical = 1 + + call ale#list#SetLists(bufnr('%'), g:loclist) + + AssertEqual 1, GetQuickfixIsVertical(b:ale_list_window_size) + +Execute(The quickfix window should be horizontal for the loclist with appropriate variables): + let g:ale_open_list = 1 + let b:ale_list_window_size = 8 + let b:ale_list_vertical = 0 + + call ale#list#SetLists(bufnr('%'), g:loclist) + + AssertEqual 0, GetQuickfixIsVertical(b:ale_list_window_size) + Execute(The quickfix window should stay open for just the loclist): let g:ale_open_list = 1 let g:ale_keep_list_window_open = 1 @@ -167,6 +200,24 @@ Execute(The quickfix window height should be correct for the quickfix list with AssertEqual 8, GetQuickfixHeight() +Execute(The quickfix window should be vertical for the quickfix with appropriate variables): + let g:ale_open_list = 1 + let b:ale_list_window_size = 8 + let b:ale_list_vertical = 1 + + call ale#list#SetLists(bufnr('%'), g:loclist) + + AssertEqual 1, GetQuickfixIsVertical(b:ale_list_window_size) + +Execute(The quickfix window should be horizontal for the quickfix with appropriate variables): + let g:ale_open_list = 1 + let b:ale_list_window_size = 8 + let b:ale_list_vertical = 0 + + call ale#list#SetLists(bufnr('%'), g:loclist) + + AssertEqual 0, GetQuickfixIsVertical(b:ale_list_window_size) + Execute(The buffer ale_open_list option should be respected): let b:ale_open_list = 1 From 2c2c7ceb1d2f3de97ba8a40dd7858e83b6755fcd Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 2 Mar 2018 20:33:45 +0000 Subject: [PATCH 59/69] Fix #1384 - Handle warnings and suggestions for tsserver --- autoload/ale/lsp/response.vim | 8 ++++++ test/lsp/test_read_lsp_diagnostics.vader | 35 ++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/autoload/ale/lsp/response.vim b/autoload/ale/lsp/response.vim index 13219ef..5a43128 100644 --- a/autoload/ale/lsp/response.vim +++ b/autoload/ale/lsp/response.vim @@ -59,6 +59,14 @@ function! ale#lsp#response#ReadTSServerDiagnostics(response) abort let l:loclist_item.nr = l:diagnostic.code endif + if get(l:diagnostic, 'category') is# 'warning' + let l:loclist_item.type = 'W' + endif + + if get(l:diagnostic, 'category') is# 'suggestion' + let l:loclist_item.type = 'I' + endif + call add(l:loclist, l:loclist_item) endfor diff --git a/test/lsp/test_read_lsp_diagnostics.vader b/test/lsp/test_read_lsp_diagnostics.vader index 3e63741..444272a 100644 --- a/test/lsp/test_read_lsp_diagnostics.vader +++ b/test/lsp/test_read_lsp_diagnostics.vader @@ -121,7 +121,8 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle multiple messages): \ ]}}) Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle tsserver responses): - AssertEqual [ + AssertEqual + \ [ \ { \ 'type': 'E', \ 'nr': 2365, @@ -131,5 +132,35 @@ Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle tsserver respon \ 'end_lnum': 1, \ 'end_col': 17, \ }, - \], + \ ], \ ale#lsp#response#ReadTSServerDiagnostics({"seq":0,"type":"event","event":"semanticDiag","body":{"file":"/bar/foo.ts","diagnostics":[{"start":{"line":1,"offset":11},"end":{"line":1,"offset":17},"text":"Operator ''+'' cannot be applied to types ''3'' and ''{}''.","code":2365}]}}) + +Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle warnings from tsserver): + AssertEqual + \ [ + \ { + \ 'lnum': 27, + \ 'col': 3, + \ 'nr': 2515, + \ 'end_lnum': 27, + \ 'type': 'W', + \ 'end_col': 14, + \ 'text': 'Calls to ''console.log'' are not allowed. (no-console)', + \ } + \ ], + \ ale#lsp#response#ReadTSServerDiagnostics({"seq":0,"type":"event","event":"semanticDiag","body":{"file":"","diagnostics":[{"start":{"line":27,"offset":3},"end":{"line":27,"offset":14},"text":"Calls to 'console.log' are not allowed. (no-console)","code":2515,"category":"warning","source":"tslint"}]}}) + +Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle suggestions from tsserver): + AssertEqual + \ [ + \ { + \ 'lnum': 27, + \ 'col': 3, + \ 'nr': 2515, + \ 'end_lnum': 27, + \ 'type': 'I', + \ 'end_col': 14, + \ 'text': 'Some info', + \ } + \ ], + \ ale#lsp#response#ReadTSServerDiagnostics({"seq":0,"type":"event","event":"semanticDiag","body":{"file":"","diagnostics":[{"start":{"line":27,"offset":3},"end":{"line":27,"offset":14},"text":"Some info","code":2515,"category":"suggestion","source":"tslint"}]}}) From 540952ca8e46d7be064b020d8ff308b205e7920c Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 2 Mar 2018 20:47:13 +0000 Subject: [PATCH 60/69] Try to fix a test which is failing on Windows --- test/handler/test_mcsc_handler.vader | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/handler/test_mcsc_handler.vader b/test/handler/test_mcsc_handler.vader index ac55ee8..6d6c4ba 100644 --- a/test/handler/test_mcsc_handler.vader +++ b/test/handler/test_mcsc_handler.vader @@ -3,10 +3,14 @@ Before: unlet! g:ale_cs_mcsc_source + call ale#test#SetDirectory('/testplugin/test/handler') + runtime ale_linters/cs/mcsc.vim After: unlet! g:ale_cs_mcsc_source + + call ale#test#RestoreDirectory() call ale#linter#Reset() Execute(The mcs handler should work with the default of the buffer's directory): @@ -18,7 +22,7 @@ Execute(The mcs handler should work with the default of the buffer's directory): \ 'text': '; expected', \ 'code': 'CS1001', \ 'type': 'E', - \ 'filename': ale#path#Simplify(expand('%:p:h') . '/Test.cs'), + \ 'filename': ale#path#Simplify(g:dir . '/Test.cs'), \ }, \ ], \ ale_linters#cs#mcsc#Handle(347, [ From b6bf6ecdbc692f05f0f89eee31018c2d659b35aa Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 2 Mar 2018 20:57:55 +0000 Subject: [PATCH 61/69] Try to fix it again --- ale_linters/cs/mcsc.vim | 2 +- test/handler/test_mcsc_handler.vader | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ale_linters/cs/mcsc.vim b/ale_linters/cs/mcsc.vim index f16e4b4..8a78d3b 100644 --- a/ale_linters/cs/mcsc.vim +++ b/ale_linters/cs/mcsc.vim @@ -10,7 +10,7 @@ function! s:GetWorkingDirectory(buffer) abort return l:working_directory endif - return fnamemodify(bufname(a:buffer), ':p:h') + return expand('#' . a:buffer . ':p:h') endfunction function! ale_linters#cs#mcsc#GetCommand(buffer) abort diff --git a/test/handler/test_mcsc_handler.vader b/test/handler/test_mcsc_handler.vader index 6d6c4ba..8ae4735 100644 --- a/test/handler/test_mcsc_handler.vader +++ b/test/handler/test_mcsc_handler.vader @@ -4,6 +4,7 @@ Before: unlet! g:ale_cs_mcsc_source call ale#test#SetDirectory('/testplugin/test/handler') + call ale#test#SetFilename('Test.cs') runtime ale_linters/cs/mcsc.vim @@ -25,7 +26,7 @@ Execute(The mcs handler should work with the default of the buffer's directory): \ 'filename': ale#path#Simplify(g:dir . '/Test.cs'), \ }, \ ], - \ ale_linters#cs#mcsc#Handle(347, [ + \ ale_linters#cs#mcsc#Handle(bufnr(''), [ \ 'Test.cs(12,29): error CS1001: ; expected', \ 'Compilation failed: 2 error(s), 1 warnings', \ ]) @@ -60,7 +61,7 @@ Execute(The mcs handler should handle cannot find symbol errors): \ 'filename': ale#path#Simplify('/home/foo/project/bar/Test.cs'), \ }, \ ], - \ ale_linters#cs#mcsc#Handle(347, [ + \ ale_linters#cs#mcsc#Handle(bufnr(''), [ \ 'Test.cs(12,29): error CS1001: ; expected', \ 'Test.cs(101,0): error CS1028: Unexpected processor directive (no #if for this #endif)', \ 'Test.cs(10,12): warning CS0123: some warning', From 8a772905539ccfe306219addae5a506def88fe44 Mon Sep 17 00:00:00 2001 From: Olaf Alders Date: Fri, 2 Mar 2018 16:04:52 -0500 Subject: [PATCH 62/69] [WIP] Begin to distinguish between Perl warnings and errors (#933) * If a Perl script compiles, there are only warnings and no errors * Let the first Perl error or warning win. Take the following example: *** sub foo { my $thing; *** This might have the following messages when we compile it: Missing right curly or square bracket at warning.pl line 7, at end of line syntax error at warning.pl line 7, at EOF warning.pl had compilation errors. With the current behaviour, we just get a "syntax error" message, which isn't all that helpful. With this patch we get "Missing right curly or square bracket". * Fix variable scope and pattern matching syntax * Use named variable to enhance clarity when matching Perl output * Add more tests for Perl linter * Remove unnecessary parens * Simplify check for pattern match --- ale_linters/perl/perl.vim | 14 ++++++++-- test/handler/test_perl_handler.vader | 39 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/ale_linters/perl/perl.vim b/ale_linters/perl/perl.vim index fcc88f3..1b9aa95 100644 --- a/ale_linters/perl/perl.vim +++ b/ale_linters/perl/perl.vim @@ -27,12 +27,20 @@ function! ale_linters#perl#perl#Handle(buffer, lines) abort let l:output = [] let l:basename = expand('#' . a:buffer . ':t') + let l:type = 'E' + if a:lines[-1] =~# 'syntax OK' + let l:type = 'W' + endif + + let l:seen = {} + for l:match in ale#util#GetMatches(a:lines, l:pattern) let l:line = l:match[3] + let l:file = l:match[2] let l:text = l:match[1] - let l:type = 'E' - if ale#path#IsBufferPath(a:buffer, l:match[2]) + if ale#path#IsBufferPath(a:buffer, l:file) + \ && !has_key(l:seen,l:line) \ && ( \ l:text isnot# 'BEGIN failed--compilation aborted' \ || empty(l:output) @@ -43,6 +51,8 @@ function! ale_linters#perl#perl#Handle(buffer, lines) abort \ 'text': l:text, \ 'type': l:type, \}) + + let l:seen[l:line] = 1 endif endfor diff --git a/test/handler/test_perl_handler.vader b/test/handler/test_perl_handler.vader index 75e8f22..c5791d7 100644 --- a/test/handler/test_perl_handler.vader +++ b/test/handler/test_perl_handler.vader @@ -47,3 +47,42 @@ Execute(The Perl linter should complain about failing to locate modules): \ 'Unable to build `ro` accessor for slot `path` in `App::CPANFileUpdate` because the slot cannot be found. at /extlib/Method/Traits.pm line 189.', \ 'BEGIN failed--compilation aborted at - line 10.', \ ]) + +Execute(The Perl linter should not report warnings as errors): + AssertEqual + \ [ + \ {'lnum': '5', 'type': 'W', 'text': '"my" variable $foo masks earlier declaration in same scope'}, + \ ], + \ ale_linters#perl#perl#Handle(bufnr(''), [ + \ '"my" variable $foo masks earlier declaration in same scope at - line 5.', + \ 't.pl syntax OK', + \ ]) + +Execute(The Perl linter does not default to reporting generic error): + AssertEqual + \ [ + \ {'lnum': '8', 'type': 'E', 'text': 'Missing right curly or square bracket'}, + \ ], + \ ale_linters#perl#perl#Handle(bufnr(''), [ + \ 'Missing right curly or square bracket at - line 8, at end of line', + \ 'syntax error at - line 8, at EOF', + \ 'Execution of t.pl aborted due to compilation errors.', + \ ]) + +" The first "error" is actually a warning, but the current implementation +" doesn't have a good way of teasing out the warnings from amongst the +" errors. If we're able to do this in future, then we'll want to switch +" the first "E" to a "W". + +Execute(The Perl linter reports errors even when mixed with warnings): + AssertEqual + \ [ + \ {'lnum': '5', 'type': 'E', 'text': '"my" variable $foo masks earlier declaration in same scope'}, + \ {'lnum': '8', 'type': 'E', 'text': 'Missing right curly or square bracket'}, + \ ], + \ ale_linters#perl#perl#Handle(bufnr(''), [ + \ '"my" variable $foo masks earlier declaration in same scope at - line 5.', + \ 'Missing right curly or square bracket at - line 8, at end of line', + \ 'syntax error at - line 8, at EOF', + \ 'Execution of t.pl aborted due to compilation errors.', + \ ]) From 565ffa0dc5e2fe53663f7228c05ad927c190b9e6 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sat, 3 Mar 2018 13:27:19 +0000 Subject: [PATCH 63/69] Use the configured mdl executable, escape it in the command, and add test for it --- ale_linters/markdown/mdl.vim | 22 +++++++++------ .../test_markdown_mdl_command_callback.vader | 28 +++++++++++++++++++ 2 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 test/command_callback/test_markdown_mdl_command_callback.vader diff --git a/ale_linters/markdown/mdl.vim b/ale_linters/markdown/mdl.vim index 9bb2031..16b08cc 100644 --- a/ale_linters/markdown/mdl.vim +++ b/ale_linters/markdown/mdl.vim @@ -4,6 +4,18 @@ call ale#Set('markdown_mdl_executable', 'mdl') call ale#Set('markdown_mdl_options', '') +function! ale_linters#markdown#mdl#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'markdown_mdl_executable') +endfunction + +function! ale_linters#markdown#mdl#GetCommand(buffer) abort + let l:executable = ale_linters#markdown#mdl#GetExecutable(a:buffer) + let l:options = ale#Var(a:buffer, 'markdown_mdl_options') + + return ale#Escape(l:executable) + \ . (!empty(l:options) ? ' ' . l:options : '') +endfunction + function! ale_linters#markdown#mdl#Handle(buffer, lines) abort " matches: '(stdin):173: MD004 Unordered list style' let l:pattern = ':\(\d*\): \(.*\)$' @@ -20,17 +32,9 @@ function! ale_linters#markdown#mdl#Handle(buffer, lines) abort return l:output endfunction -function! ale_linters#markdown#mdl#GetCommand(buffer) abort - let l:executable = ale#Var(a:buffer, 'markdown_mdl_executable') - let l:options = ale#Var(a:buffer, 'markdown_mdl_options') - - return l:executable . (!empty(l:options) ? ' ' . l:options : '') -endfunction - - call ale#linter#Define('markdown', { \ 'name': 'mdl', -\ 'executable': 'mdl', +\ 'executable_callback': 'ale_linters#markdown#mdl#GetExecutable', \ 'command_callback': 'ale_linters#markdown#mdl#GetCommand', \ 'callback': 'ale_linters#markdown#mdl#Handle' \}) diff --git a/test/command_callback/test_markdown_mdl_command_callback.vader b/test/command_callback/test_markdown_mdl_command_callback.vader new file mode 100644 index 0000000..3a68a4b --- /dev/null +++ b/test/command_callback/test_markdown_mdl_command_callback.vader @@ -0,0 +1,28 @@ +Before: + Save g:ale_markdown_mdl_executable + Save g:ale_markdown_mdl_options + + unlet! g:ale_markdown_mdl_executable + unlet! g:ale_markdown_mdl_options + + runtime ale_linters/markdown/mdl.vim + +After: + Restore + + call ale#linter#Reset() + +Execute(The default command should be correct): + AssertEqual ale_linters#markdown#mdl#GetExecutable(bufnr('')), 'mdl' + AssertEqual + \ ale_linters#markdown#mdl#GetCommand(bufnr('')), + \ ale#Escape('mdl') + +Execute(The executable and options should be configurable): + let g:ale_markdown_mdl_executable = 'foo bar' + let g:ale_markdown_mdl_options = '--wat' + + AssertEqual ale_linters#markdown#mdl#GetExecutable(bufnr('')), 'foo bar' + AssertEqual + \ ale_linters#markdown#mdl#GetCommand(bufnr('')), + \ ale#Escape('foo bar') . ' --wat' From 08cfd5f90c8113f4db25f60833b690665046b495 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sat, 3 Mar 2018 16:22:56 +0000 Subject: [PATCH 64/69] Close #1379 - Increment b:ale_linted when a buffer is checked --- autoload/ale/engine.vim | 6 ++++++ doc/ale.txt | 13 +++++++++++++ test/test_alelint_autocmd.vader | 21 +++++++++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 9ef3ba3..6ccc3a3 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -321,6 +321,12 @@ function! ale#engine#SetResults(buffer, loclist) abort " Reset the save event marker, used for opening windows, etc. call setbufvar(a:buffer, 'ale_save_event_fired', 0) + " Set a marker showing how many times a buffer has been checked. + call setbufvar( + \ a:buffer, + \ 'ale_linted', + \ getbufvar(a:buffer, 'ale_linted', 0) + 1 + \) " Automatically remove all managed temporary files and directories " now that all jobs have completed. diff --git a/doc/ale.txt b/doc/ale.txt index adcdccd..95c3c0e 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2280,6 +2280,19 @@ ale#statusline#Count(buffer) *ale#statusline#Count()* `total` -> The total number of problems. +b:ale_linted *b:ale_linted* + + `b:ale_linted` is set to the number of times a buffer has been checked by + ALE after all linters for one lint cycle have finished checking a buffer. + This variable may not be defined until ALE first checks a buffer, so it + should be accessed with |get()| or |getbufvar()|. For example: > + + " Print a message indicating how many times ALE has checked this buffer. + echo 'ALE has checked this buffer ' . get(b:, 'ale_linted') . ' time(s).' + " Print 'checked' using getbufvar() if a buffer has been checked. + echo getbufvar(bufnr(''), 'ale_linted', 0) > 0 ? 'checked' : 'not checked' +< + ALELintPre *ALELintPre-autocmd* ALELintPost *ALELintPost-autocmd* diff --git a/test/test_alelint_autocmd.vader b/test/test_alelint_autocmd.vader index b19e6b4..d51694f 100644 --- a/test/test_alelint_autocmd.vader +++ b/test/test_alelint_autocmd.vader @@ -3,12 +3,18 @@ Before: let g:post_success = 0 let g:ale_run_synchronously = 1 + unlet! b:ale_linted + After: let g:ale_run_synchronously = 0 let g:ale_buffer_info = {} - augroup! VaderTest -Execute (Run a lint cycle, and check that a variable is set in the autocmd): + try + augroup! VaderTest + catch + endtry + +Execute(Run a lint cycle, and check that a variable is set in the autocmd): augroup VaderTest autocmd! autocmd User ALELintPre let g:pre_success = 1 @@ -19,3 +25,14 @@ Execute (Run a lint cycle, and check that a variable is set in the autocmd): AssertEqual g:pre_success, 1 AssertEqual g:post_success, 1 + +Execute(b:ale_linted should be increased after each lint cycle): + AssertEqual get(b:, 'ale_linted'), 0 + + call ale#Lint() + + AssertEqual get(b:, 'ale_linted'), 1 + + call ale#Lint() + + AssertEqual get(b:, 'ale_linted'), 2 From f476c28b296ccd6322067756c5215707ee57f408 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sat, 3 Mar 2018 17:50:09 +0000 Subject: [PATCH 65/69] Add deprecation warnings for old NeoVim versions and old functions --- autoload/ale/statusline.vim | 5 +++++ plugin/ale.vim | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/autoload/ale/statusline.vim b/autoload/ale/statusline.vim index a073f7a..adb35e7 100644 --- a/autoload/ale/statusline.vim +++ b/autoload/ale/statusline.vim @@ -95,6 +95,11 @@ endfunction " This function is deprecated, and should not be used. Use the airline plugin " instead, or write your own status function with ale#statusline#Count() function! ale#statusline#Status() abort + if !get(g:, 'ale_deprecation_ale_statusline_status', 0) + echom 'ale#statusline#Status() is deprecated, use ale#statusline#Count() to write your own function.' + let g:ale_deprecation_ale_statusline_status = 1 + endif + if !exists('g:ale_statusline_format') return 'OK' endif diff --git a/plugin/ale.vim b/plugin/ale.vim index 1a473df..0ca7617 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -32,6 +32,11 @@ if !s:has_features finish endif +if has('nvim') && !has('nvim-0.2.0') && !get(g:, 'ale_use_deprecated_neovim') + echom 'ALE support for NeoVim versions below 0.2.0 is deprecated.' + echom 'Use `let g:ale_use_deprecated_neovim = 1` to silence this warning for now.' +endif + " This flag can be set to 0 to disable emitting conflict warnings. let g:ale_emit_conflict_warnings = get(g:, 'ale_emit_conflict_warnings', 1) @@ -298,9 +303,19 @@ augroup END " Backwards Compatibility function! ALELint(delay) abort + if !get(g:, 'ale_deprecation_ale_lint', 0) + echom 'ALELint() is deprecated, use ale#Queue() instead.' + let g:ale_deprecation_ale_lint = 1 + endif + call ale#Queue(a:delay) endfunction function! ALEGetStatusLine() abort + if !get(g:, 'ale_deprecation_ale_get_status_line', 0) + echom 'ALEGetStatusLine() is deprecated.' + let g:ale_deprecation_ale_get_status_line = 1 + endif + return ale#statusline#Status() endfunction From 193a4b9336e8e108b1e936a5aedb252253688616 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sat, 3 Mar 2018 18:13:57 +0000 Subject: [PATCH 66/69] Satisfy my own checks --- autoload/ale/statusline.vim | 2 +- plugin/ale.vim | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/autoload/ale/statusline.vim b/autoload/ale/statusline.vim index adb35e7..3f53368 100644 --- a/autoload/ale/statusline.vim +++ b/autoload/ale/statusline.vim @@ -96,7 +96,7 @@ endfunction " instead, or write your own status function with ale#statusline#Count() function! ale#statusline#Status() abort if !get(g:, 'ale_deprecation_ale_statusline_status', 0) - echom 'ale#statusline#Status() is deprecated, use ale#statusline#Count() to write your own function.' + execute 'echom ''ale#statusline#Status() is deprecated, use ale#statusline#Count() to write your own function.''' let g:ale_deprecation_ale_statusline_status = 1 endif diff --git a/plugin/ale.vim b/plugin/ale.vim index 0ca7617..69c0849 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -33,8 +33,8 @@ if !s:has_features endif if has('nvim') && !has('nvim-0.2.0') && !get(g:, 'ale_use_deprecated_neovim') - echom 'ALE support for NeoVim versions below 0.2.0 is deprecated.' - echom 'Use `let g:ale_use_deprecated_neovim = 1` to silence this warning for now.' + execute 'echom ''ALE support for NeoVim versions below 0.2.0 is deprecated.''' + execute 'echom ''Use `let g:ale_use_deprecated_neovim = 1` to silence this warning for now.''' endif " This flag can be set to 0 to disable emitting conflict warnings. @@ -304,7 +304,7 @@ augroup END function! ALELint(delay) abort if !get(g:, 'ale_deprecation_ale_lint', 0) - echom 'ALELint() is deprecated, use ale#Queue() instead.' + execute 'echom ''ALELint() is deprecated, use ale#Queue() instead.''' let g:ale_deprecation_ale_lint = 1 endif @@ -313,7 +313,7 @@ endfunction function! ALEGetStatusLine() abort if !get(g:, 'ale_deprecation_ale_get_status_line', 0) - echom 'ALEGetStatusLine() is deprecated.' + execute 'echom ''ALEGetStatusLine() is deprecated.''' let g:ale_deprecation_ale_get_status_line = 1 endif From b7363bef7d8bdd553f10a6a168f4cd814616f6f9 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 4 Mar 2018 11:50:39 +0000 Subject: [PATCH 67/69] Update the licence year. --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 650050f..739ccae 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2016-2017, w0rp +Copyright (c) 2016-2018, w0rp All rights reserved. Redistribution and use in source and binary forms, with or without From 0a0535546f4d9a0dfe02671630fdaba72ea5828d Mon Sep 17 00:00:00 2001 From: w0rp Date: Tue, 6 Mar 2018 10:23:49 +0000 Subject: [PATCH 68/69] Add a command for stopping all LSP clients --- autoload/ale/definition.vim | 4 ++ autoload/ale/engine.vim | 13 +++-- autoload/ale/lsp.vim | 14 ++++++ autoload/ale/lsp/reset.vim | 25 ++++++++++ doc/ale.txt | 9 ++++ plugin/ale.vim | 2 + test/lsp/test_reset_lsp.vader | 90 +++++++++++++++++++++++++++++++++++ 7 files changed, 153 insertions(+), 4 deletions(-) create mode 100644 autoload/ale/lsp/reset.vim create mode 100644 test/lsp/test_reset_lsp.vader diff --git a/autoload/ale/definition.vim b/autoload/ale/definition.vim index b20c01a..521cd0b 100644 --- a/autoload/ale/definition.vim +++ b/autoload/ale/definition.vim @@ -19,6 +19,10 @@ function! ale#definition#Execute(expr) abort execute a:expr endfunction +function! ale#definition#ClearLSPData() abort + let s:go_to_definition_map = {} +endfunction + function! ale#definition#Open(options, filename, line, column) abort if a:options.open_in_tab call ale#definition#Execute('tabedit ' . fnameescape(a:filename)) diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 6ccc3a3..8916987 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -76,6 +76,11 @@ function! ale#engine#InitBufferInfo(buffer) abort return 0 endfunction +" Clear LSP linter data for the linting engine. +function! ale#engine#ClearLSPData() abort + let s:lsp_linter_map = {} +endfunction + " This function is documented and part of the public API. " " Return 1 if ALE is busy checking a given buffer @@ -144,7 +149,7 @@ function! s:GatherOutput(job_id, line) abort endif endfunction -function! s:HandleLoclist(linter_name, buffer, loclist) abort +function! ale#engine#HandleLoclist(linter_name, buffer, loclist) abort let l:info = get(g:ale_buffer_info, a:buffer, {}) if empty(l:info) @@ -223,7 +228,7 @@ function! s:HandleExit(job_id, exit_code) abort let l:loclist = ale#util#GetFunction(l:linter.callback)(l:buffer, l:output) - call s:HandleLoclist(l:linter.name, l:buffer, l:loclist) + call ale#engine#HandleLoclist(l:linter.name, l:buffer, l:loclist) endfunction function! s:HandleLSPDiagnostics(conn_id, response) abort @@ -237,7 +242,7 @@ function! s:HandleLSPDiagnostics(conn_id, response) abort let l:loclist = ale#lsp#response#ReadDiagnostics(a:response) - call s:HandleLoclist(l:linter_name, l:buffer, l:loclist) + call ale#engine#HandleLoclist(l:linter_name, l:buffer, l:loclist) endfunction function! s:HandleTSServerDiagnostics(response, error_type) abort @@ -262,7 +267,7 @@ function! s:HandleTSServerDiagnostics(response, error_type) abort let l:loclist = get(l:info, 'semantic_loclist', []) \ + get(l:info, 'syntax_loclist', []) - call s:HandleLoclist('tsserver', l:buffer, l:loclist) + call ale#engine#HandleLoclist('tsserver', l:buffer, l:loclist) endfunction function! s:HandleLSPErrorMessage(error_message) abort diff --git a/autoload/ale/lsp.vim b/autoload/ale/lsp.vim index 126d6c1..8db9348 100644 --- a/autoload/ale/lsp.vim +++ b/autoload/ale/lsp.vim @@ -325,6 +325,20 @@ function! ale#lsp#ConnectToAddress(address, project_root, callback) abort return 1 endfunction +" Stop all LSP connections, closing all jobs and channels, and removing any +" queued messages. +function! ale#lsp#StopAll() abort + for l:conn in s:connections + if has_key(l:conn, 'channel') + call ch_close(l:conn.channel) + else + call ale#job#Stop(l:conn.id) + endif + endfor + + let s:connections = [] +endfunction + function! s:SendMessageData(conn, data) abort if has_key(a:conn, 'executable') call ale#job#SendRaw(a:conn.id, a:data) diff --git a/autoload/ale/lsp/reset.vim b/autoload/ale/lsp/reset.vim new file mode 100644 index 0000000..c206ed0 --- /dev/null +++ b/autoload/ale/lsp/reset.vim @@ -0,0 +1,25 @@ +" Stop all LSPs and remove all of the data for them. +function! ale#lsp#reset#StopAllLSPs() abort + call ale#lsp#StopAll() + + if exists('*ale#definition#ClearLSPData') + " Clear the mapping for connections, etc. + call ale#definition#ClearLSPData() + endif + + if exists('*ale#engine#ClearLSPData') + " Clear the mapping for connections, etc. + call ale#engine#ClearLSPData() + + " Remove the problems for all of the LSP linters in every buffer. + for l:buffer_string in keys(g:ale_buffer_info) + let l:buffer = str2nr(l:buffer_string) + + for l:linter in ale#linter#Get(getbufvar(l:buffer, '&filetype')) + if !empty(l:linter.lsp) + call ale#engine#HandleLoclist(l:linter.name, l:buffer, []) + endif + endfor + endfor + endif +endfunction diff --git a/doc/ale.txt b/doc/ale.txt index 95c3c0e..2e98cd7 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1871,6 +1871,15 @@ ALEResetBuffer *ALEResetBuffer* |ALEDisableBuffer|. +ALEStopAllLSPs *ALEStopAllLSPs* + + `ALEStopAllLSPs` will close and stop all channels and jobs for all LSP-like + clients, including tsserver, remove all of the data stored for them, and + delete all of the problems found for them, updating every linted buffer. + + This command can be used when LSP clients mess up and need to be restarted. + + =============================================================================== 9. API *ale-api* diff --git a/plugin/ale.vim b/plugin/ale.vim index 69c0849..1aa3582 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -249,6 +249,8 @@ command! -bar ALEToggleBuffer :call ale#toggle#ToggleBuffer(bufnr('')) command! -bar ALEEnableBuffer :call ale#toggle#EnableBuffer(bufnr('')) command! -bar ALEDisableBuffer :call ale#toggle#DisableBuffer(bufnr('')) command! -bar ALEResetBuffer :call ale#toggle#ResetBuffer(bufnr('')) +" A command to stop all LSP-like clients, including tsserver. +command! -bar ALEStopAllLSPs :call ale#lsp#reset#StopAllLSPs() " A command for linting manually. command! -bar ALELint :call ale#Queue(0, 'lint_file') diff --git a/test/lsp/test_reset_lsp.vader b/test/lsp/test_reset_lsp.vader new file mode 100644 index 0000000..2bec13d --- /dev/null +++ b/test/lsp/test_reset_lsp.vader @@ -0,0 +1,90 @@ +Before: + Save g:ale_enabled + Save g:ale_set_signs + Save g:ale_set_quickfix + Save g:ale_set_loclist + Save g:ale_set_highlights + Save g:ale_echo_cursor + + let g:ale_enabled = 0 + let g:ale_set_signs = 0 + let g:ale_set_quickfix = 0 + let g:ale_set_loclist = 0 + let g:ale_set_highlights = 0 + let g:ale_echo_cursor = 0 + + function EmptyString() abort + return '' + endfunction + + call ale#engine#InitBufferInfo(bufnr('')) + + call ale#linter#Define('testft', { + \ 'name': 'lsplinter', + \ 'lsp': 'tsserver', + \ 'executable_callback': 'EmptyString', + \ 'command_callback': 'EmptyString', + \ 'project_root_callback': 'EmptyString', + \ 'language_callback': 'EmptyString', + \}) + + call ale#linter#Define('testft', { + \ 'name': 'otherlinter', + \ 'callback': 'TestCallback', + \ 'executable': has('win32') ? 'cmd': 'true', + \ 'command': 'true', + \ 'read_buffer': 0, + \}) + +After: + Restore + + unlet! b:ale_save_event_fired + + delfunction EmptyString + call ale#linter#Reset() + +Given testft(Some file with an imaginary filetype): +Execute(ALEStopAllLSPs should clear the loclist): + let g:ale_buffer_info[bufnr('')].loclist = [ + \ { + \ 'text': 'a', + \ 'lnum': 10, + \ 'col': 0, + \ 'bufnr': bufnr(''), + \ 'vcol': 0, + \ 'type': 'E', + \ 'nr': -1, + \ 'linter_name': 'lsplinter', + \ }, + \ { + \ 'text': 'a', + \ 'lnum': 10, + \ 'col': 0, + \ 'bufnr': bufnr(''), + \ 'vcol': 0, + \ 'type': 'E', + \ 'nr': -1, + \ 'linter_name': 'otherlinter', + \ }, + \] + let g:ale_buffer_info[bufnr('')].active_linter_list = ['lsplinter', 'otherlinter'] + + ALEStopAllLSPs + + " The loclist should be updated. + AssertEqual g:ale_buffer_info[bufnr('')].loclist, [ + \ { + \ 'text': 'a', + \ 'lnum': 10, + \ 'col': 0, + \ 'bufnr': bufnr(''), + \ 'vcol': 0, + \ 'type': 'E', + \ 'nr': -1, + \ 'linter_name': 'otherlinter', + \ }, + \] + + " The LSP linter should be removed from the active linter list. + AssertEqual g:ale_buffer_info[bufnr('')].active_linter_list, ['otherlinter'] From 80ef6ef6a7f1fba7f3dbc770e1807b04caeb3ae4 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Tue, 6 Mar 2018 23:27:59 -0600 Subject: [PATCH 69/69] Find executable for `shellcheck` Wanted to be able to use `shellcheck` that was installed in node_modules. --- ale_linters/sh/shellcheck.vim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ale_linters/sh/shellcheck.vim b/ale_linters/sh/shellcheck.vim index 27c7453..ac66892 100644 --- a/ale_linters/sh/shellcheck.vim +++ b/ale_linters/sh/shellcheck.vim @@ -12,11 +12,16 @@ let g:ale_sh_shellcheck_exclusions = let g:ale_sh_shellcheck_executable = \ get(g:, 'ale_sh_shellcheck_executable', 'shellcheck') +let g:ale_sh_shellcheck_use_global = +\ get(g:, 'ale_sh_shellcheck_use_global', 0) + let g:ale_sh_shellcheck_options = \ get(g:, 'ale_sh_shellcheck_options', '') function! ale_linters#sh#shellcheck#GetExecutable(buffer) abort - return ale#Var(a:buffer, 'sh_shellcheck_executable') + return ale#node#FindExecutable(a:buffer, 'sh_shellcheck', [ + \ 'node_modules/.bin/shellcheck', + \]) endfunction function! ale_linters#sh#shellcheck#GetDialectArgument(buffer) abort