mirror of
https://github.com/dense-analysis/ale.git
synced 2026-07-29 19:26:46 +08:00
Support astgrep (#4975)
CI / Build (push) Canceled after 0s
CI / Neovim 0.10 Windows (push) Canceled after 0s
CI / Neovim 0.12 Windows (push) Canceled after 0s
CI / Vim 8.2 Windows (push) Canceled after 0s
CI / Vim 9.2 Windows (push) Canceled after 0s
CI / Lint (push) Canceled after 0s
CI / Lua (push) Canceled after 0s
CI / Neovim 0.10 Linux (push) Canceled after 0s
CI / Neovim 0.12 Linux (push) Canceled after 0s
CI / Vim 8.2 Linux (push) Canceled after 0s
CI / Vim 9.2 Linux (push) Canceled after 0s
CI / Build (push) Canceled after 0s
CI / Neovim 0.10 Windows (push) Canceled after 0s
CI / Neovim 0.12 Windows (push) Canceled after 0s
CI / Vim 8.2 Windows (push) Canceled after 0s
CI / Vim 9.2 Windows (push) Canceled after 0s
CI / Lint (push) Canceled after 0s
CI / Lua (push) Canceled after 0s
CI / Neovim 0.10 Linux (push) Canceled after 0s
CI / Neovim 0.12 Linux (push) Canceled after 0s
CI / Vim 8.2 Linux (push) Canceled after 0s
CI / Vim 9.2 Linux (push) Canceled after 0s
* astgrep: support its LSP Fixes: #4974 * astgrep: add a fixer
This commit is contained in:
@@ -22,6 +22,11 @@ let s:default_registry = {
|
||||
\ 'suggested_filetypes': ['apkbuild'],
|
||||
\ 'description': 'Fix policy violations found by apkbuild-lint in APKBUILDs',
|
||||
\ },
|
||||
\ 'ast-grep': {
|
||||
\ 'function': 'ale#fixers#astgrep#Fix',
|
||||
\ 'suggested_filetypes': ['c', 'cpp', 'cs', 'css', 'elixer', 'go', 'haskell', 'html', 'java', 'javascript', 'json', 'kotlin', 'lua', 'nix', 'php', 'python', 'ruby', 'rust', 'scala', 'sh', 'solidity', 'swift', 'tsx', 'typescript', 'yaml'],
|
||||
\ 'description': 'Apply ast-grep rules.',
|
||||
\ },
|
||||
\ 'autoimport': {
|
||||
\ 'function': 'ale#fixers#autoimport#Fix',
|
||||
\ 'suggested_filetypes': ['python'],
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
" Author: Ben Boeckel <github@me.benboeckel.net>
|
||||
" Description: Fix files with `ast-grep`.
|
||||
|
||||
call ale#Set('astgrep_executable', 'ast-grep')
|
||||
call ale#Set('astgrep_scan_options', '--update-all')
|
||||
|
||||
function! ale#fixers#astgrep#Fix(buffer) abort
|
||||
let l:executable = ale#Var(a:buffer, 'astgrep_executable')
|
||||
let l:options = ale#Var(a:buffer, 'astgrep_scan_options')
|
||||
|
||||
return {
|
||||
\ 'command': ale#Escape(l:executable)
|
||||
\ . ' scan'
|
||||
\ . (empty(l:options) ? '' : ' ' . l:options)
|
||||
\ . ' %t',
|
||||
\ 'read_temporary_file': 1,
|
||||
\}
|
||||
endfunction
|
||||
@@ -0,0 +1,29 @@
|
||||
" Author: Ben Boeckel <github@me.benboeckel.net>
|
||||
" Description: A CLI tool for code structural search, lint and rewriting
|
||||
|
||||
call ale#Set('astgrep_executable', 'ast-grep')
|
||||
|
||||
function! ale#handlers#astgrep#GetCommand(buffer) abort
|
||||
return '%e lsp'
|
||||
endfunction
|
||||
|
||||
function! ale#handlers#astgrep#GetProjectRoot(buffer) abort
|
||||
" Try to find nearest sgconfig.yml
|
||||
let l:sgconfig_file = ale#path#FindNearestFile(a:buffer, 'sgconfig.yml')
|
||||
|
||||
if !empty(l:sgconfig_file)
|
||||
return fnamemodify(l:sgconfig_file . '/', ':p:h:h')
|
||||
endif
|
||||
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! ale#handlers#astgrep#Define(lang) abort
|
||||
call ale#linter#Define(a:lang, {
|
||||
\ 'name': 'astgrep',
|
||||
\ 'lsp': 'stdio',
|
||||
\ 'executable': {b -> ale#Var(b, 'astgrep_executable')},
|
||||
\ 'command': function('ale#handlers#astgrep#GetCommand'),
|
||||
\ 'project_root': function('ale#handlers#astgrep#GetProjectRoot'),
|
||||
\})
|
||||
endfunction
|
||||
Reference in New Issue
Block a user