Skip to content

Commit

Permalink
Adds versionadded tag to each violation, closes #290
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Oct 25, 2018
1 parent 4775806 commit 00d24b4
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ matrix:
sudo: true

install:
- pip install "poetry>=0.12"
- pip install poetry
- poetry install

script:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ to the project during `#hactoberfest`. List of awesome people:

### Misc

- Updates `poetry` version
- Refactoring: some general changes, including better names and APIs
- Improves docs: now we have `versionadded` for each violation
- Improves tests: now we are testing options
- Improves tests: now we have different `tests/` folder structure
- Improves tests: now we are testing presets
- Improves tests: now we are using different logic inside `assert_errors`
Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ install:
# Setting up enviroment
- "pip install poetry"
- "poetry install"
- "poetry develop"

build: off

Expand Down
10 changes: 10 additions & 0 deletions tests/test_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-

from wemake_python_styleguide.options.config import Configuration


def test_option_docs():
"""Ensures that all options are documented."""
for option in Configuration.options:
option_name = '``' + option.long_option_name[2:] + '``'
assert option_name in Configuration.__doc__
6 changes: 6 additions & 0 deletions tests/test_violations.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ def test_all_violations_have_description_with_code(all_violations):
"""Ensures that all violations have description with violation code."""
for violation in all_violations:
assert str(violation.code) in violation.__doc__


