|
| 1 | +# reLint Cookbook |
| 2 | + |
| 3 | +A collection of recipes for reLint. Please feel free to contribute! |
| 4 | + |
| 5 | +# Table of Contents |
| 6 | + |
| 7 | +- [Python](#python) |
| 8 | + - [Django](#django) |
| 9 | +- [HTML](#html) |
| 10 | + |
| 11 | +# Python |
| 12 | + |
| 13 | +## Django |
| 14 | + |
| 15 | +### Databases |
| 16 | + |
| 17 | +```yaml |
| 18 | +- name: potential database connection limit with use of threading # by @syphar |
| 19 | + pattern: "(threading|ThreadPoolExecutor)[^#]*(?!\\s+# noqa)$" |
| 20 | + hint: | |
| 21 | + When using threads, keep in mind that they might use additional database |
| 22 | + connections. This can lead to a connection limit being reached. You may |
| 23 | + also need to manually close the database connection in the thread. |
| 24 | + filePattern: .*\.py |
| 25 | +``` |
| 26 | +
|
| 27 | +### Utils |
| 28 | +
|
| 29 | +```yaml |
| 30 | +- name: Do not import datetime or date directly # by @codingjoe |
| 31 | + pattern: '(from datetime import|from django.utils.timezone import)' |
| 32 | + filePattern: .*\.py |
| 33 | + hint: | |
| 34 | + To differentiate between naive and timezone-aware dates, |
| 35 | + please use the following imports: |
| 36 | + * 'from django.utils import timezone' |
| 37 | + * 'import datetime' |
| 38 | +``` |
| 39 | +
|
| 40 | +### Management Commands |
| 41 | +
|
| 42 | +```yaml |
| 43 | +- name: No logger in management commands # by @codingjoe |
| 44 | + pattern: (logger|import logging) |
| 45 | + hint: Please write to self.stdout or self.stderr in favor of using a logger. |
| 46 | + filePattern: \/management\/commands\/.*\.py |
| 47 | +``` |
| 48 | +
|
| 49 | +### Testing |
| 50 | +
|
| 51 | +#### PyTest-Django |
| 52 | +
|
| 53 | +```yaml |
| 54 | +- name: Code and tests seem too complex # by @codingjoe |
| 55 | + pattern: '(pytest\.fixture|def (?!test_)).*(?!\\s+# noqa)$' |
| 56 | + hint: | |
| 57 | + Large test setups hint towards complex or convoluted production code. |
| 58 | + Consider breaking down your code into smaller individually testable chunks. |
| 59 | + You may also use pytest fixtures inside a conftest.py file. Their usage should |
| 60 | + be limited to technical setups, like stubs or IO mocks. Data fixtures should |
| 61 | + be implemented via baker recipes only. |
| 62 | + filePattern: '.*\/test_.*\.py' |
| 63 | +``` |
| 64 | +
|
| 65 | +```yaml |
| 66 | +- name: IO is lava – Avoid using database fixtures # by @codingjoe |
| 67 | + pattern: '@pytest.fixture.*\n[ ]*def [^(]+\([^)]*(db|transactional_db)(, |\))' |
| 68 | + hint: Please use the "django_db" marker on individual tests only. |
| 69 | + filePattern: .*\.py |
| 70 | +``` |
| 71 | +
|
| 72 | +```yaml |
| 73 | +- name: IO is lava – Avoid the 'db' fixture # by @codingjoe |
| 74 | + pattern: "def test_[^(]+\\([^)]*db[^)]*\\):" |
| 75 | + hint: Please use the "django_db" marker instead. |
| 76 | + filePattern: .*\.py |
| 77 | +``` |
| 78 | +
|
| 79 | +```yaml |
| 80 | +- name: IO is lava – Do not mark a whole test class for database usage # by @codingjoe |
| 81 | + pattern: \@pytest\.mark\.django_db[^\n]*\n\w*class |
| 82 | + hint: Please use the "django_db" marker on individual tests only. |
| 83 | + filePattern: .*\.py |
| 84 | +``` |
| 85 | +
|
| 86 | +#### Model Bakery |
| 87 | +
|
| 88 | +```yaml |
| 89 | +- name: Follow the recipe # by @codingjoe |
| 90 | + pattern: 'baker\.(make|prepare)\(' |
| 91 | + filePattern: '.*\/test_.*\.py' |
| 92 | + hint: | |
| 93 | + Please use baker recipes instead of `baker.make` or `baker.prepare`. |
| 94 | + This allows us to easily create complex objects with a single line of code. |
| 95 | +``` |
| 96 | +
|
| 97 | +# HTML |
| 98 | +
|
| 99 | +```yaml |
| 100 | +- name: no inline CSS # by @codingjoe |
| 101 | + pattern: 'style=\"[^\"]*;[^\"]+\"' |
| 102 | + hint: | |
| 103 | + Please do not use more than one inline style attribute. |
| 104 | + You may use a CSS class instead. |
| 105 | + filePattern: .*\.(html|vue|jsx|tsx) |
| 106 | +``` |
0 commit comments