summaryrefslogtreecommitdiff
path: root/ale_linters/python/flake8.vim
diff options
context:
space:
mode:
authorKonstantin Alekseev <mail@kalekseev.com>2019-10-22 00:38:54 +0300
committerKonstantin Alekseev <mail@kalekseev.com>2020-08-30 22:56:10 +0300
commit1462de6685d7d71b7adba9f1b5e4f568b40da6b1 (patch)
tree607422568e1454ee37825782a2cc617f4597986a /ale_linters/python/flake8.vim
parent0989da4a38c80983548db623d407d7178f2452d5 (diff)
downloadale-1462de6685d7d71b7adba9f1b5e4f568b40da6b1.zip
Run flake8 from project root by default.
Option `per-file-ignores` was introduced in flake8 version 3.7.0. It allows to ignore specific errors in specific files using glob syntax. For example `per-file-ignores = src/generated/*.py:F401` will ignore `F401` error in all python files in `src/generated`. Thus ale has to run flake8 from project root where .flake8 config is placed otherwise glob won't match linted file.
Diffstat (limited to 'ale_linters/python/flake8.vim')
-rw-r--r--ale_linters/python/flake8.vim32
1 files changed, 28 insertions, 4 deletions
diff --git a/ale_linters/python/flake8.vim b/ale_linters/python/flake8.vim
index e2e7b743..85216ae8 100644
--- a/ale_linters/python/flake8.vim
+++ b/ale_linters/python/flake8.vim
@@ -4,7 +4,7 @@
call ale#Set('python_flake8_executable', 'flake8')
call ale#Set('python_flake8_options', '')
call ale#Set('python_flake8_use_global', get(g:, 'ale_use_global_executables', 0))
-call ale#Set('python_flake8_change_directory', 1)
+call ale#Set('python_flake8_change_directory', 'project')
call ale#Set('python_flake8_auto_pipenv', 0)
function! s:UsingModule(buffer) abort
@@ -38,10 +38,34 @@ function! ale_linters#python#flake8#RunWithVersionCheck(buffer) abort
\)
endfunction
+function! ale_linters#python#flake8#GetCdString(buffer) abort
+ let l:change_directory = ale#Var(a:buffer, 'python_flake8_change_directory')
+
+ " map legacy options to new ones
+ if l:change_directory is# 1
+ let l:change_directory = 'file'
+ elseif l:change_directory is# 0
+ let l:change_directory = 'off'
+ endif
+
+ if l:change_directory is# 'file'
+ return ale#path#BufferCdString(a:buffer)
+ elseif l:change_directory is# 'off'
+ return ''
+ endif
+
+ let l:project_root = ale#python#FindProjectRootIni(a:buffer)
+
+ if !empty(l:project_root)
+ return ale#path#CdString(l:project_root)
+ endif
+
+ return ale#path#BufferCdString(a:buffer)
+endfunction
+
function! ale_linters#python#flake8#GetCommand(buffer, version) abort
- let l:cd_string = ale#Var(a:buffer, 'python_flake8_change_directory')
- \ ? ale#path#BufferCdString(a:buffer)
- \ : ''
+ let l:cd_string = ale_linters#python#flake8#GetCdString(a:buffer)
+
let l:executable = ale_linters#python#flake8#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv$'