def test_all_violations_have_versionadded(all_violations):
"""Ensures that all violations have `versionadded` tag."""
for violation in all_violations:
assert '.. versionadded:: ' in violation.__doc__
8 changes: 7 additions & 1 deletion wemake_python_styleguide/options/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Configuration(object):
:str:`wemake_python_styleguide.options.defaults.MAX_OFFSET_BLOCKS`
- ``max-elifs`` - maximum number of ``elif`` blocks, defaults to
:str:`wemake_python_styleguide.options.defaults.MAX_ELIFS`
- `max-module-members` - maximum number of classes and functions
- ``max-module-members`` - maximum number of classes and functions
in a single module, defaults to
:str:`wemake_python_styleguide.options.defaults.MAX_MODULE_MEMBERS`
- ``max-methods`` - maximum number of methods in a single class,
Expand All @@ -84,9 +84,15 @@ class Configuration(object):
- ``max-jones-score`` - maximum Jones score for a module, which is equal
to the median of all lines complexity sum, defaults to
:str:`wemake_python_styleguide.options.defaults.MAX_JONES_SCORE`
- ``max-imports`` - maximum number of imports in a single module,
defaults to
:str:`wemake_python_styleguide.options.defaults.MAX_IMPORTS`
- ``max-conditions`` - maximum number of boolean conditions
in a single ``if`` or ``while`` node, defaults to
:str:`wemake_python_styleguide.options.defaults.MAX_CONDITIONS`
- ``max-base-classes`` - maximum number of parent classes inside a class
definition, defaults to
:str:`wemake_python_styleguide.options.defaults.MAX_BASE_CLASSES`
All options are configurable via ``flake8`` CLI:
Expand Down
38 changes: 38 additions & 0 deletions wemake_python_styleguide/violations/best_practices.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class WrongMagicCommentViolation(SimpleViolation):
type = MyClass.get_type() # noqa
coordinate = 10 # type: int
.. versionadded:: 0.1.0
Note:
Returns Z400 as error code
Expand Down Expand Up @@ -154,6 +156,8 @@ class WrongDocCommentViolation(TokenizeViolation):
#:
NAMES_WHITELIST = ['feature', 'bug', 'research']
.. versionadded:: 0.1.0
Note:
Returns Z401 as error code
Expand Down Expand Up @@ -192,6 +196,8 @@ class WrongModuleMetadataViolation(ASTViolation):
__author__ = 'Nikita Sobolev'
__version__ = 0.1.2
.. versionadded:: 0.1.0
Note:
Returns Z410 as error code
Expand All @@ -216,6 +222,8 @@ class EmptyModuleViolation(ASTViolation):
1. delete it
2. drop some documentation in it, so you will explain why it is there
.. versionadded:: 0.1.0
Note:
Returns Z411 as error code
Expand Down Expand Up @@ -249,6 +257,8 @@ class InitModuleHasLogicViolation(ASTViolation):
1. comments, since they are dropped before AST comes in play
2. docs string, because sometimes it is required to state something
.. versionadded:: 0.1.0
Note:
Returns Z412 as error code
Expand Down Expand Up @@ -286,6 +296,8 @@ class WrongKeywordViolation(ASTViolation):
nonlocal
global
.. versionadded:: 0.1.0
Note:
Returns Z420 as error code
Expand Down Expand Up @@ -313,6 +325,8 @@ class WrongFunctionCallViolation(ASTViolation):
See also:
https://www.youtube.com/watch?v=YjHsOrOOSuI
.. versionadded:: 0.1.0
Note:
Returns Z421 as error code
Expand Down Expand Up @@ -348,6 +362,8 @@ class FutureImportViolation(ASTViolation):
# Wrong:
from __future__ import print_function
.. versionadded:: 0.1.0
Note:
Returns Z422 as error code
Expand Down Expand Up @@ -383,6 +399,8 @@ class RaiseNotImplementedViolation(ASTViolation):
See Also:
https://stackoverflow.com/a/44575926/4842742
.. versionadded:: 0.1.0
Note:
Returns Z423 as error code
Expand Down Expand Up @@ -420,6 +438,8 @@ class BaseExceptionViolation(ASTViolation):
https://docs.python.org/3/library/exceptions.html#exception-hierarchy
https://help.semmle.com/wiki/pages/viewpage.action?pageId=1608527
.. versionadded:: 0.3.0
Note:
Returns Z424 as error code
Expand Down Expand Up @@ -465,6 +485,8 @@ def do_some():
def inner():
...
.. versionadded:: 0.1.0
Note:
Returns Z430 as error code
Expand Down Expand Up @@ -505,6 +527,8 @@ class Some(object):
class Inner(object):
...
.. versionadded:: 0.1.0
Note:
Returns Z431 as error code
Expand Down Expand Up @@ -552,6 +576,8 @@ class MagicNumberViolation(ASTViolation):
See also:
https://en.wikipedia.org/wiki/Magic_number_(programming)
.. versionadded:: 0.1.0
Note:
Returns Z432 as error code
Expand All @@ -574,6 +600,8 @@ class StaticMethodViolation(ASTViolation):
Solution:
Use instance methods, ``@classmethod``, or functions instead.
.. versionadded:: 0.1.0
Note:
Returns Z433 as error code
Expand Down Expand Up @@ -606,6 +634,8 @@ class BadMagicMethodViolation(ASTViolation):
See also:
https://www.youtube.com/watch?v=F6u5rhUQ6dU
.. versionadded:: 0.1.0
Note:
Returns Z434 as error code
Expand Down Expand Up @@ -644,6 +674,8 @@ def some():
See also:
https://github.com/seddonym/layer_linter
.. versionadded:: 0.1.0
Note:
Returns Z435 as error code
Expand All @@ -667,6 +699,8 @@ class RedundantForElseViolation(ASTViolation):
Refactor your ``else`` case logic
to be inside the ``for`` body.
.. versionadded:: 0.3.0
Note:
Returns Z436 as error code
Expand Down Expand Up @@ -702,6 +736,8 @@ class RedundantFinallyViolation(ASTViolation):
finally:
f.close()
.. versionadded:: 0.3.0
Note:
Returns Z437 as error code
Expand Down Expand Up @@ -731,6 +767,8 @@ class ReassigningVariableToItselfViolation(ASTViolation):
some = some
x_coord, y_coord = x_coord, y_coord
.. versionadded:: 0.3.0
Note:
Returns Z438 as error code
"""
Expand Down
31 changes: 30 additions & 1 deletion wemake_python_styleguide/violations/complexity.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class JonesScoreViolation(SimpleViolation):
This rule is configurable with ``--max-module-score``.
.. versionadded:: 0.1.0
Note:
Returns Z200 as error code
Expand Down Expand Up @@ -139,6 +141,8 @@ class TooManyImportsViolation(SimpleViolation):
This rule is configurable with ``--max-imports``.
.. versionadded:: 0.1.0
Note:
Returns Z201 as error code
Expand Down Expand Up @@ -168,6 +172,8 @@ class TooManyModuleMembersViolation(SimpleViolation):
This rule is configurable with ``--max-module-members``.
.. versionadded:: 0.1.0
Note:
Returns Z202 as error code
Expand Down Expand Up @@ -221,6 +227,8 @@ def second_function(argument):
This rule is configurable with ``--max-local-variables``.
.. versionadded:: 0.1.0
Note:
Returns Z210 as error code
Expand All @@ -247,6 +255,8 @@ class TooManyArgumentsViolation(ASTViolation):
This rule is configurable with ``--max-arguments``.
.. versionadded:: 0.1.0
Note:
Returns Z211 as error code
Expand All @@ -272,6 +282,8 @@ class TooManyReturnsViolation(ASTViolation):
This rule is configurable with ``--max-returns``.
.. versionadded:: 0.1.0
Note:
Returns Z212 as error code
Expand All @@ -296,6 +308,8 @@ class TooManyExpressionsViolation(ASTViolation):
This rule is configurable with ``--max-expressions``.
.. versionadded:: 0.1.0
Note:
Returns Z213 as error code
Expand Down Expand Up @@ -330,6 +344,8 @@ class TooManyMethodsViolation(ASTViolation):
This rule is configurable with ``--max-methods``.
.. versionadded:: 0.1.0
Note:
Returns Z214 as error code
Expand Down Expand Up @@ -358,6 +374,8 @@ class TooDeepNestingViolation(ASTViolation):
This rule is configurable with ``--max-offset-blocks``.
.. versionadded:: 0.1.0
Note:
Returns Z220 as error code
Expand Down Expand Up @@ -402,6 +420,8 @@ class LineComplexityViolation(ASTViolation):
This rule is configurable with ``--max-line-complexity``.
.. versionadded:: 0.1.0
Note:
Returns Z221 as error code
Expand Down Expand Up @@ -439,6 +459,8 @@ class TooManyConditionsViolation(ASTViolation):
This rule is configurable with ``--max-conditions``.
.. versionadded:: 0.1.0
Note:
Returns Z222 as error code
Expand Down Expand Up @@ -466,6 +488,8 @@ class TooManyElifsViolation(ASTViolation):
This rule is configurable with ``--max-elifs``.
.. versionadded:: 0.1.0
Note:
Returns Z223 as error code
Expand All @@ -492,6 +516,7 @@ class TooManyForsInComprehensionViolation(ASTViolation):
``for`` loops, comprehensions, or different functions.
Example::
# Wrong:
ast_nodes = [
target
Expand All @@ -500,6 +525,8 @@ class TooManyForsInComprehensionViolation(ASTViolation):
for _ in range(10)
]
.. versionadded:: 0.3.0
Note:
Returns Z224 as error code
Expand All @@ -525,7 +552,7 @@ class TooManyBaseClassesViolation(ASTViolation):
Solution:
Restrict the number of base classes.
This rule is configurable with ``--max_base_classes``.
This rule is configurable with ``--max-base-classes``.
Example::
Expand All @@ -541,6 +568,8 @@ class SomeClassName(
AddedClass,
): ...
.. versionadded:: 0.3.0
Note:
Returns Z225 as error code
"""
Expand Down
Loading

0 comments on commit 00d24b4

Please sign in to comment.