Commit cb358e5a authored by BAIRE Anthony's avatar BAIRE Anthony
Browse files

add a lint for objects.create()

parent 857aa8f7
......@@ -5,7 +5,7 @@
# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
#init-hook=
init-hook=sys.path.append("tools")
# Add files or directories to the blacklist. They should be base names, not
# paths.
......@@ -20,7 +20,7 @@ persistent=yes
# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=pylint_django
load-plugins=pylint_django,pylint_allgo
# Use multiple processes to speed up Pylint.
jobs=1
......
#!/usr/bin/python3
from astroid.node_classes import Attribute, Call
from pylint import checkers, interfaces
class ObjectsCreateChecker(checkers.BaseChecker):
__implements__ = interfaces.IAstroidChecker
name = "objects-create-checker"
priority = -100
msgs = {"W9901": (".objects.create() is called.", "objects-create-called",
"We prefer to avoid using Queryset.create() in django because it"
" bypasses the integrity checks implemented by"
" allgo.main.models.BaseModel.save().")}
def visit_attribute(self, node):
if node.attrname == "objects":
if (isinstance(node.parent, Attribute)
and node.parent.attrname=="create"
and isinstance(node.parent.parent, Call)):
self.add_message("objects-create-called", node=node)
def register(linter):
linter.register_checker(ObjectsCreateChecker(linter))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment