Flycheck: flake8 checker ignores project-specific configuration

Created on 10 Aug 2015  路  5Comments  路  Source: flycheck/flycheck

I've been using the flake8 checker along with flycheck to lint my code on-the-fly for a while now. Recently I started a project that has some per-project flake8 configuration settings defined in a setup.cfg file at the root of the project repository.

When I run the flake8 executable outside of emacs, the configuration settings in this file are respected. However, it seems flycheck's flake8 checker does not respect these settings. I guess I have two questions about how flycheck sets things up that might clear this up.

  1. Does flycheck execute flake8 in the same directory as the source code? According to the flake8 documentation, flake8 will take settings from a per-project configuration file if it finds a [flake8] section in a setup.cfg file that lives in the current directory or any parent directory.
  2. Does flycheck have a special way for me to specify per-project configuration outside of flake8's built-in capabilities?

Thanks for your help!

blocked

Most helpful comment

I usually put a .dir-locals.el file at the project root containing:

((python-mode . ((flycheck-flake8rc . "setup.cfg"))))

All 5 comments

Flycheck runs `flake8 from the default directory of the buffer. Normally that's the directory the file is contained in.

I'm not sure what you mean with "flake8's built in capabilities ". I've never used flake8 and used to prefer pylint when I was writing large amounts of Python code, so my knowledge is very superficial here. Off the top of my head, I don't know how Flycheck invokes flake8 exactly, but you can take a look at the definition of the syntax checker to find out.

I usually put a .dir-locals.el file at the project root containing:

((python-mode . ((flycheck-flake8rc . "setup.cfg"))))

@ngoldbaum Does that solve your problem?

Yes, @fbergroth's suggestion works for me.

There's also a way to set a global option it in your ~/.emacs, from the editor. You can do M-x customize-group RET flycheck-config-files, and edit the "Flycheck Flake8rc" setting to .flake8.

The previous default was .flake8rc in my case.

The description of the setting is:

If set to a string, locate the configuration file using the
functions from `flycheck-locate-config-file-functions'. If the
file is found pass it to the syntax checker as configuration
file.
If no configuration file is found, or if this variable is set to
nil, invoke the syntax checker without a configuration file.
Use this variable as file-local variable if you need a specific
configuration file a buffer.

I suspect this would apply to all projects then. Unlike @fbergroth's approach.

Was this page helpful?
0 / 5 - 0 ratings