forked from kiwitcms/Kiwi
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves kiwitcms#736. Add a lint checker class to check for use of d…
…b_column argument in model field definition.
- Loading branch information
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from pylint import interfaces, checkers | ||
from pylint.checkers import utils | ||
|
||
|
||
class DbColumnChecker(checkers.BaseChecker): | ||
__implements__ = (interfaces.IAstroidChecker, ) | ||
|
||
name = 'db-column-used' | ||
|
||
msgs = { | ||
'E4841': ( | ||
'Do not use db_column in model field definitions', | ||
'db-column-used', | ||
'Do not use db_column argument in model field definitions,' | ||
'See: https://github.com/kiwitcms/Kiwi/issues/736' | ||
) | ||
} | ||
|
||
@utils.check_messages('db-column-used') | ||
def visit_attribute(self, node): | ||
if (node.attrname.endswith(('Field', 'Key')) | ||
and node.expr.name == 'models' and node.parent.keywords): | ||
for keyword_arg in node.parent.keywords: | ||
if keyword_arg.arg == 'db_column': | ||
self.add_message('db-column-used', node=node) |