Chris Lamb

django-lint

BlogProjectsAbout

View all my projects »

Static analysis tool for Django projects.


Django Lint is a static analysis tool that checks (or "lints") projects and applications that use the Django web development framework.

It reports on common programming errors and bad code smells, including checking for nullable CharField field types, the use of brittle or deprecated Django features (such as auto_now_add) as well as the absence of recommended options in settings.py. It aims to encourage the development of high-quality re-usable Django applications.

Django Lint is currently implemented as a wrapper around PyLint.

An example output is:

$ django-lint django_lint_example/
************* Module django_lint_example.settings
W:  1: Missing required field 'MANAGERS'
W:  6: Empty 'ADMINS' setting
W: 64: SessionMiddleware after AuthenticationMiddleware
W: 65: ConditionalGetMiddleware after CommonMiddleware
W: 74: Non-absolute directory 'relative/directory' in TEMPLATE_DIRS
W: 75: 'C:\\windows\\user' in TEMPLATE_DIRS should use forward slashes
************* Module django_lint_example.example.models
W:  6:NullableModel: charfield: Nullable CharField or TextField
W:  7:NullableModel: charfield_2: Nullable CharField or TextField
W:  7:NullableModel: charfield_2: Field is nullable but blank=False
W:  8:NullableModel: textfield: Nullable CharField or TextField
W: 11:NullableModel: boolean_false: BooleanField with default=True will not be reflected in database
W: 13:NullableModel: nullable_boolean: NullBooleanField instead of BooleanField with null=True
W: 17:NullableModel: (unknown name): NullBooleanField instead of BooleanField with null=True
W:  3:NullableModel: Missing __unicode__ method
W: 21:UniqueForModels: u_date: uses brittle unique_for_date
W: 22:UniqueForModels: u_month: uses brittle unique_for_month
W: 23:UniqueForModels: u_year: uses brittle unique_for_year
W: 19:UniqueForModels: Missing __unicode__ method
W: 26:ParentModel: parent: Naive tree structure implementation using ForeignKey('self')
W: 31:StrModel.__str__: Use __unicode__ instead of __str__
W: 34:StrModel.__unicode__: Standard model method should come before '__str__'
W: 37:NullBlankModel: Missing __unicode__ method
W: 40:BigModel: Missing __unicode__ method
W: 40:BigModel: Model has too many fields (31/30); consider splitting model
W: 73:NoFieldsModel: Model has no fields
W: 78:Post: content: CharField with huge (1000/500) max_length instead of TextField
W: 79:Post: views: PositiveSmallIntegerField has database-dependent limits
W: 80:Post: words: SmallIntegerField has database-dependent limits
W: 81:Post: created: Uses deprecated auto_now or auto_now_add
W: 82:Post: updated: Uses deprecated auto_now or auto_now_add
W: 88:Comment: post: ForeignKey missing related_name
W: 89:Comment: url: URLField uses verify_exists=True default
W: 97:MisorderedMethodsModel.incorrect_place: Method should come after standard model methods
W:103:MisorderedMethodsModel.__unicode__: Standard model method should come before 'get_absolute_url'
W:149:PrimaryKeyModel: primary_key: Unique ForeignKey constraint better modelled as OneToOneField
W:150:PrimaryKeyModel: unique_field: Unique ForeignKey constraint better modelled as OneToOneField
W:151:PrimaryKeyModel: not_both: primary_key=True should imply unique=True
W:  1: Too many models (17/15); consider splitting application
W:  1: 5 models have common prefix ('Model') - rename or split application
W:  1: 'django_lint_example.example.models' is actually a directory; consider splitting application

In the future Django Lint will perform more intensive checks, including linting templates.

You can install django-lint from PyPI:

$ pip install django-lint
… or by adding django-lint to your requirements.txt and re-running pip install -r requirements.txt.

You can browse the source tree, create or file bugs or download the code from Git:

$ git clone https://github.com/lamby/django-lint

django-lint is released under the GNU General Public license version 3 or later.

View all my projects »