File tree Expand file tree Collapse file tree 7 files changed +107
-0
lines changed
test-files/generic/astgrep Expand file tree Collapse file tree 7 files changed +107
-0
lines changed Original file line number Diff line number Diff line change 1+ " Author: Ben Boeckel <[email protected] >2+ " Description: A CLI tool for code structural search, lint and rewriting
3+
4+ call ale#Set (' astgrep_executable' , ' ast-grep' )
5+
6+ function ! ale#astgrep#GetCommand (buffer ) abort
7+ return ' %e lsp'
8+ endfunction
9+
10+ function ! ale#astgrep#GetProjectRoot (buffer ) abort
11+ " Try to find nearest sgconfig.yml
12+ let l: sgconfig_file = ale#path#FindNearestFile (a: buffer , ' sgconfig.yml' )
13+
14+ if ! empty (l: sgconfig_file )
15+ return fnamemodify (l: sgconfig_file . ' /' , ' :p:h:h' )
16+ endif
17+
18+ return ' '
19+ endfunction
20+
21+ function ! ale#astgrep#Define (lang) abort
22+ call ale#linter#Define (a: lang , {
23+ \ ' name' : ' astgrep' ,
24+ \ ' lsp' : ' stdio' ,
25+ \ ' executable' : {b - > ale#Var (b , ' astgrep_executable' )},
26+ \ ' command' : function (' ale#astgrep#GetCommand' ),
27+ \ ' project_root' : function (' ale#astgrep#GetProjectRoot' ),
28+ \} )
29+ endfunction
30+
31+ function ! ale#astgrep#ApplyLanguages () abort
32+ for l: lang in g: ale_astgrep_linter_languages
33+ call ale#astgrep#Define (l: lang )
34+ endfor
35+ endfunction
36+
37+ let g: ale_astgrep_linter_languages = get (g: , ' ale_astgrep_linter_languages' , [])
38+ call ale#astgrep#ApplyLanguages ()
Original file line number Diff line number Diff line change 1+ ===============================================================================
2+ ALE Generic Integration *ale-generic-options*
3+ *ale-integration-generic*
4+
5+ ===============================================================================
6+ Integration Information
7+
8+ Some tools are not language specific. This document collects information on
9+ ale's support for these tools.
10+
11+
12+ ===============================================================================
13+ astgrep *ale-generic-astgrep*
14+
15+ `' ast-grep' ` is a tool which can detect code patterns and offer fixes based
16+ on various languages' abstract syntax trees (ASTs) using tree-sitter.
17+
18+ *ale-options.astgrep_executable*
19+ *g:ale_astgrep_executable*
20+ *b:ale_astgrep_executable*
21+ astgrep_executable
22+ g:ale_astgrep_executable
23+ Type: | String |
24+ Default: `' ast-grep' `
25+
26+ This variable can be modified to change the executable path for
27+ `ast- grep ` .
28+
29+
30+ *ale-options.astgrep_linter_languages*
31+ *g:ale_astgrep_linter_languages*
32+ astgrep_linter_languages
33+ g:ale_astgrep_linter_languages
34+ Type: | List |
35+ Default: `' []' `
36+
37+ This variable can be set to a list of languages for which to enable the
38+ `ast- grep ` linter.
39+
40+
41+ ===============================================================================
42+ vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
Original file line number Diff line number Diff line change @@ -3485,6 +3485,8 @@ documented in additional help files.
34853485 fountain................................| ale-fountain-options |
34863486 fusionscript............................| ale-fuse-options |
34873487 fusion-lint...........................| ale-fuse-fusionlint |
3488+ generic.................................| ale-generic-options |
3489+ astgrep...............................| ale-generic-astgrep |
34883490 git commit..............................| ale-gitcommit-options |
34893491 gitlint...............................| ale-gitcommit-gitlint |
34903492 gleam...................................| ale-gleam-options |
Original file line number Diff line number Diff line change @@ -220,6 +220,8 @@ formatting.
220220 * [ proselint] ( http://proselint.com/ )
221221* FusionScript
222222 * [ fusion-lint] ( https://github.com/RyanSquared/fusionscript )
223+ * Generic
224+ * [ ast-grep] ( https://ast-grep.github.io/ )
223225* Git Commit Messages
224226 * [ gitlint] ( https://github.com/jorisroovers/gitlint )
225227* Gleam
Original file line number Diff line number Diff line change 1+ Before:
2+ " Load the dummy linter; tests will register as needed.
3+ call ale#assert#SetUpLinterTest('testft', 'testlinter')
4+ " Replace the dummy linter with a defined linter.
5+ call ale#linter#Reset()
6+ call ale#linter#PreventLoading('python')
7+ call ale#astgrep#Define('python')
8+
9+ After:
10+ call ale#assert#TearDownLinterTest()
11+
12+ Execute(The default executable path should be correct):
13+ AssertLinter 'ast-grep', ale#Escape('ast-grep') . ' lsp'
14+
15+ Execute(The project root should be detected correctly with a configuration file):
16+ call ale#test#SetFilename('../test-files/generic/astgrep/subdir/file.py')
17+
18+ AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/generic/astgrep')
19+
20+ Execute(The project root should be empty when no project files can be detected):
21+ call ale#test#SetFilename('../test-files/dummy')
22+
23+ AssertLSPProject ''
You can’t perform that action at this time.
0 commit comments