mirror of
https://github.com/dense-analysis/ale.git
synced 2026-11-27 05:33:55 +08:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5098dfd27e | ||
|
|
7cdaaa645d |
No files matched your search
@@ -0,0 +1,57 @@
|
||||
" Author: oliverralbertini <oliver.albertini@gmail.com>
|
||||
" Description: A performant type-checker supporting LSP for Python 3 created by Facebook
|
||||
|
||||
call ale#Set('python_pyrefly_executable', 'pyrefly')
|
||||
call ale#Set('python_pyrefly_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||
call ale#Set('python_pyrefly_auto_pipenv', 0)
|
||||
call ale#Set('python_pyrefly_auto_poetry', 0)
|
||||
call ale#Set('python_pyrefly_auto_uv', 0)
|
||||
|
||||
function! ale_linters#python#pyrefly#GetExecutable(buffer) abort
|
||||
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_pyrefly_auto_pipenv'))
|
||||
\ && ale#python#PipenvPresent(a:buffer)
|
||||
return 'pipenv'
|
||||
endif
|
||||
|
||||
if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pyrefly_auto_poetry'))
|
||||
\ && ale#python#PoetryPresent(a:buffer)
|
||||
return 'poetry'
|
||||
endif
|
||||
|
||||
if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_pyrefly_auto_uv'))
|
||||
\ && ale#python#UvPresent(a:buffer)
|
||||
return 'uv'
|
||||
endif
|
||||
|
||||
return ale#python#FindExecutable(a:buffer, 'python_pyrefly', ['pyrefly'])
|
||||
endfunction
|
||||
|
||||
function! ale_linters#python#pyrefly#GetCommand(buffer) abort
|
||||
let l:executable = ale_linters#python#pyrefly#GetExecutable(a:buffer)
|
||||
let l:exec_args = [
|
||||
\ ale#Escape(l:executable)
|
||||
\ ]
|
||||
\ + (l:executable =~? '\(pipenv\|poetry\|uv\)$' ? ['run', 'pyrefly'] : [])
|
||||
\ + [
|
||||
\ 'lsp',
|
||||
\ ]
|
||||
|
||||
return join(l:exec_args, ' ')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#python#pyrefly#GetCwd(buffer) abort
|
||||
" Run from project root if found, else from buffer dir.
|
||||
let l:project_root = ale#python#FindProjectRoot(a:buffer)
|
||||
|
||||
return !empty(l:project_root) ? l:project_root : '%s:h'
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('python', {
|
||||
\ 'name': 'pyrefly',
|
||||
\ 'lsp': 'stdio',
|
||||
\ 'executable': function('ale_linters#python#pyrefly#GetExecutable'),
|
||||
\ 'command': function('ale_linters#python#pyrefly#GetCommand'),
|
||||
\ 'project_root': function('ale#python#FindProjectRoot'),
|
||||
\ 'completion_filter': 'ale#completion#python#CompletionItemFilter',
|
||||
\ 'cwd': function('ale_linters#python#pyrefly#GetCwd'),
|
||||
\})
|
||||
@@ -1,32 +1,48 @@
|
||||
" Author: Ian Stapleton Cordasco <graffatcolmingov@gmail.com>
|
||||
" Description: Run golangci-lint with the --fix flag to autofix some issues
|
||||
|
||||
call ale#Set('go_golangci_lint_options', '')
|
||||
call ale#Set('go_golangci_lint_executable', 'golangci-lint')
|
||||
call ale#Set('go_golangci_lint_package', 1)
|
||||
call ale#Set('go_golangci_formatter_options', '')
|
||||
call ale#Set('go_golangci_formatter_executable', 'golangci-lint')
|
||||
|
||||
function! ale#fixers#golangci_lint#GetCommand(buffer) abort
|
||||
function! ale#fixers#golangci_lint#GetExecutable(buffer) abort
|
||||
let l:executable = ale#Var(a:buffer, 'go_golangci_formatter_executable')
|
||||
|
||||
return l:executable
|
||||
endfunction
|
||||
|
||||
function! ale#fixers#golangci_lint#GetCommand(buffer, version) abort
|
||||
let l:filename = expand('#' . a:buffer . ':t')
|
||||
let l:executable = ale#Var(a:buffer, 'go_golangci_lint_executable')
|
||||
let l:options = ale#Var(a:buffer, 'go_golangci_lint_options') . ' --fix'
|
||||
let l:package_mode = ale#Var(a:buffer, 'go_golangci_lint_package')
|
||||
let l:executable = ale#fixers#golangci_lint#GetExecutable(a:buffer)
|
||||
let l:options = ale#Var(a:buffer, 'go_golangci_formatter_options')
|
||||
let l:env = ale#go#EnvString(a:buffer)
|
||||
|
||||
|
||||
if l:package_mode
|
||||
if ale#semver#GTE(a:version, [2, 0, 0])
|
||||
return l:env . ale#Escape(l:executable)
|
||||
\ . ' run '
|
||||
\ . l:options
|
||||
\ . ' fmt --stdin '
|
||||
\ . l:options
|
||||
else
|
||||
return l:env . ale#Escape(l:executable)
|
||||
\ . ' run --fix '
|
||||
\ . l:options
|
||||
\ . ' '
|
||||
\ . ale#Escape(l:filename)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
return l:env . ale#Escape(l:executable)
|
||||
\ . ' run '
|
||||
\ . l:options
|
||||
\ . ' ' . ale#Escape(l:filename)
|
||||
function! ale#fixers#golangci_lint#GetCommandForVersion(buffer, version) abort
|
||||
return {
|
||||
\ 'command': ale#fixers#golangci_lint#GetCommand(a:buffer, a:version)
|
||||
\}
|
||||
endfunction
|
||||
|
||||
function! ale#fixers#golangci_lint#Fix(buffer) abort
|
||||
return {
|
||||
\ 'command': ale#fixers#golangci_lint#GetCommand(a:buffer),
|
||||
\}
|
||||
let l:executable = ale#fixers#golangci_lint#GetExecutable(a:buffer)
|
||||
let l:command = ale#fixers#golangci_lint#GetExecutable(a:buffer) . ale#Pad('--version')
|
||||
|
||||
return ale#semver#RunWithVersionCheck(
|
||||
\ a:buffer,
|
||||
\ l:executable,
|
||||
\ l:command,
|
||||
\ function('ale#fixers#golangci_lint#GetCommandForVersion'),
|
||||
\)
|
||||
endfunction
|
||||
+25
-1
@@ -144,7 +144,7 @@ g:ale_go_golangci_lint_options
|
||||
Default: `''`
|
||||
|
||||
This variable can be changed to alter the command-line arguments to the
|
||||
golangci-lint invocation.
|
||||
golangci-lint run invocation.
|
||||
|
||||
*ale-options.go_golangci_lint_package*
|
||||
*g:ale_go_golangci_lint_package*
|
||||
@@ -157,6 +157,30 @@ g:ale_go_golangci_lint_package
|
||||
When set to `1`, the whole Go package will be checked instead of only the
|
||||
current file.
|
||||
|
||||
golangci_lint can also be user as a fixer to format go source files. In this
|
||||
case the following configuration variables can be used to configure the
|
||||
formatters:
|
||||
|
||||
*ale-options.go_golangci_formatter_executable*
|
||||
*g:ale_go_golangci_formatter_executable*
|
||||
*b:ale_go_golangci_formatter_executable*
|
||||
go_golangci_formatter_executable
|
||||
g:ale_go_golangci_formatter_executable
|
||||
Type: |String|
|
||||
Default: `'golangci-lint'`
|
||||
|
||||
The executable that will be run for golangci-lint.
|
||||
|
||||
*ale-options.go_golangci_formatter_options*
|
||||
*g:ale_go_golangci_formatter_options*
|
||||
*b:ale_go_golangci_formatter_options*
|
||||
go_golangci_formatter_options
|
||||
g:ale_go_golangci_formatter_options
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
This variable can be changed to alter the command-line arguments to the
|
||||
golangci-lint fmt invocation.
|
||||
|
||||
===============================================================================
|
||||
golangserver *ale-go-golangserver*
|
||||
|
||||
@@ -1616,6 +1616,69 @@ g:ale_python_pyre_auto_uv
|
||||
executable.
|
||||
|
||||
|
||||
===============================================================================
|
||||
pyrefly *ale-python-pyrefly*
|
||||
|
||||
`pyrefly` will be run from a detected project root, per |ale-python-root|.
|
||||
|
||||
*ale-options.python_pyrefly_executable*
|
||||
*g:ale_python_pyrefly_executable*
|
||||
*b:ale_python_pyrefly_executable*
|
||||
python_pyrefly_executable
|
||||
g:ale_python_pyrefly_executable
|
||||
Type: |String|
|
||||
Default: `'pyrefly'`
|
||||
|
||||
See |ale-integrations-local-executables|
|
||||
|
||||
Set this to `'pipenv'` to invoke `'pipenv` `run` `pyrefly'`.
|
||||
Set this to `'poetry'` to invoke `'poetry` `run` `pyrefly'`.
|
||||
Set this to `'uv'` to invoke `'uv` `run` `pyrefly'`.
|
||||
|
||||
*ale-options.python_pyrefly_use_global*
|
||||
*g:ale_python_pyrefly_use_global*
|
||||
*b:ale_python_pyrefly_use_global*
|
||||
python_pyrefly_use_global
|
||||
g:ale_python_pyrefly_use_global
|
||||
Type: |Number|
|
||||
Default: `get(g:, 'ale_use_global_executables', 0)`
|
||||
|
||||
See |ale-integrations-local-executables|
|
||||
|
||||
*ale-options.python_pyrefly_auto_pipenv*
|
||||
*g:ale_python_pyrefly_auto_pipenv*
|
||||
*b:ale_python_pyrefly_auto_pipenv*
|
||||
python_pyrefly_auto_pipenv
|
||||
g:ale_python_pyrefly_auto_pipenv
|
||||
Type: |Number|
|
||||
Default: `0`
|
||||
|
||||
Detect whether the file is inside a pipenv, and set the executable to `pipenv`
|
||||
if true. This is overridden by a manually-set executable.
|
||||
|
||||
*ale-options.python_pyrefly_auto_poetry*
|
||||
*g:ale_python_pyrefly_auto_poetry*
|
||||
*b:ale_python_pyrefly_auto_poetry*
|
||||
python_pyrefly_auto_poetry
|
||||
g:ale_python_pyrefly_auto_poetry
|
||||
Type: |Number|
|
||||
Default: `0`
|
||||
|
||||
Detect whether the file is inside a poetry, and set the executable to `poetry`
|
||||
if true. This is overridden by a manually-set executable.
|
||||
|
||||
*ale-options.python_pyrefly_auto_uv*
|
||||
*g:ale_python_pyrefly_auto_uv*
|
||||
*b:ale_python_pyrefly_auto_uv*
|
||||
python_pyrefly_auto_uv
|
||||
g:ale_python_pyrefly_auto_uv
|
||||
Type: |Number|
|
||||
Default: `0`
|
||||
|
||||
Set the executable to `uv` if true. This is overridden by a manually-set
|
||||
executable.
|
||||
|
||||
|
||||
===============================================================================
|
||||
pyright *ale-python-pyright*
|
||||
|
||||
|
||||
@@ -545,6 +545,7 @@ Notes:
|
||||
* `pylint`!!
|
||||
* `pylsp`
|
||||
* `pyre`
|
||||
* `pyrefly`
|
||||
* `pyright`
|
||||
* `refurb`
|
||||
* `reorder-python-imports`
|
||||
|
||||
@@ -3788,6 +3788,7 @@ documented in additional help files.
|
||||
pylint................................|ale-python-pylint|
|
||||
pylsp.................................|ale-python-pylsp|
|
||||
pyre..................................|ale-python-pyre|
|
||||
pyrefly...............................|ale-python-pyrefly|
|
||||
pyright...............................|ale-python-pyright|
|
||||
refurb................................|ale-python-refurb|
|
||||
reorder-python-imports................|ale-python-reorder_python_imports|
|
||||
|
||||
@@ -554,6 +554,7 @@ formatting.
|
||||
* [pylint](https://www.pylint.org/) :floppy_disk:
|
||||
* [pylsp](https://github.com/python-lsp/python-lsp-server) :warning:
|
||||
* [pyre](https://github.com/facebook/pyre-check) :warning:
|
||||
* [pyrefly](https://github.com/facebook/pyrefly) :warning:
|
||||
* [pyright](https://github.com/microsoft/pyright)
|
||||
* [refurb](https://github.com/dosisod/refurb) :floppy_disk:
|
||||
* [reorder-python-imports](https://github.com/asottile/reorder_python_imports)
|
||||
|
||||
@@ -14,7 +14,7 @@ Before:
|
||||
let g:ale_completion_enabled = 0
|
||||
let g:ale_completion_autoimport = 0
|
||||
let g:ale_completion_max_suggestions = 50
|
||||
let g:ale_linters = {'typescript': ['tsserver'], 'python': ['pyre']}
|
||||
let g:ale_linters = {'typescript': ['tsserver'], 'python': ['pyrefly']}
|
||||
unlet! b:ale_linters
|
||||
|
||||
let g:server_started_value = 1
|
||||
|
||||
@@ -1,48 +1,80 @@
|
||||
Before:
|
||||
call ale#assert#SetUpFixerTest('go', 'golangci_lint')
|
||||
Save g:ale_go_go111module
|
||||
Save g:ale_go_golangci_lint_executable
|
||||
Save g:ale_go_golangci_lint_options
|
||||
Save g:ale_go_golangci_lint_package
|
||||
Save g:ale_go_golangci_formatter_executable
|
||||
Save g:ale_go_golangci_formatter_options
|
||||
|
||||
" Use an invalid global executable, so we don't match it.
|
||||
let g:ale_go_golangci_lint_executable = 'xxxinvalid'
|
||||
let g:ale_go_golangci_lint_options = ''
|
||||
|
||||
call ale#test#SetDirectory('/testplugin/test/fixers')
|
||||
call ale#test#SetFilename('../test-files/go/testfile.go')
|
||||
|
||||
After:
|
||||
Restore
|
||||
call ale#test#RestoreDirectory()
|
||||
call ale#assert#TearDownFixerTest()
|
||||
|
||||
unlet! b:ale_go_go111module
|
||||
|
||||
call ale#test#RestoreDirectory()
|
||||
Execute(The golangci-lint callback should return the correct default values with v1):
|
||||
|
||||
Execute(The golangci-lint callback should return the correct default values):
|
||||
GivenCommandOutput ['golangci-lint has version 1.64.8 built with go1.23.0']
|
||||
|
||||
AssertEqual
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'command': ale#Escape('xxxinvalid') . ' run --fix',
|
||||
\ 'command': ale#Escape('golangci-lint') . ' run --fix ' . ale#Escape('testfile.go'),
|
||||
\ }
|
||||
|
||||
Execute(The golangci-lint callback should include custom golangci-lint options with v1):
|
||||
let g:ale_go_golangci_formatter_options = "--new --config /dev/null"
|
||||
|
||||
GivenCommandOutput ['golangci-lint has version 1.64.8 built with go1.23.0']
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'command': ale#Escape('golangci-lint')
|
||||
\ . ' run --fix ' . g:ale_go_golangci_formatter_options . ' ' . ale#Escape('testfile.go'),
|
||||
\ },
|
||||
\ ale#fixers#golangci_lint#Fix(bufnr(''))
|
||||
|
||||
Execute(The golangci-lint callback should include custom golangci-lint options):
|
||||
let g:ale_go_golangci_lint_options = "--new --config /dev/null"
|
||||
Execute(The golangci-lint callback should override executable with v1):
|
||||
let g:ale_go_golangci_formatter_executable = 'xxxinvalid'
|
||||
|
||||
AssertEqual
|
||||
GivenCommandOutput ['golangci-lint has version 1.64.8 built with go1.23.0']
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'command': ale#Escape('xxxinvalid')
|
||||
\ . ' run ' . g:ale_go_golangci_lint_options . ' --fix',
|
||||
\ . ' run --fix '
|
||||
\ . g:ale_go_golangci_formatter_options
|
||||
\ . ' ' . ale#Escape('testfile.go'),
|
||||
\ },
|
||||
\ ale#fixers#golangci_lint#Fix(bufnr(''))
|
||||
|
||||
Execute(The golangci-lint callback should support per-file mode):
|
||||
let g:ale_go_golangci_lint_package = 0
|
||||
Execute(The golangci-lint callback should return the correct default values with v2):
|
||||
|
||||
AssertEqual
|
||||
GivenCommandOutput ['golangci-lint has version 2.1.5 built with go1.23.0']
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'command': ale#Escape('golangci-lint') . ' fmt --stdin ',
|
||||
\ }
|
||||
|
||||
Execute(The golangci-lint callback should include custom golangci-lint options with v2):
|
||||
let g:ale_go_golangci_formatter_options = "--new --config /dev/null"
|
||||
|
||||
GivenCommandOutput ['golangci-lint has version 2.1.5 built with go1.23.0']
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'command': ale#Escape('golangci-lint')
|
||||
\ . ' fmt --stdin ' . g:ale_go_golangci_formatter_options,
|
||||
\ },
|
||||
|
||||
Execute(The golangci-lint callback should override executable with v2):
|
||||
let g:ale_go_golangci_formatter_executable = 'xxxinvalid'
|
||||
|
||||
GivenCommandOutput ['golangci-lint has version 2.1.5 built with go1.23.0']
|
||||
|
||||
AssertFixer
|
||||
\ {
|
||||
\ 'command': ale#Escape('xxxinvalid')
|
||||
\ . ' run '
|
||||
\ . g:ale_go_golangci_lint_options
|
||||
\ . ' --fix ' . ale#Escape('testfile.go'),
|
||||
\ . ' fmt --stdin '
|
||||
\ . g:ale_go_golangci_formatter_options
|
||||
\ },
|
||||
\ ale#fixers#golangci_lint#Fix(bufnr(''))
|
||||
@@ -0,0 +1,69 @@
|
||||
Before:
|
||||
call ale#assert#SetUpLinterTest('python', 'pyrefly')
|
||||
let b:bin_dir = has('win32') ? 'Scripts' : 'bin'
|
||||
|
||||
After:
|
||||
unlet! b:bin_dir
|
||||
unlet! b:executable
|
||||
call ale#assert#TearDownLinterTest()
|
||||
|
||||
Execute(The pyrefly command callback should return default string):
|
||||
call ale#test#SetFilename('./foo.py')
|
||||
|
||||
AssertLinter 'pyrefly', ale#Escape('pyrefly') . ' lsp'
|
||||
|
||||
Execute(The pyrefly executable should be configurable):
|
||||
let g:ale_python_pyrefly_executable = '~/.local/bin/pyrefly'
|
||||
|
||||
AssertLinter '~/.local/bin/pyrefly',
|
||||
\ ale#Escape('~/.local/bin/pyrefly') . ' lsp'
|
||||
|
||||
Execute(The pyrefly executable should be run from the virtualenv path):
|
||||
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
||||
|
||||
let b:executable = ale#path#Simplify(
|
||||
\ g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/pyrefly'
|
||||
\)
|
||||
|
||||
AssertLinter b:executable, ale#Escape(b:executable) . ' lsp'
|
||||
|
||||
Execute(You should be able to override the pyrefly virtualenv lookup):
|
||||
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
||||
|
||||
let g:ale_python_pyrefly_use_global = 1
|
||||
|
||||
AssertLinter 'pyrefly', ale#Escape('pyrefly') . ' lsp'
|
||||
|
||||
Execute(Setting executable to 'pipenv' appends 'run pyrefly'):
|
||||
let g:ale_python_pyrefly_executable = 'path/to/pipenv'
|
||||
call ale#test#SetFilename('../test-files/dummy')
|
||||
|
||||
AssertLinter 'path/to/pipenv',
|
||||
\ ale#Escape('path/to/pipenv') . ' run pyrefly lsp'
|
||||
|
||||
Execute(Pipenv is detected when python_pyrefly_auto_pipenv is set):
|
||||
let g:ale_python_pyrefly_auto_pipenv = 1
|
||||
call ale#test#SetFilename('../test-files/python/pipenv/whatever.py')
|
||||
|
||||
AssertLinter 'pipenv',
|
||||
\ ale#Escape('pipenv') . ' run pyrefly lsp'
|
||||
|
||||
Execute(Setting executable to 'poetry' appends 'run pyrefly lsp'):
|
||||
let g:ale_python_pyrefly_executable = 'path/to/poetry'
|
||||
|
||||
AssertLinter 'path/to/poetry',
|
||||
\ ale#Escape('path/to/poetry') . ' run pyrefly lsp'
|
||||
|
||||
Execute(Poetry is detected when python_pyrefly_auto_poetry is set):
|
||||
let g:ale_python_pyrefly_auto_poetry = 1
|
||||
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
|
||||
|
||||
AssertLinter 'poetry',
|
||||
\ ale#Escape('poetry') . ' run pyrefly lsp'
|
||||
|
||||
Execute(uv is detected when python_pyrefly_auto_uv is set):
|
||||
let g:ale_python_pyrefly_auto_uv = 1
|
||||
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
|
||||
|
||||
AssertLinter 'uv',
|
||||
\ ale#Escape('uv') . ' run pyrefly lsp'
|
||||
Whitespace-only changes.
Whitespace-only changes.
Reference in new issue
Block a user