Skip to content

Cannot override linter options per project #1158

Description

@ziirish

The following code prevents us from overriding the linter options per project.

for linter in linters:
opts = env.var('g:pymode_lint_options_%s' % linter, silence=True)
if opts:
options.linters_params[linter] = options.linters_params.get(
linter, {})
options.linters_params[linter].update(opts)

Here is what the pymode logs show (I have added some log line 53 to see what is set globally):

pymode debug msg 9: check code
1661433148 ['pyflakes', 'pep8'] []
1661433148 Namespace(paths=['/tmp/bla'], verbose=False, format='pycodestyle', select=[], sort=[], linters=[('pyflakes', <pylama.lint.pylama_pyflakes.Linter object at 0x7f177ab71870>), ('pep8', <pylama.lint.pylama_pycodestyle.Linter object
at 0x7f177ab71990>)], ignore=['W'], skip=[], report=None, hook=False, concurrent=False, options='/tmp/bla/pylama.ini', force=True, abspath=False, file_params={}, linters_params={'pep8': {'max_line_length': 101}}) []
1661433148 g:pymode_lint_options_pyflakes -> {'builtins': '_'} []
1661433148 g:pymode_lint_options_pep8 -> {'max_line_length': '79'} []
1661433148 Start code check:  [wrong.py]
Checking params: {'skip': False, 'ignore': {'W'}, 'select': set(), 'linters': []} - Namespace(paths=['/tmp/bla'], verbose=False, format='pycodestyle', select=[], sort=[], linters=[('pyflakes', <pylama.lint.pylama_pyflakes.Linter object at
0x7f177ab71870>), ('pep8', <pylama.lint.pylama_pycodestyle.Linter object at 0x7f177ab71990>)], ignore=['W'], skip=[], report=None, hook=False, concurrent=False, options='/tmp/bla/pylama.ini', force=True, abspath=False, file_params={}, lint
ers_params={'pep8': {'max_line_length': '79'}, 'pyflakes': {'builtins': '_'}})
Run pyflakes {'builtins': '_'}
Run pep8 {'max_line_length': '79'}

As you can see, pylama finds its custom settings inside the pylama.ini file, but they are then overridden.

I would have expected the pylama.ini settings to override the global ones but it's definitely not the case.

I'd suggest the code above to be replaced with:

        for linter in linters:
            opts = env.var('g:pymode_lint_options_%s' % linter, silence=True)
            if opts:
                opts_override = options.linters_params.get(linter, {})
                options.linters_params[linter] = opts
                options.linters_params[linter].update(opts_override)

I can open a PR if needed

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions