Skip to content

Commit 3269be9

Browse files
committed
Adds configuration docs, closes #302
1 parent 600e2dd commit 3269be9

File tree

7 files changed

+96
-23
lines changed

7 files changed

+96
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ We used to have incremental versioning before `0.1.0`.
3838
- Improves tests: now testing almost all violations inside `noqa.py`
3939
- Improves tests: now testing violations text
4040
- Improves tests: now all common patters live in related `conftest.py`
41+
- Improves docs: now all configuration options are listed in the violations
4142

4243

4344
## 0.3.0 aka The Hacktoberfest Feast

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ We are *not* planning to do the following things:
7878

7979
## Contributing
8080

81+
We warmly welcome any contributions!
82+
8183
See ["Contributing" section](https://wemake-python-styleguide.readthedocs.io/en/latest/_pages/contributing.html) in the documentation if you want to contribute.
84+
8285
You can also check which [issues need some help](https://github.com/wemake-services/wemake-python-styleguide/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) right now.
8386

8487

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _get_project_meta():
6969
'added_value',
7070
]
7171

72-
autoclass_content = 'both'
72+
autoclass_content = 'class'
7373
autodoc_member_order = 'bysource'
7474

7575
autodoc_mock_imports = [

tests/test_violations/test_docs.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# -*- coding: utf-8 -*-
22

3+
from wemake_python_styleguide.options.config import Configuration
4+
35

46
def test_all_violations_are_documented(all_module_violations):
57
"""Ensures that all violations are documented."""
@@ -38,3 +40,21 @@ def test_violation_error_text(all_violations):
3840
assert violation.error_template.endswith(error_format)
3941
else:
4042
assert '{0}' not in violation.error_template
43+
44+
45+
def test_configuration(all_violations):
46+
"""Ensures that all configuration options are listed in the docs."""
47+
option_listed = dict.fromkeys([
48+
option.long_option_name for option in Configuration.options
49+
], False)
50+
51+
for violation in all_violations:
52+
for option in option_listed.keys():
53+
if option in violation.__doc__:
54+
option_listed[option] = True
55+
56+
assert 'Configuration:' in violation.__doc__
57+
assert 'Default:' in violation.__doc__
58+
59+
for option, is_listed in option_listed.items():
60+
assert is_listed, option

wemake_python_styleguide/violations/best_practices.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,15 @@ class InitModuleHasLogicViolation(ASTViolation):
261261
1. comments, since they are dropped before AST comes in play
262262
2. docs string, because sometimes it is required to state something
263263
264+
It is also fine when you have different users that use your code.
265+
And you do not want to break everything for them.
266+
In this case this rule can be configured.
267+
268+
Configuration:
269+
This rule is configurable with ``--i-control-code``.
270+
Default:
271+
:str:`wemake_python_styleguide.options.defaults.I_CONTROL_CODE`
272+
264273
.. versionadded:: 0.1.0
265274
266275
Note:

wemake_python_styleguide/violations/complexity.py

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,16 @@ class JonesScoreViolation(SimpleViolation):
9292
Solution:
9393
Refactor the module contents.
9494
95-
See also:
96-
https://github.com/Miserlou/JonesComplexity
97-
98-
This rule is configurable with ``--max-module-score``.
95+
Configuration:
96+
This rule is configurable with ``--max-jones-score``.
97+
Default:
98+
:str:`wemake_python_styleguide.options.defaults.MAX_JONES_SCORE`
9999
100100
.. versionadded:: 0.1.0
101101
102+
See also:
103+
https://github.com/Miserlou/JonesComplexity
104+
102105
Note:
103106
Returns Z200 as error code
104107
@@ -136,7 +139,9 @@ class TooManyImportsViolation(SimpleViolation):
136139
We do not make any differences between
137140
``import`` and ``from ... import ...``.
138141
139-
This rule is configurable with ``--max-imports``.
142+
Configuration:
143+
This rule is configurable with ``--max-imports``.
144+
Default: :str:`wemake_python_styleguide.options.defaults.MAX_IMPORTS`
140145
141146
.. versionadded:: 0.1.0
142147
@@ -167,7 +172,10 @@ class TooManyModuleMembersViolation(SimpleViolation):
167172
We also do not care about functions and classes being public or not.
168173
However, methods are counted separately on a per-class basis.
169174
170-
This rule is configurable with ``--max-module-members``.
175+
Configuration:
176+
This rule is configurable with ``--max-module-members``.
177+
Default:
178+
:str:`wemake_python_styleguide.options.defaults.MAX_MODULE_MEMBERS`
171179
172180
.. versionadded:: 0.1.0
173181
@@ -221,7 +229,10 @@ def second_function(argument):
221229
Please, note that ``_`` is a special case. It is not counted as a local
222230
variable. Since by design it means: do not count me as a real variable.
223231
224-
This rule is configurable with ``--max-local-variables``.
232+
Configuration:
233+
This rule is configurable with ``--max-local-variables``.
234+
Default:
235+
:str:`wemake_python_styleguide.options.defaults.MAX_LOCAL_VARIABLES`
225236
226237
.. versionadded:: 0.1.0
227238
@@ -249,7 +260,9 @@ class TooManyArgumentsViolation(ASTViolation):
249260
Split function into several functions.
250261
Then it will be easier to use them.
251262
252-
This rule is configurable with ``--max-arguments``.
263+
Configuration:
264+
This rule is configurable with ``--max-arguments``.
265+
Default: :str:`wemake_python_styleguide.options.defaults.MAX_ARGUMENTS`
253266
254267
.. versionadded:: 0.1.0
255268
@@ -276,7 +289,9 @@ class TooManyReturnsViolation(ASTViolation):
276289
Solution:
277290
Change your design.
278291
279-
This rule is configurable with ``--max-returns``.
292+
Configuration:
293+
This rule is configurable with ``--max-returns``.
294+
Default: :str:`wemake_python_styleguide.options.defaults.MAX_RETURNS`
280295
281296
.. versionadded:: 0.1.0
282297
@@ -302,7 +317,10 @@ class TooManyExpressionsViolation(ASTViolation):
302317
Solution:
303318
Split function into several functions, refactor your API.
304319
305-
This rule is configurable with ``--max-expressions``.
320+
Configuration:
321+
This rule is configurable with ``--max-expressions``.
322+
Default:
323+
:str:`wemake_python_styleguide.options.defaults.MAX_EXPRESSIONS`
306324
307325
.. versionadded:: 0.1.0
308326
@@ -331,17 +349,21 @@ class TooManyMethodsViolation(ASTViolation):
331349
Split this class into several classes.
332350
Then use composition or inheritance to refactor your code.
333351
This will protect you from "God object" anti-pattern.
334-
See: https://en.wikipedia.org/wiki/God_object
335352
336353
We do not make any difference between instance and class methods.
337354
We also do not care about functions and classes being public or not.
338355
We also do not count inherited methods from parents.
339356
This rule does not count attributes of a class.
340357
341-
This rule is configurable with ``--max-methods``.
358+
Configuration:
359+
This rule is configurable with ``--max-methods``.
360+
Default: :str:`wemake_python_styleguide.options.defaults.MAX_METHODS`
342361
343362
.. versionadded:: 0.1.0
344363
364+
See also:
365+
https://en.wikipedia.org/wiki/God_object
366+
345367
Note:
346368
Returns Z214 as error code
347369
@@ -368,7 +390,10 @@ class TooDeepNestingViolation(ASTViolation):
368390
We need to refactor our complex construction into simpler ones.
369391
We can use new functions or different constructions.
370392
371-
This rule is configurable with ``--max-offset-blocks``.
393+
Configuration:
394+
This rule is configurable with ``--max-offset-blocks``.
395+
Default:
396+
:str:`wemake_python_styleguide.options.defaults.MAX_OFFSET_BLOCKS`
372397
373398
.. versionadded:: 0.1.0
374399
@@ -411,13 +436,16 @@ class LineComplexityViolation(ASTViolation):
411436
With this technique a single new node in a line might trigger a complex
412437
refactoring process including several modules.
413438
414-
See also:
415-
https://github.com/Miserlou/JonesComplexity
416-
417-
This rule is configurable with ``--max-line-complexity``.
439+
Configuration:
440+
This rule is configurable with ``--max-line-complexity``.
441+
Default:
442+
:str:`wemake_python_styleguide.options.defaults.MAX_LINE_COMPLEXITY`
418443
419444
.. versionadded:: 0.1.0
420445
446+
See also:
447+
https://github.com/Miserlou/JonesComplexity
448+
421449
Note:
422450
Returns Z221 as error code
423451
@@ -453,7 +481,10 @@ class TooManyConditionsViolation(ASTViolation):
453481
# The next line has 2 conditions:
454482
if x_coord > 1 and x_coord < 10: ...
455483
456-
This rule is configurable with ``--max-conditions``.
484+
Configuration:
485+
This rule is configurable with ``--max-conditions``.
486+
Default:
487+
:str:`wemake_python_styleguide.options.defaults.MAX_CONDITIONS`
457488
458489
.. versionadded:: 0.1.0
459490
@@ -482,7 +513,9 @@ class TooManyElifsViolation(ASTViolation):
482513
For example, you can use some interface that
483514
just call a specific method without ``if``.
484515
485-
This rule is configurable with ``--max-elifs``.
516+
Configuration:
517+
This rule is configurable with ``--max-elifs``.
518+
Default: :str:`wemake_python_styleguide.options.defaults.MAX_ELIFS`
486519
487520
.. versionadded:: 0.1.0
488521
@@ -547,8 +580,6 @@ class TooManyBaseClassesViolation(ASTViolation):
547580
Solution:
548581
Restrict the number of base classes.
549582
550-
This rule is configurable with ``--max-base-classes``.
551-
552583
Example::
553584
554585
# Correct:
@@ -563,6 +594,11 @@ class SomeClassName(
563594
AddedClass,
564595
): ...
565596
597+
Configuration:
598+
This rule is configurable with ``--max-base-classes``.
599+
Default:
600+
:str:`wemake_python_styleguide.options.defaults.MAX_BASE_CLASSES`
601+
566602
.. versionadded:: 0.3.0
567603
568604
Note:

wemake_python_styleguide/violations/naming.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ class TooShortNameViolation(MaybeASTViolation):
316316
317317
This rule checks: modules, variables, attributes,
318318
functions, methods, and classes.
319-
This rule is configurable with ``--min-name-length``.
320319
321320
Example::
322321
@@ -328,6 +327,11 @@ class TooShortNameViolation(MaybeASTViolation):
328327
x = 1
329328
y = 2
330329
330+
Configuration:
331+
This rule is configurable with ``--min-name-length``.
332+
Default:
333+
:str:`wemake_python_styleguide.options.defaults.MAX_NAME_LENGTH`
334+
331335
.. versionadded:: 0.1.0
332336
.. versionchanged:: 0.4.0
333337

0 commit comments

Comments
 (0)