Django Smelly Tokens

It is sometimes possible to tell that code stinks even without looking at it. This Django app tries to accomplish that.

Pipeline status Documentation status

Installation

pip install django-smelly-tokens

Usage

In your settings.py define SMELLY_TOKENS_APPLICATIONS list with packages you want to inspect.

In a package with code quality tests (e.g. test_tokens.py) import tests you want to check your apps against:

from smelly_tokens.test_smelly_tokens import (
    EvalTokenTestCase,
    PdbTokenTestCase,
)

Run django-admin.py test or ./manage.py test or py.test or nose or whatever runner you’re using.

Exceptions

To silence known errors PEP8-style noqa comment can be used in the beginning of a file:

# smelly_tokens: noqa

Or in-line:

eval('print 123')  # noqa

To exclude an entire directory add it’s path to SMELLY_TOKENS_EXCLUDE_DIRS list in settings.

Adding your own tokens

To create a new type of smelly token test case, inherit SmellyTokensTestCase and override _tokens list:

from django.test import TestCase
from smelly_tokens.test_smelly_tokens import SmellyTokensTestCase


class OOPTokensTestCase(SmellyTokensTestCase, TestCase):
""" OOP hater. """
_tokens = ['class', 'object', 'Object']

References