Giter Site home page Giter Site logo

django_linter's Introduction

Django linter

https://travis-ci.org/geerk/django_linter.svg?branch=master

This is a simple extension for pylint that aims to check some common mistakes in django projects.

Contributions are welcome.

Installation

pip install django_linter

Usage

It can be used as a plugin or standalone script. To use it as a plugin it should be installed first, then run with pylint:

pylint --load-plugins=django_linter TARGET

To use it as a standalone script:

usage: django-linter [-h] TARGET [TARGET ...]

Simple extension for pylint to check django projects for common mistakes.

positional arguments:
  TARGET      python package or module

optional arguments:
  -h, --help  show this help message and exit

Implemented checks

Settings:

  • E5221 (required-setting-missed): Used when required setting missed in settings file.
  • E5222 (empty-setting): Used when setting is empty value.
  • W5221 (improper-settings-import): Used when settings is not imported from django.conf

Models:

  • W5241 (nullable-text-field): Used when text field has null=True.
  • W5242 (float-money-field): Used when money related field uses FloatField.
  • W5243 (naive-datetime-used): Used when there is datetime.now is used.
  • W5244 (related-field-named-with-id): Used when related field is named with _id suffix
  • W5245 (unicode-method-absent): Used when model has no unicode method.
  • W5246 (unicode-method-return): Used when unicode method does not return unicode.
  • W5247 (model-field-redefinition): Used when there are more than one model field with the same name.
  • W5248 (get-absolute-url-without-reverse): Used when get_absolute_url method is defined without using reverse function.

Forms:

  • W5211 (form-field-redefinition): Used when there are more than one form field with the same name.

Views:

  • W5231 (is-authenticated-not-called): Used when is_authenticated method is not called
  • W5232 (objects-get-without-doesnotexist): Used when Model.objects.get is used without enclosing it in try-except block to catch DoesNotExist exception.
  • W5233 (fetching-db-objects-len): Used when there is db query that fetches objects from database only to check the number of returned objects.
  • W5234 (raw-get-post-access): Used when request.GET or request.POST dicts is accessed directly, it is better to use forms.

Layout:

  • W5201 (forms-layout): Used when form class definition is not in forms module.
  • W5202 (admin-layout): Used when admin class definition is not in admin module.

Misc:

  • W5251 (print-used): Used when there is print statement or function

Implemented suppressers

  • "Meta" classes
  • urlpatterns
  • logger

Implemented transformers

Models

  • "id" field
  • "objects" manager
  • "DoesNotExist" exception
  • "MultipleObjectsReturned" exception

Testing

  • test responses (django and DRF)

Factories

  • factory-boy's factories (factory should return django model, but not always possible to infer model class)

django_linter's People

Contributors

geerk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

wowkin2 enefeq

django_linter's Issues

Getting following stack when django-linter fired

$ django-linter managerQ
Traceback (most recent call last):
File "/usr/local/bin/django-linter", line 11, in
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/django_linter/main.py", line 26, in main
linter.check(args.targets)
File "/usr/local/lib/python2.7/dist-packages/pylint/lint.py", line 747, in check
self._do_check(files_or_modules)
File "/usr/local/lib/python2.7/dist-packages/pylint/lint.py", line 869, in _do_check
self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
File "/usr/local/lib/python2.7/dist-packages/pylint/lint.py", line 946, in check_astroid_module
walker.walk(ast_node)
File "/usr/local/lib/python2.7/dist-packages/pylint/utils.py", line 874, in walk
self.walk(child)
File "/usr/local/lib/python2.7/dist-packages/pylint/utils.py", line 874, in walk
self.walk(child)
File "/usr/local/lib/python2.7/dist-packages/pylint/utils.py", line 874, in walk
self.walk(child)
File "/usr/local/lib/python2.7/dist-packages/pylint/utils.py", line 874, in walk
self.walk(child)
File "/usr/local/lib/python2.7/dist-packages/pylint/utils.py", line 874, in walk
self.walk(child)
File "/usr/local/lib/python2.7/dist-packages/pylint/utils.py", line 871, in walk
cb(astroid)
File "/usr/local/lib/python2.7/dist-packages/django_linter/checkers/views.py", line 71, in visit_getattr
if parent.attrname == 'get':
AttributeError: 'Assign' object has no attribute 'attrname'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.