summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorDavid Houston <houstdav000@gmail.com>2021-11-11 17:34:25 -0500
committerGitHub <noreply@github.com>2021-11-12 07:34:25 +0900
commita9d7f45924b97a5244fb626dd9ae0bf934ca1ee6 (patch)
tree92469b20ab095a1742fa84f5782b479606824caa /autoload
parent8b3b16d71c4c683da6f3ca39662d207a3e894901 (diff)
downloadale-a9d7f45924b97a5244fb626dd9ae0bf934ca1ee6.zip
Implement statix Linter and Fixer (#3969)
* Add Statix for Linting Add `statix check` as a linter. Provides a simple set of definition tests additionally. Variable names specify "check" to allow for later addition of `statix fix` as a formatter once stream support is added. Signed-off-by: David Houston <houstdav000@gmail.com> * Fixup Supported Tools List I didn't realise there were two separate lists of tools, so add statix to the other list. Also, remembered "S" comes after "R", and so re-ordered it. Signed-off-by: David Houston <houstdav000@gmail.com> * Fix statix Test File I refactored the variables for statix to allow for writing a fixer later, and forgot to update them in the test, so update them now. Also remove a stray "i", add missing space before checks Signed-off-by: David Houston <houstdav000@gmail.com> * Update Output Stream for v0.4.0 statix v0.4.0 provides a breaking change of output stream from stderr to stdout. Signed-off-by: David Houston <houstdav000@gmail.com> * Add statix fix Fixer Implement statix fix as a fixer for simple Nix antipatterns. Signed-off-by: David Houston <houstdav000@gmail.com> * Fix statix Fixer Tests Fix the statix fixer tests by removing the unnecessary 'read_temporary_file' value from the command, since it simply uses the default value. Signed-off-by: David Houston <houstdav000@gmail.com> * Add statix Handler Test Add a test for the statix handler per @hsanson's request. Signed-off-by: David Houston <houstdav000@gmail.com> * Fix to run only on stdin for linting Signed-off-by: David Houston <houstdav000@gmail.com>
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/statix.vim17
-rw-r--r--autoload/ale/handlers/statix.vim24
3 files changed, 46 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index eb7d7f53..c80d2271 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -191,6 +191,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['ruby'],
\ 'description': 'Fix ruby files with standardrb --fix',
\ },
+\ 'statix': {
+\ 'function': 'ale#fixers#statix#Fix',
+\ 'suggested_filetypes': ['nix'],
+\ 'description': 'Fix common Nix antipatterns with statix fix',
+\ },
\ 'stylelint': {
\ 'function': 'ale#fixers#stylelint#Fix',
\ 'suggested_filetypes': ['css', 'sass', 'scss', 'sugarss', 'stylus'],
diff --git a/autoload/ale/fixers/statix.vim b/autoload/ale/fixers/statix.vim
new file mode 100644
index 00000000..5991c925
--- /dev/null
+++ b/autoload/ale/fixers/statix.vim
@@ -0,0 +1,17 @@
+" Author: David Houston <houstdav000>
+" Description: Provide statix fix as a fixer for simple Nix antipatterns.
+
+call ale#Set('nix_statix_fix_executable', 'statix')
+call ale#Set('nix_statix_fix_options', '')
+
+function! ale#fixers#statix#Fix(buffer) abort
+ let l:executable = ale#Var(a:buffer, 'nix_statix_fix_executable')
+ let l:options = ale#Var(a:buffer, 'nix_statix_fix_options')
+
+ return {
+ \ 'command': ale#Escape(l:executable)
+ \ . ale#Pad('fix')
+ \ . ale#Pad('--stdin')
+ \ . ale#Pad(l:options),
+ \}
+endfunction
diff --git a/autoload/ale/handlers/statix.vim b/autoload/ale/handlers/statix.vim
new file mode 100644
index 00000000..eeef4107
--- /dev/null
+++ b/autoload/ale/handlers/statix.vim
@@ -0,0 +1,24 @@
+scriptencoding utf-8
+" Author: David Houston
+" Description: This file defines a handler function for statix's errorformat
+" output.
+
+function! ale#handlers#statix#Handle(buffer, lines) abort
+ " Look for lines like the following.
+ "
+ " flake.nix>46:13:W:3:This assignment is better written with `inherit`
+ let l:pattern = '\v^.*\>(\d+):(\d+):([A-Z]):(\d+):(.*)$'
+ let l:output = []
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ call add(l:output, {
+ \ 'lnum': l:match[1] + 0,
+ \ 'col': l:match[2] + 0,
+ \ 'type': l:match[3],
+ \ 'code': l:match[4],
+ \ 'text': l:match[5],
+ \})
+ endfor
+
+ return l:output
+endfunction