mirror of
https://github.com/dense-analysis/ale.git
synced 2026-11-27 05:33:55 +08:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b0f8d91bc | ||
|
|
9e49019a26 | ||
|
|
a0572359ae | ||
|
|
80ff84db84 | ||
|
|
c8c33e7217 |
No files matched your search
@@ -36,7 +36,7 @@ function! ale_linters#python#pylsp#GetCwd(buffer) abort
|
|||||||
\ 'name': 'pylsp',
|
\ 'name': 'pylsp',
|
||||||
\ 'project_root': function('ale#python#FindProjectRoot'),
|
\ 'project_root': function('ale#python#FindProjectRoot'),
|
||||||
\}
|
\}
|
||||||
let l:root = ale#lsp_linter#FindProjectRoot(a:buffer, l:fake_linter)
|
let l:root = ale#linter#GetRoot(a:buffer, l:fake_linter)
|
||||||
|
|
||||||
return !empty(l:root) ? l:root : v:null
|
return !empty(l:root) ? l:root : v:null
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ function! ale_linters#python#pyright#GetCwd(buffer) abort
|
|||||||
\ 'name': 'pyright',
|
\ 'name': 'pyright',
|
||||||
\ 'project_root': function('ale#python#FindProjectRoot'),
|
\ 'project_root': function('ale#python#FindProjectRoot'),
|
||||||
\}
|
\}
|
||||||
let l:root = ale#lsp_linter#FindProjectRoot(a:buffer, l:fake_linter)
|
let l:root = ale#linter#GetRoot(a:buffer, l:fake_linter)
|
||||||
|
|
||||||
return !empty(l:root) ? l:root : v:null
|
return !empty(l:root) ? l:root : v:null
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -72,10 +72,22 @@ function! ale_linters#python#ruff#Handle(buffer, lines) abort
|
|||||||
try
|
try
|
||||||
let l:item = json_decode(l:line)
|
let l:item = json_decode(l:line)
|
||||||
catch
|
catch
|
||||||
let l:item = v:null
|
" If we can't decode a line, skip it.
|
||||||
|
continue
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
if !empty(l:item)
|
if (l:item.code is# 'W291' || l:item.code is# 'W293')
|
||||||
|
\&& !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
|
||||||
|
" Skip warnings for trailing whitespace if the option is off.
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
|
||||||
|
if l:item.code is# 'W391'
|
||||||
|
\&& !ale#Var(a:buffer, 'warn_about_trailing_blank_lines')
|
||||||
|
" Skip warnings for trailing blank lines if the option is off
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
|
||||||
call add(l:output, {
|
call add(l:output, {
|
||||||
\ 'lnum': l:item.location.row,
|
\ 'lnum': l:item.location.row,
|
||||||
\ 'col': l:item.location.column,
|
\ 'col': l:item.location.column,
|
||||||
@@ -85,7 +97,6 @@ function! ale_linters#python#ruff#Handle(buffer, lines) abort
|
|||||||
\ 'text': l:item.message,
|
\ 'text': l:item.message,
|
||||||
\ 'type': l:item.code =~? '\vE\d+' ? 'E' : 'W',
|
\ 'type': l:item.code =~? '\vE\d+' ? 'E' : 'W',
|
||||||
\})
|
\})
|
||||||
endif
|
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
return l:output
|
return l:output
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ endfunction
|
|||||||
|
|
||||||
call ale#linter#Define('sh', {
|
call ale#linter#Define('sh', {
|
||||||
\ 'name': 'language_server',
|
\ 'name': 'language_server',
|
||||||
|
\ 'aliases': ['bash-language-server'],
|
||||||
\ 'lsp': 'stdio',
|
\ 'lsp': 'stdio',
|
||||||
\ 'executable': function('ale_linters#sh#language_server#GetExecutable'),
|
\ 'executable': function('ale_linters#sh#language_server#GetExecutable'),
|
||||||
\ 'command': function('ale_linters#sh#language_server#GetCommand'),
|
\ 'command': function('ale_linters#sh#language_server#GetCommand'),
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ endfunction
|
|||||||
function! ale#assert#LSPProject(expected_root) abort
|
function! ale#assert#LSPProject(expected_root) abort
|
||||||
let l:buffer = bufnr('')
|
let l:buffer = bufnr('')
|
||||||
let l:linter = s:GetLinter()
|
let l:linter = s:GetLinter()
|
||||||
let l:root = ale#lsp_linter#FindProjectRoot(l:buffer, l:linter)
|
let l:root = ale#linter#GetRoot(l:buffer, l:linter)
|
||||||
|
|
||||||
AssertEqual a:expected_root, l:root
|
AssertEqual a:expected_root, l:root
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -447,3 +447,32 @@ function! ale#linter#GetAddress(buffer, linter) abort
|
|||||||
|
|
||||||
return type(l:Address) is v:t_func ? l:Address(a:buffer) : l:Address
|
return type(l:Address) is v:t_func ? l:Address(a:buffer) : l:Address
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Get the project root for a linter.
|
||||||
|
" If |b:ale_root| or |g:ale_root| is set to either a String or a Dict mapping
|
||||||
|
" linter names to roots or callbacks, return that value immediately. When no
|
||||||
|
" value is available, fall back to the linter-specific configuration.
|
||||||
|
function! ale#linter#GetRoot(buffer, linter) abort
|
||||||
|
let l:buffer_ale_root = getbufvar(a:buffer, 'ale_root', {})
|
||||||
|
|
||||||
|
if type(l:buffer_ale_root) is v:t_string
|
||||||
|
return l:buffer_ale_root
|
||||||
|
endif
|
||||||
|
|
||||||
|
if has_key(l:buffer_ale_root, a:linter.name)
|
||||||
|
let l:Root = l:buffer_ale_root[a:linter.name]
|
||||||
|
return type(l:Root) is v:t_func ? l:Root(a:buffer) : l:Root
|
||||||
|
endif
|
||||||
|
|
||||||
|
if has_key(g:ale_root, a:linter.name)
|
||||||
|
let l:Root = g:ale_root[a:linter.name]
|
||||||
|
return type(l:Root) is v:t_func ? l:Root(a:buffer) : l:Root
|
||||||
|
endif
|
||||||
|
|
||||||
|
if has_key(a:linter, 'project_root')
|
||||||
|
let l:Root = a:linter.project_root
|
||||||
|
return type(l:Root) is v:t_func ? l:Root(a:buffer) : l:Root
|
||||||
|
endif
|
||||||
|
|
||||||
|
return ''
|
||||||
|
endfunction
|
||||||
@@ -296,44 +296,6 @@ function! ale#lsp_linter#GetConfig(buffer, linter) abort
|
|||||||
return {}
|
return {}
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#lsp_linter#FindProjectRoot(buffer, linter) abort
|
|
||||||
let l:buffer_ale_root = getbufvar(a:buffer, 'ale_root', {})
|
|
||||||
|
|
||||||
if type(l:buffer_ale_root) is v:t_string
|
|
||||||
return l:buffer_ale_root
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Try to get a buffer-local setting for the root
|
|
||||||
if has_key(l:buffer_ale_root, a:linter.name)
|
|
||||||
let l:Root = l:buffer_ale_root[a:linter.name]
|
|
||||||
|
|
||||||
if type(l:Root) is v:t_func
|
|
||||||
return l:Root(a:buffer)
|
|
||||||
else
|
|
||||||
return l:Root
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Try to get a global setting for the root
|
|
||||||
if has_key(g:ale_root, a:linter.name)
|
|
||||||
let l:Root = g:ale_root[a:linter.name]
|
|
||||||
|
|
||||||
if type(l:Root) is v:t_func
|
|
||||||
return l:Root(a:buffer)
|
|
||||||
else
|
|
||||||
return l:Root
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Fall back to the linter-specific configuration
|
|
||||||
if has_key(a:linter, 'project_root')
|
|
||||||
let l:Root = a:linter.project_root
|
|
||||||
|
|
||||||
return type(l:Root) is v:t_func ? l:Root(a:buffer) : l:Root
|
|
||||||
endif
|
|
||||||
|
|
||||||
return ale#util#GetFunction(a:linter.project_root_callback)(a:buffer)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" This function is accessible so tests can call it.
|
" This function is accessible so tests can call it.
|
||||||
function! ale#lsp_linter#OnInit(linter, details, Callback) abort
|
function! ale#lsp_linter#OnInit(linter, details, Callback) abort
|
||||||
@@ -504,7 +466,7 @@ endfunction
|
|||||||
function! ale#lsp_linter#StartLSP(buffer, linter, Callback) abort
|
function! ale#lsp_linter#StartLSP(buffer, linter, Callback) abort
|
||||||
let l:command = ''
|
let l:command = ''
|
||||||
let l:address = ''
|
let l:address = ''
|
||||||
let l:root = ale#lsp_linter#FindProjectRoot(a:buffer, a:linter)
|
let l:root = ale#linter#GetRoot(a:buffer, a:linter)
|
||||||
|
|
||||||
if empty(l:root) && a:linter.lsp isnot# 'tsserver'
|
if empty(l:root) && a:linter.lsp isnot# 'tsserver'
|
||||||
" If there's no project root, then we can't check files with LSP,
|
" If there's no project root, then we can't check files with LSP,
|
||||||
|
|||||||
@@ -115,12 +115,11 @@ endfunction
|
|||||||
|
|
||||||
" Return 1 if a path is an absolute path.
|
" Return 1 if a path is an absolute path.
|
||||||
function! ale#path#IsAbsolute(filename) abort
|
function! ale#path#IsAbsolute(filename) abort
|
||||||
if has('win32') && a:filename[:0] is# '\'
|
if has('win32')
|
||||||
return 1
|
return a:filename[:0] =~# '[\\/]' || a:filename[0:2] =~? '[A-Z]:[/\\]'
|
||||||
|
else
|
||||||
|
return a:filename[:0] is# '/'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Check for /foo and C:\foo, etc.
|
|
||||||
return a:filename[:0] is# '/' || a:filename[1:2] is# ':\'
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:temp_dir = ale#path#Simplify(fnamemodify(ale#util#Tempname(), ':h:h'))
|
let s:temp_dir = ale#path#Simplify(fnamemodify(ale#util#Tempname(), ':h:h'))
|
||||||
|
|||||||
+12
-6
@@ -26,7 +26,6 @@ function! ale#python#FindProjectRootIni(buffer) abort
|
|||||||
" If you change this, update ale-python-root documentation.
|
" If you change this, update ale-python-root documentation.
|
||||||
if filereadable(l:path . '/MANIFEST.in')
|
if filereadable(l:path . '/MANIFEST.in')
|
||||||
\|| filereadable(l:path . '/setup.cfg')
|
\|| filereadable(l:path . '/setup.cfg')
|
||||||
\|| filereadable(l:path . '/pytest.ini')
|
|
||||||
\|| filereadable(l:path . '/tox.ini')
|
\|| filereadable(l:path . '/tox.ini')
|
||||||
\|| filereadable(l:path . '/.pyre_configuration.local')
|
\|| filereadable(l:path . '/.pyre_configuration.local')
|
||||||
\|| filereadable(l:path . '/mypy.ini')
|
\|| filereadable(l:path . '/mypy.ini')
|
||||||
@@ -55,12 +54,19 @@ endfunction
|
|||||||
" Given a buffer number, find the project root directory for Python.
|
" Given a buffer number, find the project root directory for Python.
|
||||||
" The root directory is defined as the first directory found while searching
|
" The root directory is defined as the first directory found while searching
|
||||||
" upwards through paths, including the current directory, until a path
|
" upwards through paths, including the current directory, until a path
|
||||||
" containing an init file (one from MANIFEST.in, setup.cfg, pytest.ini,
|
" containing an configuration file is found. (See list above)
|
||||||
" tox.ini) is found. If it is not possible to find the project root directory
|
"
|
||||||
" via init file, then it will be defined as the first directory found
|
" If it is not possible to find the project root directory via configuration
|
||||||
" searching upwards through paths, including the current directory, until no
|
" file, then it will be defined as the first directory found searching upwards
|
||||||
" __init__.py files is found.
|
" through paths, including the current directory, until no __init__.py files
|
||||||
|
" is found.
|
||||||
function! ale#python#FindProjectRoot(buffer) abort
|
function! ale#python#FindProjectRoot(buffer) abort
|
||||||
|
let l:root = ale#linter#GetRoot(a:buffer, {'name': 'python'})
|
||||||
|
|
||||||
|
if !empty(l:root)
|
||||||
|
return l:root
|
||||||
|
endif
|
||||||
|
|
||||||
let l:ini_root = ale#python#FindProjectRootIni(a:buffer)
|
let l:ini_root = ale#python#FindProjectRootIni(a:buffer)
|
||||||
|
|
||||||
if !empty(l:ini_root)
|
if !empty(l:ini_root)
|
||||||
|
|||||||
+4
-1
@@ -55,6 +55,9 @@ For some linters, ALE will search for a Python project root by looking at the
|
|||||||
files in directories on or above where a file being checked is. ALE applies
|
files in directories on or above where a file being checked is. ALE applies
|
||||||
the following methods, in order:
|
the following methods, in order:
|
||||||
|
|
||||||
|
If |g:ale_root| or |b:ale_root| provides a value, that value is used as the
|
||||||
|
project root instead and the searching described below is skipped.
|
||||||
|
|
||||||
1. Find the first directory containing a common Python configuration file.
|
1. Find the first directory containing a common Python configuration file.
|
||||||
2. If no configuration file can be found, use the first directory which does
|
2. If no configuration file can be found, use the first directory which does
|
||||||
not contain a readable file named `__init__.py`.
|
not contain a readable file named `__init__.py`.
|
||||||
@@ -63,7 +66,6 @@ ALE will look for configuration files with the following filenames. >
|
|||||||
|
|
||||||
MANIFEST.in
|
MANIFEST.in
|
||||||
setup.cfg
|
setup.cfg
|
||||||
pytest.ini
|
|
||||||
tox.ini
|
tox.ini
|
||||||
.pyre_configuration.local
|
.pyre_configuration.local
|
||||||
mypy.ini
|
mypy.ini
|
||||||
@@ -81,6 +83,7 @@ ALE will look for configuration files with the following filenames. >
|
|||||||
poetry.lock
|
poetry.lock
|
||||||
pyproject.toml
|
pyproject.toml
|
||||||
.tool-versions
|
.tool-versions
|
||||||
|
uv.lock
|
||||||
<
|
<
|
||||||
|
|
||||||
The first directory containing any of the files named above will be used.
|
The first directory containing any of the files named above will be used.
|
||||||
|
|||||||
+9
-8
@@ -2297,17 +2297,18 @@ g:ale_root
|
|||||||
Type: |Dictionary| or |String|
|
Type: |Dictionary| or |String|
|
||||||
Default: `{}`
|
Default: `{}`
|
||||||
|
|
||||||
This option is used to determine the project root for a linter. If the value
|
This option is used to determine the project root for a linter. When set to a
|
||||||
is a |Dictionary|, it maps a linter to either a |String| containing the
|
|String| it will be used for all linters. When set to a |Dictionary|, the
|
||||||
project root or a |Funcref| to call to look up the root. The |Funcref| is
|
keys are linter names and the values are either |Strings| containing project
|
||||||
provided the buffer number as its argument.
|
roots or |Funcref|s which are passed the buffer number.
|
||||||
|
|
||||||
The buffer-specific variable may additionally be a string containing the
|
The buffer-specific variable may additionally be a |String| containing the
|
||||||
project root itself.
|
project root itself.
|
||||||
|
|
||||||
If neither variable yields a result, a linter-specific function is invoked to
|
If a value can be found from either variable, ALE uses it directly and skips
|
||||||
detect a project root. If this, too, yields no result, and the linter is an
|
searching for a project root. If no value is found, a linter-specific
|
||||||
LSP linter, it will not run.
|
function is invoked to detect a project root. If this, too, yields no result
|
||||||
|
and the linter is an LSP linter, it will not run.
|
||||||
|
|
||||||
*ale-options.save_hidden*
|
*ale-options.save_hidden*
|
||||||
*g:ale_save_hidden*
|
*g:ale_save_hidden*
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ Execute(The mypy handler should handle Windows names with spaces):
|
|||||||
\ {
|
\ {
|
||||||
\ 'lnum': 4,
|
\ 'lnum': 4,
|
||||||
\ 'col': 0,
|
\ 'col': 0,
|
||||||
\ 'filename': ale#path#Simplify('C:\something\with spaces.py'),
|
\ 'filename': ale#path#GetAbsPath(getcwd(), 'C:\something\with spaces.py'),
|
||||||
\ 'type': 'E',
|
\ 'type': 'E',
|
||||||
\ 'text': 'No library stub file for module ''django.db''',
|
\ 'text': 'No library stub file for module ''django.db''',
|
||||||
\ },
|
\ },
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
Before:
|
Before:
|
||||||
|
Save g:ale_warn_about_trailing_blank_lines
|
||||||
|
Save g:ale_warn_about_trailing_whitespace
|
||||||
|
|
||||||
|
let g:ale_warn_about_trailing_blank_lines = 1
|
||||||
|
let g:ale_warn_about_trailing_whitespace = 1
|
||||||
|
|
||||||
runtime ale_linters/python/ruff.vim
|
runtime ale_linters/python/ruff.vim
|
||||||
|
|
||||||
After:
|
After:
|
||||||
|
Restore
|
||||||
|
|
||||||
|
unlet! b:ale_warn_about_trailing_blank_lines
|
||||||
|
unlet! b:ale_warn_about_trailing_whitespace
|
||||||
|
|
||||||
call ale#linter#Reset()
|
call ale#linter#Reset()
|
||||||
|
|
||||||
Execute(We should handle basic output of ruff correctly):
|
Execute(We should handle basic output of ruff correctly):
|
||||||
@@ -41,3 +52,66 @@ Execute(We should handle mixed error lines and JSON output from ruff):
|
|||||||
\ 'ERROR: oh noes!',
|
\ 'ERROR: oh noes!',
|
||||||
\ '{"cell":null,"code":"F821","end_location":{"column":8,"row":2},"filename":"/home/eduardo/Code/Python/test.py","fix":null,"location":{"column":1,"row":2},"message":"Undefined name example","noqa_row":2,"url":"https://docs.astral.sh/ruff/rules/undefined-name"}',
|
\ '{"cell":null,"code":"F821","end_location":{"column":8,"row":2},"filename":"/home/eduardo/Code/Python/test.py","fix":null,"location":{"column":1,"row":2},"message":"Undefined name example","noqa_row":2,"url":"https://docs.astral.sh/ruff/rules/undefined-name"}',
|
||||||
\ ])
|
\ ])
|
||||||
|
|
||||||
|
Execute(Warnings about trailing whitespace should be reported by default):
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 6,
|
||||||
|
\ 'col': 1,
|
||||||
|
\ 'end_lnum': 6,
|
||||||
|
\ 'end_col': 1,
|
||||||
|
\ 'code': 'W291',
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'text': 'who cares',
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 6,
|
||||||
|
\ 'col': 1,
|
||||||
|
\ 'end_lnum': 6,
|
||||||
|
\ 'end_col': 1,
|
||||||
|
\ 'code': 'W293',
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'text': 'who cares',
|
||||||
|
\ },
|
||||||
|
\ ],
|
||||||
|
\ ale_linters#python#ruff#Handle(bufnr(''), [
|
||||||
|
\ '{"cell":null,"code":"W291","end_location":{"column":2,"row":6},"filename":"/test.py","fix":null,"location":{"column":1,"row":6},"message":"who cares","noqa_row":2,"url":""}',
|
||||||
|
\ '{"cell":null,"code":"W293","end_location":{"column":2,"row":6},"filename":"/test.py","fix":null,"location":{"column":1,"row":6},"message":"who cares","noqa_row":2,"url":""}',
|
||||||
|
\ ])
|
||||||
|
|
||||||
|
Execute(Disabling trailing whitespace warnings should work):
|
||||||
|
let b:ale_warn_about_trailing_whitespace = 0
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ [],
|
||||||
|
\ ale_linters#python#ruff#Handle(bufnr(''), [
|
||||||
|
\ '{"cell":null,"code":"W291","end_location":{"column":2,"row":6},"filename":"/test.py","fix":null,"location":{"column":1,"row":6},"message":"who cares","noqa_row":2,"url":""}',
|
||||||
|
\ '{"cell":null,"code":"W293","end_location":{"column":2,"row":6},"filename":"/test.py","fix":null,"location":{"column":1,"row":6},"message":"who cares","noqa_row":2,"url":""}',
|
||||||
|
\ ])
|
||||||
|
|
||||||
|
Execute(Warnings about trailing blank lines should be reported by default):
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 6,
|
||||||
|
\ 'col': 1,
|
||||||
|
\ 'end_lnum': 6,
|
||||||
|
\ 'end_col': 1,
|
||||||
|
\ 'code': 'W391',
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'text': 'blank line at end of file',
|
||||||
|
\ },
|
||||||
|
\ ],
|
||||||
|
\ ale_linters#python#ruff#Handle(bufnr(''), [
|
||||||
|
\ '{"cell":null,"code":"W391","end_location":{"column":2,"row":6},"filename":"/test.py","fix":null,"location":{"column":1,"row":6},"message":"blank line at end of file","noqa_row":2,"url":""}',
|
||||||
|
\ ])
|
||||||
|
|
||||||
|
Execute(Disabling trailing blank line warnings should work):
|
||||||
|
let b:ale_warn_about_trailing_blank_lines = 0
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ [],
|
||||||
|
\ ale_linters#python#ruff#Handle(bufnr(''), [
|
||||||
|
\ '{"cell":null,"code":"W391","end_location":{"column":2,"row":6},"filename":"/test.py","fix":null,"location":{"column":1,"row":6},"message":"blank line at end of file","noqa_row":2,"url":""}',
|
||||||
|
\ ])
|
||||||
@@ -125,35 +125,35 @@ Execute(The flake8 callbacks should detect virtualenv directories):
|
|||||||
\ . ' --stdin-display-name %s -',
|
\ . ' --stdin-display-name %s -',
|
||||||
\]
|
\]
|
||||||
|
|
||||||
Execute(The FindProjectRoot should detect the project root directory for namespace package via Manifest.in):
|
Execute(FindProjectRoot should detect the project root directory for namespace package via Manifest.in):
|
||||||
call ale#test#SetFilename('../test-files/python/namespace_package_manifest/namespace/foo/bar.py')
|
call ale#test#SetFilename('../test-files/python/namespace_package_manifest/namespace/foo/bar.py')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_manifest'),
|
\ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_manifest'),
|
||||||
\ ale#python#FindProjectRoot(bufnr(''))
|
\ ale#python#FindProjectRoot(bufnr(''))
|
||||||
|
|
||||||
Execute(The FindProjectRoot should detect the project root directory for namespace package via setup.cf):
|
Execute(FindProjectRoot should detect the project root directory for namespace package via setup.cf):
|
||||||
call ale#test#SetFilename('../test-files/python/namespace_package_setup/namespace/foo/bar.py')
|
call ale#test#SetFilename('../test-files/python/namespace_package_setup/namespace/foo/bar.py')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_setup'),
|
\ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_setup'),
|
||||||
\ ale#python#FindProjectRoot(bufnr(''))
|
\ ale#python#FindProjectRoot(bufnr(''))
|
||||||
|
|
||||||
Execute(The FindProjectRoot should detect the project root directory for namespace package via pytest.ini):
|
Execute(FindProjectRoot should ignore the location of pytest.ini):
|
||||||
call ale#test#SetFilename('../test-files/python/namespace_package_pytest/namespace/foo/bar.py')
|
call ale#test#SetFilename('../test-files/python/namespace_package_pytest/namespace/foo/bar.py')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_pytest'),
|
\ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_pytest/namespace'),
|
||||||
\ ale#python#FindProjectRoot(bufnr(''))
|
\ ale#python#FindProjectRoot(bufnr(''))
|
||||||
|
|
||||||
Execute(The FindProjectRoot should detect the project root directory for namespace package via tox.ini):
|
Execute(FindProjectRoot should detect the project root directory for namespace package via tox.ini):
|
||||||
call ale#test#SetFilename('../test-files/python/namespace_package_tox/namespace/foo/bar.py')
|
call ale#test#SetFilename('../test-files/python/namespace_package_tox/namespace/foo/bar.py')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_tox'),
|
\ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_tox'),
|
||||||
\ ale#python#FindProjectRoot(bufnr(''))
|
\ ale#python#FindProjectRoot(bufnr(''))
|
||||||
|
|
||||||
Execute(The FindProjectRoot should detect the project root directory for non-namespace package):
|
Execute(FindProjectRoot should detect the project root directory for non-namespace package):
|
||||||
call ale#test#SetFilename('../test-files/python/no_virtualenv/subdir/foo/bar.py')
|
call ale#test#SetFilename('../test-files/python/no_virtualenv/subdir/foo/bar.py')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
|
|||||||
@@ -111,41 +111,6 @@ Execute(The flakehell callbacks should detect virtualenv directories):
|
|||||||
\ . ' --stdin-display-name %s -',
|
\ . ' --stdin-display-name %s -',
|
||||||
\]
|
\]
|
||||||
|
|
||||||
Execute(The FindProjectRoot should detect the project root directory for namespace package via Manifest.in):
|
|
||||||
call ale#test#SetFilename('../test-files/python/namespace_package_manifest/namespace/foo/bar.py')
|
|
||||||
|
|
||||||
AssertEqual
|
|
||||||
\ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_manifest'),
|
|
||||||
\ ale#python#FindProjectRoot(bufnr(''))
|
|
||||||
|
|
||||||
Execute(The FindProjectRoot should detect the project root directory for namespace package via setup.cf):
|
|
||||||
call ale#test#SetFilename('../test-files/python/namespace_package_setup/namespace/foo/bar.py')
|
|
||||||
|
|
||||||
AssertEqual
|
|
||||||
\ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_setup'),
|
|
||||||
\ ale#python#FindProjectRoot(bufnr(''))
|
|
||||||
|
|
||||||
Execute(The FindProjectRoot should detect the project root directory for namespace package via pytest.ini):
|
|
||||||
call ale#test#SetFilename('../test-files/python/namespace_package_pytest/namespace/foo/bar.py')
|
|
||||||
|
|
||||||
AssertEqual
|
|
||||||
\ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_pytest'),
|
|
||||||
\ ale#python#FindProjectRoot(bufnr(''))
|
|
||||||
|
|
||||||
Execute(The FindProjectRoot should detect the project root directory for namespace package via tox.ini):
|
|
||||||
call ale#test#SetFilename('../test-files/python/namespace_package_tox/namespace/foo/bar.py')
|
|
||||||
|
|
||||||
AssertEqual
|
|
||||||
\ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_tox'),
|
|
||||||
\ ale#python#FindProjectRoot(bufnr(''))
|
|
||||||
|
|
||||||
Execute(The FindProjectRoot should detect the project root directory for non-namespace package):
|
|
||||||
call ale#test#SetFilename('../test-files/python/no_virtualenv/subdir/foo/bar.py')
|
|
||||||
|
|
||||||
AssertEqual
|
|
||||||
\ ale#path#Simplify(g:dir . '/../test-files/python/no_virtualenv/subdir'),
|
|
||||||
\ ale#python#FindProjectRoot(bufnr(''))
|
|
||||||
|
|
||||||
" Some users currently run flakehell this way, so we should support it.
|
" Some users currently run flakehell this way, so we should support it.
|
||||||
Execute(Using `python -m flakehell` should be supported for running flakehell):
|
Execute(Using `python -m flakehell` should be supported for running flakehell):
|
||||||
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
||||||
|
|||||||
@@ -13,6 +13,15 @@ Execute(Relative paths should be resolved correctly):
|
|||||||
AssertEqual
|
AssertEqual
|
||||||
\ 'C:\foo\bar\baz\whatever.txt',
|
\ 'C:\foo\bar\baz\whatever.txt',
|
||||||
\ ale#path#GetAbsPath('C:\foo\bar\baz\xyz', '../whatever.txt')
|
\ ale#path#GetAbsPath('C:\foo\bar\baz\xyz', '../whatever.txt')
|
||||||
|
AssertEqual
|
||||||
|
\ 'C:\foo\bar\baz\whatever.txt',
|
||||||
|
\ ale#path#GetAbsPath('C:\foo\bar\baz\xyz', '..\whatever.txt')
|
||||||
|
AssertEqual
|
||||||
|
\ 'C:\foo\bar\baz\whatever.txt',
|
||||||
|
\ ale#path#GetAbsPath('C:/foo/bar/baz/xyz', '../whatever.txt')
|
||||||
|
AssertEqual
|
||||||
|
\ 'C:\foo\bar\baz\whatever.txt',
|
||||||
|
\ ale#path#GetAbsPath('C:/foo/bar/baz/xyz', '..\whatever.txt')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
Execute(Absolute paths should be resolved correctly):
|
Execute(Absolute paths should be resolved correctly):
|
||||||
@@ -26,4 +35,12 @@ Execute(Absolute paths should be resolved correctly):
|
|||||||
|
|
||||||
if has('win32')
|
if has('win32')
|
||||||
AssertEqual '\ding', ale#path#GetAbsPath('/foo/bar/xyz', '\\ding')
|
AssertEqual '\ding', ale#path#GetAbsPath('/foo/bar/xyz', '\\ding')
|
||||||
|
AssertEqual 'c:\ding', ale#path#GetAbsPath('/foo/bar/xyz', 'c:/ding')
|
||||||
|
AssertEqual 'c:\ding', ale#path#GetAbsPath('/foo/bar/xyz', 'c:\ding')
|
||||||
|
AssertEqual 'c:\ding', ale#path#GetAbsPath('\foo\bar\xyz', 'c:/ding')
|
||||||
|
AssertEqual 'c:\ding', ale#path#GetAbsPath('\foo\bar\xyz', 'c:\ding')
|
||||||
|
AssertEqual 'c:\ding', ale#path#GetAbsPath('c:/foo/bar/xyz', 'c:/ding')
|
||||||
|
AssertEqual 'c:\ding', ale#path#GetAbsPath('c:/foo/bar/xyz', 'c:\ding')
|
||||||
|
AssertEqual 'c:\ding', ale#path#GetAbsPath('c:\foo\bar\xyz', 'c:/ding')
|
||||||
|
AssertEqual 'c:\ding', ale#path#GetAbsPath('c:\foo\bar\xyz', 'c:\ding')
|
||||||
endif
|
endif
|
||||||
@@ -407,7 +407,7 @@ Execute(PreProcess should allow the `project_root` to be set as a String):
|
|||||||
\ 'project_root': '/foo/bar',
|
\ 'project_root': '/foo/bar',
|
||||||
\})
|
\})
|
||||||
|
|
||||||
AssertEqual '/foo/bar', ale#lsp_linter#FindProjectRoot(0, g:linter)
|
AssertEqual '/foo/bar', ale#linter#GetRoot(0, g:linter)
|
||||||
|
|
||||||
Execute(PreProcess should `project_root` be set as a Function):
|
Execute(PreProcess should `project_root` be set as a Function):
|
||||||
let g:linter = ale#linter#PreProcess('testft', {
|
let g:linter = ale#linter#PreProcess('testft', {
|
||||||
@@ -418,7 +418,7 @@ Execute(PreProcess should `project_root` be set as a Function):
|
|||||||
\ 'project_root': {-> '/foo/bar'},
|
\ 'project_root': {-> '/foo/bar'},
|
||||||
\})
|
\})
|
||||||
|
|
||||||
AssertEqual '/foo/bar', ale#lsp_linter#FindProjectRoot(0, g:linter)
|
AssertEqual '/foo/bar', ale#linter#GetRoot(0, g:linter)
|
||||||
|
|
||||||
Execute(PreProcess should complain when `project_root` is invalid):
|
Execute(PreProcess should complain when `project_root` is invalid):
|
||||||
AssertThrows call ale#linter#PreProcess('testft', {
|
AssertThrows call ale#linter#PreProcess('testft', {
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
Before:
|
||||||
|
Save g:ale_root
|
||||||
|
Save b:ale_root
|
||||||
|
call ale#test#SetDirectory('/testplugin/test')
|
||||||
|
|
||||||
|
After:
|
||||||
|
Restore
|
||||||
|
call ale#test#RestoreDirectory()
|
||||||
|
|
||||||
|
Execute(The global setting is used as the project root):
|
||||||
|
let g:ale_root = '/foo/python'
|
||||||
|
call ale#test#SetFilename('test-files/python/no_virtualenv/subdir/foo/bar.py')
|
||||||
|
AssertEqual '/foo/python', ale#python#FindProjectRoot(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The buffer setting overrides the global setting):
|
||||||
|
let g:ale_root = '/foo/python'
|
||||||
|
let b:ale_root = '/bar/python'
|
||||||
|
call ale#test#SetFilename('test-files/python/no_virtualenv/subdir/foo/bar.py')
|
||||||
|
AssertEqual '/bar/python', ale#python#FindProjectRoot(bufnr(''))
|
||||||
|
|
||||||
|
Execute(Fallback to searching when no setting is used):
|
||||||
|
unlet! g:ale_root
|
||||||
|
unlet! b:ale_root
|
||||||
|
call ale#test#SetFilename('test-files/python/no_virtualenv/subdir/foo/bar.py')
|
||||||
|
AssertEqual \
|
||||||
|
\ ale#path#Simplify(g:dir . '/../test-files/python/no_virtualenv/subdir'),
|
||||||
|
\ ale#python#FindProjectRoot(bufnr(''))
|
||||||
Reference in new issue
Block a user