Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom good names #181

Closed
horejsek opened this issue Jul 17, 2018 · 5 comments
Closed

Custom good names #181

horejsek opened this issue Jul 17, 2018 · 5 comments

Comments

@horejsek
Copy link

After change in pull request #109 seems to be broken to ability to set own good names. Example pylintrc:

[MASTER]
load-plugins=pylint_django

[BASIC]
good-names=_,dt,e,f,default_app_config,logger

In version v0.7.2 it was working properly but starting version 0.8.0 it can be one or other. Probably previous version was merging two lists of good names which is not the case now.

@atodorov
Copy link
Contributor

atodorov commented Aug 2, 2018

@horejsek can you provide a code snippet that should work fine with your own good-names but doesn't?

I think the root cause of your problem may be related to how pylint deals with these settings, see: #167 (comment)

@horejsek
Copy link
Author

horejsek commented Aug 3, 2018

Code snippet could be simple urls.py like this one: https://docs.djangoproject.com/en/2.1/topics/http/urls/#example

It uses urlpatterns which is bad by pylint as it should be constant with uppercase, but OK by Django. This plugin adds this one name to good ones but when I have also own list of good names, then it's not working.

Let's see if it's bug or feature as you linked to other issue. From my point of view it looks like bug, though. :-)

@AC-TimRourke
Copy link

+1, I recently encountered this myself. I used pylint to autogenerate a .pylintrc file, and then when I started using pylint-django, the linter still threw errors about urlpatterns.

@Jean-Daniel
Copy link

ditto. both urlpatterns and app_name should be allowed in urls modules.

@matusvalo
Copy link
Contributor

I have the same issue that when after setting good-names in .pylintrc, false positive errors are raised for defaults of pylint-django. I have investigated the problem and it is because by setting good-names in .pylintrc, the defaults together with pylint-django good names are overridden. This can be easily proven:

  1. Execute pylint outside project with rcfile set - false positive error is raised for urlpatterns:
$ pylint --load-plugins=pylint_django --rcfile DJANGO_PROJECT_DIR/.pylintrc  DJANGO_PROJECT_DIR/MYPROJECT/MYPROJECT/urls.py
DJANGO_PROJECT_DIR/MYPROJECT/MYPROJECT/urls.py:26:0: C0103: Constant name "urlpatterns" doesn't conform to UPPER_CASE naming style (invalid-name)
  1. Execute pylint outside project without rcfile set - false positive error is not raised:
$ pylint --load-plugins=pylint_django DJANGO_PROJECT_DIR/MYPROJECT/MYPROJECT/urls.py
# urlpatterns issue is not reported

The problem is that pylint-django is extending default values:
https://github.com/PyCQA/pylint-django/blob/c5b5bfdef66453575074b36018ee716411bcb0a4/pylint_django/plugin.py#L19
which pylint overrides with values from configuration file [1]:

        if config_parser.has_option("MASTER", "load-plugins"):
            plugins = utils._splitstrip(config_parser.get("MASTER", "load-plugins"))
            linter.load_plugin_modules(plugins)
        # now we can load file config and command line, plugins (which can
        # provide options) have been registered
        linter.load_config_file()

Hence, I suggest that pylint plugins should have hooks which are called after configuration is loaded to inject plugin configurations. But this decition should be done in mainly in pylint.
[1] https://github.com/PyCQA/pylint/blob/fcc01516ae176ad3fdedc4497328105f3314e376/pylint/lint.py#L1566-L1571

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants