diff options
author | Kevin Locke <kevin@kevinlocke.name> | 2019-02-17 10:12:24 -0700 |
---|---|---|
committer | Kevin Locke <kevin@kevinlocke.name> | 2019-02-17 10:40:50 -0700 |
commit | 3300b1aca7f53a8468547194d074e1cb5bc55e15 (patch) | |
tree | b91fa66db7c68e172c26ea6739a02ddb1786af2a | |
parent | c3d4e0983b4b08e61692cdd88990a79525a78707 (diff) | |
download | ale-3300b1aca7f53a8468547194d074e1cb5bc55e15.zip |
python/pylint: Change directory to project root
Pylint only [checks for pylintrc] (and .pylintrc) files in the packages
aboves its current directory before falling back to user and global
pylintrc. For projects with a src dir, running pylint from the
directory containing the file will not use the project pylintrc.
Adopt the convention used by many other Python linters of running from
the project root, which solves this issue. Add pylintrc and .pylintrc
to FindProjectRoot. Update docs.
[checks for pylintrc]: https://github.com/PyCQA/pylint/blob/pylint-2.2.2/pylint/config.py#L106
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
-rw-r--r-- | ale_linters/python/pylint.vim | 14 | ||||
-rw-r--r-- | autoload/ale/python.vim | 2 | ||||
-rw-r--r-- | doc/ale-python.txt | 12 | ||||
-rw-r--r-- | test/command_callback/test_pylint_command_callback.vader | 6 |
4 files changed, 24 insertions, 10 deletions
diff --git a/ale_linters/python/pylint.vim b/ale_linters/python/pylint.vim index da845b7a..f0f79cd7 100644 --- a/ale_linters/python/pylint.vim +++ b/ale_linters/python/pylint.vim @@ -17,9 +17,17 @@ function! ale_linters#python#pylint#GetExecutable(buffer) abort endfunction function! ale_linters#python#pylint#GetCommand(buffer) abort - let l:cd_string = ale#Var(a:buffer, 'python_pylint_change_directory') - \ ? ale#path#BufferCdString(a:buffer) - \ : '' + let l:cd_string = '' + + if ale#Var(a:buffer, 'python_pylint_change_directory') + " pylint only checks for pylintrc in the packages above its current + " directory before falling back to user and global pylintrc. + " Run from project root, if found, otherwise buffer dir. + let l:project_root = ale#python#FindProjectRoot(a:buffer) + let l:cd_string = l:project_root isnot# '' + \ ? ale#path#CdString(l:project_root) + \ : ale#path#BufferCdString(a:buffer) + endif let l:executable = ale_linters#python#pylint#GetExecutable(a:buffer) diff --git a/autoload/ale/python.vim b/autoload/ale/python.vim index c911c046..2f28214b 100644 --- a/autoload/ale/python.vim +++ b/autoload/ale/python.vim @@ -28,6 +28,8 @@ function! ale#python#FindProjectRootIni(buffer) abort \|| filereadable(l:path . '/flake8.cfg') \|| filereadable(l:path . '/.flake8rc') \|| filereadable(l:path . '/pylama.ini') + \|| filereadable(l:path . '/pylintrc') + \|| filereadable(l:path . '/.pylintrc') \|| filereadable(l:path . '/Pipfile') \|| filereadable(l:path . '/Pipfile.lock') return l:path diff --git a/doc/ale-python.txt b/doc/ale-python.txt index f74e4e83..dd5d4cc6 100644 --- a/doc/ale-python.txt +++ b/doc/ale-python.txt @@ -32,6 +32,8 @@ ALE will look for configuration files with the following filenames. > flake8.cfg .flake8rc pylama.ini + pylintrc + .pylintrc Pipfile Pipfile.lock < @@ -512,10 +514,12 @@ g:ale_python_pylint_change_directory *g:ale_python_pylint_change_directory* Type: |Number| Default: `1` - If set to `1`, ALE will switch to the directory the Python file being - checked with `pylint` is in before checking it. This helps `pylint` find - configuration files more easily. This option can be turned off if you want - to control the directory Python is executed from yourself. + If set to `1`, `pylint` will be run from a detected project root, per + |ale-python-root|. Since `pylint` only checks for `pylintrc` in the packages + above its current directory before falling back to user and global `pylintrc` + files, this is necessary for `pylint` to use a project `pylintrc` file, if + present. This option can be turned off if you want to control the directory + Python is executed from yourself. g:ale_python_pylint_executable *g:ale_python_pylint_executable* diff --git a/test/command_callback/test_pylint_command_callback.vader b/test/command_callback/test_pylint_command_callback.vader index 6b21b127..c41c8398 100644 --- a/test/command_callback/test_pylint_command_callback.vader +++ b/test/command_callback/test_pylint_command_callback.vader @@ -39,7 +39,7 @@ Execute(The pylint callbacks shouldn't detect virtualenv directories where they silent execute 'file ' . fnameescape(g:dir . '/python_paths/no_virtualenv/subdir/foo/bar.py') AssertLinter 'pylint', - \ ale#path#BufferCdString(bufnr('')) + \ ale#path#CdString(ale#path#Simplify(g:dir . '/python_paths/no_virtualenv/subdir')) \ . ale#Escape('pylint') . ' ' . b:command_tail Execute(The pylint callbacks should detect virtualenv directories): @@ -50,7 +50,7 @@ Execute(The pylint callbacks should detect virtualenv directories): \) AssertLinter b:executable, - \ ale#path#BufferCdString(bufnr('')) + \ ale#path#CdString(ale#path#Simplify(g:dir . '/python_paths/with_virtualenv/subdir')) \ . ale#Escape(b:executable) . ' ' . b:command_tail Execute(You should able able to use the global pylint instead): @@ -58,7 +58,7 @@ Execute(You should able able to use the global pylint instead): let g:ale_python_pylint_use_global = 1 AssertLinter 'pylint', - \ ale#path#BufferCdString(bufnr('')) + \ ale#path#CdString(ale#path#Simplify(g:dir . '/python_paths/with_virtualenv/subdir')) \ . ale#Escape('pylint') . ' ' . b:command_tail Execute(Setting executable to 'pipenv' appends 'run pylint'): |