-
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 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,28 @@ | ||
# Copyright (c) 2018 Alexander Todorov <[email protected]> | ||
|
||
# Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html | ||
|
||
import astroid | ||
|
||
from pylint import interfaces | ||
from pylint import checkers | ||
from pylint.checkers import utils | ||
|
||
|
||
class RawSQLChecker(checkers.BaseChecker): | ||
__implements__ = (interfaces.IAstroidChecker,) | ||
|
||
name = 'raw-sql-checker' | ||
|
||
msgs = {'R4431': ('Avoid using raw SQL', | ||
'avoid-raw-sql', | ||
'Avoid raw SQL, use Django ORM queries instead')} | ||
|
||
@utils.check_messages('avoid-raw-sql') | ||
def visit_attribute(self, node): | ||
# looking for .extra(select={}) patterns | ||
if node.attrname == 'extra' and isinstance(node.parent, astroid.Call): | ||
for keyword in node.parent.keywords: | ||
if keyword.arg == 'select': | ||
self.add_message('avoid-raw-sql', node=node) | ||
break |