sma
sma

Reputation: 9597

Vim Flake8 ignoring project config file

vim-flake8 seems to be ignoring my project-specific config file. If I run flake8 from the command line in my project root, it works, but when I open vim and try to run flake8 against my files, its not picking up that setting. I know this because its using a default line-length of 79, instead of my project-specific 120.

I read this post: flake8 not picking up config file, but it doesn't seem to help. It mentions a bug fixed over a year ago in the comments.

In my project root, I have a .flake8 file with a [flake8] section.

How does vim-flake8 determine what the project root is and where to look for the config file? Does it just use the directory in which Vim is opened?

Upvotes: 1

Views: 2059

Answers (4)

Ahmet C. Toker
Ahmet C. Toker

Reputation: 61

I couldn't get g:syntastic_python_flake8_* variations working on my MacOS.

The shortcut that worked for me was to add a symlink to the project base directory:

ln -s /path/to/common/.flake8 .flake8

with this link syntastic is forwarded to the .flake8 in the desired location.

Upvotes: 0

odie
odie

Reputation: 21

I ran into the same problem today. Flake8 ran fine from the command line, but inside of vim every config file seemed do be ignored by syntastic. Running flake8 inside of vim itself (with :!flake8) picked up the config.

Based on the answer from Tomi I fixed it by adding

    let g:syntastic_python_flake8_args='--config=setup.cfg'

to my vim config, which should work if vim is started from the project root. Still a bit hacky but at least the flake8 config stays in a single place.

Upvotes: 2

Tony S Yu
Tony S Yu

Reputation: 3173

I ran into a similar issue today, and I got around it by adding the following to my ~/.vimrc (or actually, my ~/.config/nvim/init.vim) file:

let g:syntastic_python_flake8_config_file='.flake8'

This was based on syntastic's official documentation on language-specific configuration files.

Upvotes: 3

Tomi Mickelsson
Tomi Mickelsson

Reputation: 309

Had the same problem too on my OSX, and partially solved it. Had the latest versions of syntastic (git clone today) and flake8 3.0.4. Vim 7.4.

flake8 ran fine from command line and picked my global ~/.config/flake8. Vim did not output anything if I had the config file, but worked fine without the flake8 config file.

I partially solved the problem by having the flake8 config not in file system but in my .vimrc:

let g:syntastic_python_flake8_args='--ignore=E203,E231'

but this is not the best solution as the config is not shared.

For the initiated developers, when I enable debugging

let g:syntastic_debug = 1

I get this output:

syntastic: 4.516990: &shell = '/bin/bash', &shellcmdflag = '-c', &shellpipe = '2
>&1| tee', &shellquote = '', &shellredir = '>%s 2>&1', &shellslash = 0, &shellte
mp = 1, &shellxquote = '', &shellxescape = ''
syntastic: 4.517587: UpdateErrors (auto): default checkers
syntastic: 4.517927: CacheErrors: default checkers
syntastic: 4.518502: g:syntastic_aggregate_errors = 0
syntastic: 4.518666: getcwd() = '/Volumes/myproject/src'
syntastic: 4.525418: CacheErrors: Invoking checker: python/flake8
syntastic: 4.526113: SyntasticMake: called with options: {'errorformat': '%E%f:%
l: could not compile,%-Z%p^,%A%f:%l:%c: %t%n %m,%A%f:%l: %t%n %m,%-G%.%#', 'make
prg': 'flake8 main.py', 'env': {'TERM': 'dumb'}}
syntastic: 4.727963: system: command run in 0.201426s
syntastic: 4.729751: getLocList: checker python/flake8 returned 1
syntastic: 4.730094: getLocList: checker python/flake8 run in 0.204568s

Upvotes: 0

Related Questions