Skip to content

Latest commit

 

History

History
106 lines (85 loc) · 2.96 KB

COOKBOOK.md

File metadata and controls

106 lines (85 loc) · 2.96 KB

reLint Cookbook

A collection of recipes for reLint. Please feel free to contribute!

Table of Contents

Python

Django

Databases

- name: potential database connection limit with use of threading # by @syphar
  pattern: "(threading|ThreadPoolExecutor)[^#]*(?!\\s+# noqa)$"
  hint: |
    When using threads, keep in mind that they might use additional database
    connections. This can lead to a connection limit being reached. You may
    also need to manually close the database connection in the thread.
  filePattern: .*\.py

Utils

- name: Do not import datetime or date directly # by @codingjoe
  pattern: '(from datetime import|from django.utils.timezone import)'
  filePattern: .*\.py
  hint: |
    To differentiate between naive and timezone-aware dates,
    please use the following imports:
     * 'from django.utils import timezone'
     * 'import datetime'

Management Commands

- name: No logger in management commands # by @codingjoe
  pattern: (logger|import logging)
  hint: Please write to self.stdout or self.stderr in favor of using a logger.
  filePattern: \/management\/commands\/.*\.py

Testing

PyTest-Django

- name: Code and tests seem too complex # by @codingjoe
  pattern: '(pytest\.fixture|def (?!test_)).*(?!\\s+# noqa)$'
  hint: |
    Large test setups hint towards complex or convoluted production code.
    Consider breaking down your code into smaller individually testable chunks.
    You may also use pytest fixtures inside a conftest.py file. Their usage should
    be limited to technical setups, like stubs or IO mocks. Data fixtures should
    be implemented via baker recipes only.
  filePattern: '.*\/test_.*\.py'
- name: IO is lava – Avoid using database fixtures # by @codingjoe
  pattern: '@pytest.fixture.*\n[ ]*def [^(]+\([^)]*(db|transactional_db)(, |\))'
  hint: Please use the "django_db" marker on individual tests only.
  filePattern: .*\.py
- name: IO is lava – Avoid the 'db' fixture # by @codingjoe
  pattern: "def test_[^(]+\\([^)]*db[^)]*\\):"
  hint: Please use the "django_db" marker instead.
  filePattern: .*\.py
- name: IO is lava – Do not mark a whole test class for database usage # by @codingjoe
  pattern: \@pytest\.mark\.django_db[^\n]*\n\w*class
  hint: Please use the "django_db" marker on individual tests only.
  filePattern: .*\.py

Model Bakery

- name: Follow the recipe # by @codingjoe
  pattern: 'baker\.(make|prepare)\('
  filePattern: '.*\/test_.*\.py'
  hint: |
    Please use baker recipes instead of `baker.make` or `baker.prepare`.
    This allows us to easily create complex objects with a single line of code.

HTML

- name: no inline CSS # by @codingjoe
  pattern: 'style=\"[^\"]*;[^\"]+\"'
  hint: |
    Please do not use more than one inline style attribute.
    You may use a CSS class instead.
  filePattern: .*\.(html|vue|jsx|tsx)