Skip to content

Add support for new load_configuration hook of pylint #214

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

Merged
merged 1 commit into from
Dec 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
* [atodorov](https://github.com/atodorov)
* [bittner](https://github.com/bittner)
* [federicobond](https://github.com/federicobond)
* [matusvalo](https://github.com/matusvalo)
9 changes: 7 additions & 2 deletions pylint_django/checkers/db_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pylint import checkers
from pylint.checkers import utils
from pylint_django.__pkginfo__ import BASE_ID
from pylint_django import compat


def _is_addfield_with_default(call):
Expand Down Expand Up @@ -113,12 +114,16 @@ def _path(node):
self.add_message('new-db-field-with-default', args=module.name, node=node)


def register(linter):
"""Required method to auto register this checker."""
def load_configuration(linter):
# don't blacklist migrations for this checker
new_black_list = list(linter.config.black_list)
if 'migrations' in new_black_list:
new_black_list.remove('migrations')
linter.config.black_list = new_black_list


def register(linter):
"""Required method to auto register this checker."""
linter.register_checker(NewDbFieldWithDefaultChecker(linter))
if not compat.LOAD_CONFIGURATION_SUPPORTED:
load_configuration(linter)
4 changes: 4 additions & 0 deletions pylint_django/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@
except ImportError:
from astroid.util import Uninferable

import pylint

# pylint before version 2.3 does not support load_configuration() hook.
LOAD_CONFIGURATION_SUPPORTED = pylint.__pkginfo__.numversion >= (2, 3)
15 changes: 11 additions & 4 deletions pylint_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@
# we want to import the transforms to make sure they get added to the astroid manager,
# however we don't actually access them directly, so we'll disable the warning
from pylint_django import transforms # noqa, pylint: disable=unused-import
from pylint_django import compat


def register(linter):
def load_configuration(linter):
"""
Registering additional checkers.

However, we will also use it to amend existing checker config.
Amend existing checker config.
"""
name_checker = get_checker(linter, NameChecker)
name_checker.config.good_names += ('qs', 'urlpatterns', 'register', 'app_name', 'handler500')

# we don't care about South migrations
linter.config.black_list += ('migrations', 'south_migrations')


def register(linter):
"""
Registering additional checkers.
"""
# add all of the checkers
register_checkers(linter)

Expand All @@ -32,3 +36,6 @@ def register(linter):
# probably trying to execute pylint_django when Django isn't installed
# in this case the django-not-installed checker will kick-in
pass

if not compat.LOAD_CONFIGURATION_SUPPORTED:
load_configuration(linter)