-
-
Notifications
You must be signed in to change notification settings - Fork 384
/
consistency.py
2097 lines (1477 loc) · 47.2 KB
/
consistency.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
These checks limit the Python's inconsistency.
We can do the same things differently in Python.
For example, there are three ways to format a string.
There are several ways to write the same number.
We like our code to be consistent.
It is easier to bare with your code base if you follow these rules.
So, we choose a single way to do things.
It does not mean that we choose the best way to do it.
But, we value consistency more than being 100% right.
And we are ready to suffer all trade-offs that might come.
Once again, these rules are highly subjective. But, we love them.
.. currentmodule:: wemake_python_styleguide.violations.consistency
Summary
-------
.. autosummary::
:nosignatures:
LocalFolderImportViolation
DottedRawImportViolation
UnicodeStringViolation
UnderscoredNumberViolation
PartialFloatViolation
FormattedStringViolation
RequiredBaseClassViolation
MultipleIfsInComprehensionViolation
ConstantCompareViolation
CompareOrderViolation
BadNumberSuffixViolation
MultipleInCompareViolation
UselessCompareViolation
MissingSpaceBetweenKeywordAndParenViolation
ConstantConditionViolation
ObjectInBaseClassesListViolation
MultipleContextManagerAssignmentsViolation
ParametersIndentationViolation
ExtraIndentationViolation
WrongBracketPositionViolation
MultilineFunctionAnnotationViolation
UppercaseStringModifierViolation
WrongMultilineStringViolation
EmptyLineAfterCodingViolation
InconsistentReturnViolation
InconsistentYieldViolation
ImplicitStringConcatenationViolation
UselessContinueViolation
UselessNodeViolation
UselessExceptCaseViolation
UselessOperatorsViolation
InconsistentReturnVariableViolation
ImplicitTernaryViolation
ImplicitComplexCompareViolation
ReversedComplexCompareViolation
WrongLoopIterTypeViolation
ExplicitStringConcatViolation
MultilineConditionsViolation
WrongMethodOrderViolation
NumberWithMeaninglessZeroViolation
PositiveExponentViolation
WrongHexNumberCaseViolation
ImplicitRawStringViolation
BadComplexNumberSuffixViolation
ZeroDivisionViolation
MeaninglessNumberOperationViolation
OperationSignNegationViolation
VagueImportViolation
LineStartsWithDotViolation
RedundantSubscriptViolation
AugmentedAssignPatternViolation
UnnecessaryLiteralsViolation
MultilineLoopViolation
IncorrectYieldFromTargetViolation
ConsecutiveYieldsViolation
BracketBlankLineViolation
IterableUnpackingViolation
Consistency checks
------------------
.. autoclass:: LocalFolderImportViolation
.. autoclass:: DottedRawImportViolation
.. autoclass:: UnicodeStringViolation
.. autoclass:: UnderscoredNumberViolation
.. autoclass:: PartialFloatViolation
.. autoclass:: FormattedStringViolation
.. autoclass:: RequiredBaseClassViolation
.. autoclass:: MultipleIfsInComprehensionViolation
.. autoclass:: ConstantCompareViolation
.. autoclass:: CompareOrderViolation
.. autoclass:: BadNumberSuffixViolation
.. autoclass:: MultipleInCompareViolation
.. autoclass:: UselessCompareViolation
.. autoclass:: MissingSpaceBetweenKeywordAndParenViolation
.. autoclass:: ConstantConditionViolation
.. autoclass:: ObjectInBaseClassesListViolation
.. autoclass:: MultipleContextManagerAssignmentsViolation
.. autoclass:: ParametersIndentationViolation
.. autoclass:: ExtraIndentationViolation
.. autoclass:: WrongBracketPositionViolation
.. autoclass:: MultilineFunctionAnnotationViolation
.. autoclass:: UppercaseStringModifierViolation
.. autoclass:: WrongMultilineStringViolation
.. autoclass:: EmptyLineAfterCodingViolation
.. autoclass:: InconsistentReturnViolation
.. autoclass:: InconsistentYieldViolation
.. autoclass:: ImplicitStringConcatenationViolation
.. autoclass:: UselessContinueViolation
.. autoclass:: UselessNodeViolation
.. autoclass:: UselessExceptCaseViolation
.. autoclass:: UselessOperatorsViolation
.. autoclass:: InconsistentReturnVariableViolation
.. autoclass:: ImplicitTernaryViolation
.. autoclass:: ImplicitComplexCompareViolation
.. autoclass:: ReversedComplexCompareViolation
.. autoclass:: WrongLoopIterTypeViolation
.. autoclass:: ExplicitStringConcatViolation
.. autoclass:: MultilineConditionsViolation
.. autoclass:: WrongMethodOrderViolation
.. autoclass:: NumberWithMeaninglessZeroViolation
.. autoclass:: PositiveExponentViolation
.. autoclass:: WrongHexNumberCaseViolation
.. autoclass:: ImplicitRawStringViolation
.. autoclass:: BadComplexNumberSuffixViolation
.. autoclass:: ZeroDivisionViolation
.. autoclass:: MeaninglessNumberOperationViolation
.. autoclass:: OperationSignNegationViolation
.. autoclass:: VagueImportViolation
.. autoclass:: LineStartsWithDotViolation
.. autoclass:: RedundantSubscriptViolation
.. autoclass:: AugmentedAssignPatternViolation
.. autoclass:: UnnecessaryLiteralsViolation
.. autoclass:: MultilineLoopViolation
.. autoclass:: IncorrectYieldFromTargetViolation
.. autoclass:: ConsecutiveYieldsViolation
.. autoclass:: BracketBlankLineViolation
.. autoclass:: IterableUnpackingViolation
"""
from typing_extensions import final
from wemake_python_styleguide.violations.base import (
ASTViolation,
TokenizeViolation,
)
@final
class LocalFolderImportViolation(ASTViolation):
"""
Forbids to have imports relative to the current folder.
Reasoning:
We should pick one style and stick to it.
We have decided to use the explicit one.
Solution:
Refactor your imports to use the absolute path.
Example::
# Correct:
from my_package.version import get_version
# Wrong:
from .version import get_version
from ..drivers import MySQLDriver
.. versionadded:: 0.1.0
"""
error_template = 'Found local folder import'
code = 300
@final
class DottedRawImportViolation(ASTViolation):
"""
Forbids to use imports like ``import os.path``.
Reasoning:
There too many different ways to import something.
We should pick one style and stick to it.
We have decided to use the readable one.
Solution:
Refactor your import statement.
Example::
# Correct:
from os import path
# Wrong:
import os.path
.. versionadded:: 0.1.0
"""
error_template = 'Found dotted raw import: {0}'
code = 301
@final
class UnicodeStringViolation(TokenizeViolation):
"""
Forbids to use ``u`` string prefix.
Reasoning:
We do not need this prefix since ``python2``.
But, it is still possible to find it inside the codebase.
Solution:
Remove this prefix.
Example::
# Correct:
nickname = 'sobolevn'
file_contents = b'aabbcc'
# Wrong:
nickname = u'sobolevn'
.. versionadded:: 0.1.0
"""
code = 302
error_template = 'Found unicode string prefix: {0}'
@final
class UnderscoredNumberViolation(TokenizeViolation):
"""
Forbids to use underscores (``_``) in numbers.
Reasoning:
It is possible to write ``1000`` in three different ways:
``1_000``, ``10_00``, and ``100_0``.
And it would be still the same number.
Count how many ways there are to write bigger numbers.
Currently, it all depends on the cultural habits of the author.
We enforce a single way to write numbers: without the underscore.
Solution:
Numbers should be written as numbers: ``1000``.
If you have a very big number with a lot of zeros, use multiplication.
Example::
# Correct:
phone = 88313443
million = 1000000
# Wrong:
phone = 8_83_134_43
million = 100_00_00
.. versionadded:: 0.1.0
"""
code = 303
error_template = 'Found underscored number: {0}'
@final
class PartialFloatViolation(TokenizeViolation):
"""
Forbids to use partial floats like ``.05`` or ``23.``.
Reasoning:
Partial numbers are hard to read and they can be confused with
other numbers. For example, it is really
easy to confuse ``0.5`` and ``.05`` when reading
through the source code.
Solution:
Use full versions with leading and starting zeros.
Example::
# Correct:
half = 0.5
ten_float = 10.0
# Wrong:
half = .5
ten_float = 10.
.. versionadded:: 0.1.0
"""
code = 304
error_template = 'Found partial float: {0}'
@final
class FormattedStringViolation(ASTViolation):
"""
Forbids to use ``f`` strings.
Reasoning:
``f`` strings loses context too often and they are hard to lint.
Imagine that you have a string that breaks
when you move it two lines above.
That's not how a string should behave.
Also, they promote a bad practice:
putting your logic inside the template.
Solution:
Use ``.format()`` with indexed params instead.
See also:
https://github.com/xZise/flake8-string-format
Example::
# Wrong:
f'Result is: {2 + 2}'
# Correct:
'Result is: {0}'.format(2 + 2)
'Hey {user}! How are you?'.format(user='sobolevn')
.. versionadded:: 0.1.0
"""
error_template = 'Found `f` string'
code = 305
@final
class RequiredBaseClassViolation(ASTViolation):
"""
Forbids to write classes without base classes.
Reasoning:
We just need to decide how to do it.
We need a single and unified rule about base classes.
We have decided to stick to the explicit base class notation.
Solution:
Add a base class.
Example::
# Correct:
class Some(object): ...
# Wrong:
class Some: ...
See also:
https://google.github.io/styleguide/pyguide.html#39-classes
.. versionadded:: 0.1.0
"""
error_template = 'Found class without a base class: {0}'
code = 306
@final
class MultipleIfsInComprehensionViolation(ASTViolation):
"""
Forbids to have multiple ``if`` statements inside list comprehensions.
Reasoning:
It is very hard to read multiple ``if`` statements inside
a list comprehension. Since it is even hard to tell all of them
should pass or fail.
Solution:
Use a single ``if`` statement inside list comprehensions.
Use ``filter()`` if you have complicated logic.
Example::
# Wrong:
nodes = [node for node in html if node != 'b' if node != 'i']
# Correct:
nodes = [node for node in html if node not in ('b', 'i')]
.. versionadded:: 0.1.0
"""
error_template = 'Found list comprehension with multiple `if`s'
code = 307
@final
class ConstantCompareViolation(ASTViolation):
"""
Forbids to have compares between two literals.
Reasoning:
When two constants are compared it is typically an indication of a
mistake, since the Boolean value of the compare, will always be
the same.
Solution:
Remove the constant compare and any associated dead code.
Example::
# Wrong:
if 60 * 60 < 1000:
do_something()
else:
do_something_else()
# Correct:
do_something_else()
.. versionadded:: 0.3.0
"""
error_template = 'Found constant compare'
code = 308
@final
class CompareOrderViolation(ASTViolation):
"""
Forbids comparison where argument doesn't come first.
Reasoning:
It is hard to read the code when
you have to shuffle ordering of the arguments all the time.
Bring consistency to the compare!
Solution:
Refactor your compare expression, place the argument first.
Example::
# Correct:
if some_x > 3:
if 3 < some_x < 10:
# Wrong:
if 3 < some_x:
.. versionadded:: 0.3.0
"""
error_template = 'Found reversed compare order'
code = 309
@final
class BadNumberSuffixViolation(TokenizeViolation):
"""
Forbids to use capital ``X``, ``O``, ``B``, and ``E`` in numbers.
Reasoning:
Octal, hex, binary and scientific notation suffixes could
be written in two possible notations: lowercase and uppercase.
Which brings confusion and decreases code consistency and readability.
We enforce a single way to write numbers with suffixes:
suffix with lowercase chars.
Solution:
Octal, hex, binary and scientific notation suffixes in numbers
should be written in lowercase.
Example::
# Correct:
hex_number = 0xFF
octal_number = 0o11
binary_number = 0b1001
number_with_scientific_notation = 1.5e+10
# Wrong:
hex_number = 0XFF
octal_number = 0O11
binary_number = 0B1001
number_with_scientific_notation = 1.5E+10
.. versionadded:: 0.3.0
"""
error_template = 'Found bad number suffix: {0}'
code = 310
@final
class MultipleInCompareViolation(ASTViolation):
"""
Forbids comparison where multiple ``in`` checks.
Reasoning:
Using multiple ``in`` is unreadable.
Solution:
Refactor your compare expression to use several ``and`` conditions
or separate ``if`` statements in case it is appropriate.
Example::
# Correct:
if item in bucket and bucket in master_list_of_buckets:
if x_coord not in line and line not in square:
# Wrong:
if item in bucket in master_list_of_buckets:
if x_cord not in line not in square:
.. versionadded:: 0.3.0
.. versionchanged:: 0.10.0
"""
error_template = 'Found multiple `in` compares'
code = 311
@final
class UselessCompareViolation(ASTViolation):
"""
Forbids to have compares between the same variable.
Reasoning:
When the same variables are compared it is typically an indication
of a mistake, since the Boolean value of the compare will always be
the same.
Solution:
Remove the same variable compare and any associated dead code.
Example::
# Wrong:
a = 1
if a < a:
do_something()
else:
do_something_else()
# Correct:
do_something()
.. versionadded:: 0.3.0
"""
error_template = 'Found compare between same variable'
code = 312
@final
class MissingSpaceBetweenKeywordAndParenViolation(TokenizeViolation):
"""
Enforces to separate parenthesis from the keywords with spaces.
Reasoning:
Some people use ``return`` and ``yield`` keywords as functions.
The same happened to good old ``print`` in Python2.
Solution:
Insert space symbol between keyword and open paren.
Example::
# Wrong:
def func():
a = 1
b = 2
del(a, b)
yield(1, 2, 3)
# Correct:
def func():
a = 1
del (a, b)
yield (1, 2, 3)
.. versionadded:: 0.3.0
"""
error_template = 'Found parens right after a keyword'
code = 313
@final
class ConstantConditionViolation(ASTViolation):
"""
Forbids using ``if`` statements that use invalid conditionals.
Reasoning:
When invalid conditional arguments are used
it is typically an indication of a mistake, since
the value of the conditional result will always be the same.
Solution:
Remove the conditional and any associated dead code.
Example::
# Correct:
if value is True: ...
# Wrong:
if True: ...
.. versionadded:: 0.3.0
"""
error_template = 'Conditional always evaluates to same result'
code = 314
@final
class ObjectInBaseClassesListViolation(ASTViolation):
"""
Forbids extra ``object`` in parent classes list.
Reasoning:
We should allow object only when
we explicitly use it as a single parent class.
When there is another class or there are multiple
parents - we should not allow it for the consistency reasons.
Solution:
Remove extra ``object`` parent class from the list.
Example::
# Correct:
class SomeClassName(object): ...
class SomeClassName(FirstParentClass, SecondParentClass): ...
# Wrong:
class SomeClassName(FirstParentClass, SecondParentClass, object): ...
.. versionadded:: 0.3.0
"""
error_template = 'Founded extra `object` in parent classes list'
code = 315
@final
class MultipleContextManagerAssignmentsViolation(ASTViolation):
"""
Forbids multiple assignment targets for context managers.
Reasoning:
It is hard to distinguish whether ``as`` should unpack into
tuple or we are just using two context managers.
Solution:
Use several context managers. Or explicit brackets.
Example::
# Correct:
with open('') as first:
with second:
...
with some_context as (first, second):
...
# Wrong:
with open('') as first, second:
...
.. versionadded:: 0.6.0
"""
error_template = 'Found context manager with too many assignments'
code = 316
@final
class ParametersIndentationViolation(ASTViolation):
"""
Forbids to use incorrect parameters indentation.
Reasoning:
It is really easy to spoil your perfect, readable code with
incorrect multi-line parameters indentation.
Since it is really easy to style them in any of 100 possible ways.
We enforce a strict rule about how it is possible to write these
multi-line parameters.
Solution:
Use consistent multi-line parameters indentation.
Example::
# Correct:
def my_function(arg1, arg2, arg3) -> None:
return None
print(1, 2, 3, 4, 5, 6)
def my_function(
arg1, arg2, arg3,
) -> None:
return None
print(
1, 2, 3, 4, 5, 6,
)
def my_function(
arg1,
arg2,
arg3,
) -> None:
return None
print(
first_variable,
2,
third_value,
4,
5,
last_item,
)
# Special case:
print('some text', 'description', [
first_variable,
second_variable,
third_variable,
last_item,
], end='')
# Correct complex case:
@pytest.mark.parametrize(('boolean_arg', 'string_arg'), [
(True, "string"),
(False, "another string"),
])
Everything else is considered a violation.
This rule checks: lists, sets, tuples, dicts, calls,
functions, methods, and classes.
.. versionadded:: 0.6.0
"""
error_template = 'Found incorrect multi-line parameters'
code = 317
@final
class ExtraIndentationViolation(TokenizeViolation):
"""
Forbids to use extra indentation.
Reasoning:
You can use extra indentation for lines of code.
Python allows you to do that in case you will keep the indentation
level equal for this specific node.
But, that's insane!
Solution:
We should stick to 4 spaces for an indentation block.
Each next block should be indented by just 4 extra spaces.
Example::
# Correct:
def test():
print('test')
# Wrong:
def test():
print('test')
This rule is consistent with the "Vertical Hanging Indent" option for
``multi_line_output`` setting of ``isort``. To avoid conflicting rules,
you should set ``multi_line_output = 3`` in the ``isort`` settings.
See also:
https://github.com/timothycrosley/isort#multi-line-output-modes
https://github.com/wemake-services/wemake-python-styleguide/blob/master/styles/isort.toml
.. versionadded:: 0.6.0
"""
error_template = 'Found extra indentation'
code = 318
@final
class WrongBracketPositionViolation(TokenizeViolation):
"""
Forbids to have brackets in the wrong position.
Reasoning:
You can do bizzare things with bracket positioning in python.
We require all brackets to be consistent.
Solution:
Place bracket on the same line, in case of a single line expression.
Or place the bracket on a new line in case of a multi-line expression.
Example::
# Correct:
print([
1, 2, 3,
])
print(
1,
2,
)
def _annotate_brackets(
tokens: List[tokenize.TokenInfo],
) -> TokenLines:
...
# Wrong:
print([
1, 2, 3],
)
print(
1,
2)
def _annotate_brackets(
tokens: List[tokenize.TokenInfo]) -> TokenLines:
...
We check round, square, and curly brackets.
.. versionadded:: 0.6.0
"""
error_template = 'Found bracket in wrong position'
code = 319
@final
class MultilineFunctionAnnotationViolation(ASTViolation):
"""
Forbids to use multi-line function type annotations.
Reasoning:
Functions with multi-line type annotations are unreadable.
Solution:
Use type annotations that fit into a single line to annotate functions.
If your annotation is too long, then use type aliases.
Example::
# Correct:
def create_list(length: int) -> List[int]:
...
# Wrong:
def create_list(length: int) -> List[
int,
]:
...
This rule checks argument and return type annotations.
.. versionadded:: 0.6.0
"""
error_template = 'Found multi-line function type annotation'
code = 320
@final
class UppercaseStringModifierViolation(TokenizeViolation):
"""
Forbids to use uppercase string modifiers.
Reasoning:
String modifiers should be consistent.
Solution:
Use lowercase modifiers.
Example::
# Correct:
some_string = r'/regex/'
some_bytes = b'123'
# Wrong:
some_string = R'/regex/'
some_bytes = B'123'
.. versionadded:: 0.6.0
"""
error_template = 'Found uppercase string modifier: {0}'
code = 321
@final
class WrongMultilineStringViolation(TokenizeViolation):
'''
Forbids to use triple quotes for singleline strings.
Reasoning:
String quotes should be consistent.
Solution:
Use single quotes for single-line strings.
Triple quotes are only allowed for real multiline strings.
Example::
# Correct:
single_line = 'abc'
multiline = """
one
two
"""
# Wrong:
some_string = """abc"""
some_bytes = b"""123"""
Docstrings are ignored from this rule.
You must use triple quotes strings for docstrings.
.. versionadded:: 0.7.0
'''
error_template = 'Found incorrect multi-line string'
code = 322
@final
class EmptyLineAfterCodingViolation(TokenizeViolation):
"""
Enforces to have an extra empty line after the ``coding`` comment.
Reasoning:
Since we use
`flake8-coding <https://github.com/tk0miya/flake8-coding>`_
as a part of our linter
we care about extra space after this coding comment.
This is done for pure consistency.
Why should we even care about this magic coding comment?
For several reasons.
First, explicit encoding is always better that an implicit one,
different countries still use some non utf-8 encodings as a default.
But, people might override it with other encodings in a comment.
Do you know how much pain it can cause to you?
We still know that ``python3`` uses ``utf-8`` inside.
Second, some tools break because of this incorrect encoding comment.
Including, ``django``, ``flake8``, and ``tokenize`` core module.
It is very hard to notice these things when they happen.
Solution:
Add an empty line between ``coding`` magic comment and your code.
Example::