Skip to content

Commit

Permalink
Version 0.0.13 release (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn authored Sep 15, 2018
1 parent bce6424 commit d5a9841
Show file tree
Hide file tree
Showing 17 changed files with 418 additions and 46 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ We follow Semantic Versions since the `0.1.0` release.
We used to have incremental versioning before `0.1.0`.


## Version 0.0.13 aka The Jones Complexity

This release is the last feature release before `0.1.0`.
However, there might be some supporting releases.

### Features

- Adds `jones` complexity checker
- Adds `--max-line-complexity` and `--max-jones-score` options

### Misc

- Improves docs: adds detailed installation instructions
- Removes `flake8-blind-except` plugin


## Version 0.0.12

This is just a supporting release.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ We are here not to:

1. Assume or check types, use `mypy` instead
2. Reformat code, since we believe that developers should do that
3. Suite everyone, this is *our* linter
4. Check for `SyntaxError`s or exceptions, write tests instead
3. Check for `SyntaxError`s or exceptions, write tests instead
4. Suite everyone, this is *our* linter


## Contributing
Expand Down
15 changes: 1 addition & 14 deletions pyproject.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,6 @@ mccabe = ">=0.6.0,<0.7.0"
pycodestyle = ">=2.0.0,<2.4.0"
pyflakes = ">=1.5.0,<1.7.0"

[[package]]
category = "main"
description = "A flake8 extension that checks for blind except: statements"
name = "flake8-blind-except"
optional = false
platform = "*"
python-versions = "*"
version = "0.1.1"

[package.dependencies]
setuptools = "*"

[[package]]
category = "main"
description = "A plugin for flake8 finding likely bugs and design problems in your program. Contains warnings that don't belong in pyflakes and pycodestyle."
Expand Down Expand Up @@ -797,7 +785,7 @@ python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4"
version = "1.23"

[metadata]
content-hash = "98de8b21f5b2a1bcafe5a454c39f16a47e51980ebc85925b5c4e504eb73965bc"
content-hash = "e00b93239a7e2149bee5a8ed276c3f7972c68bb16426bbb9d25f3e613a89cf5d"
platform = "*"
python-versions = "^3.6 || ^3.7"

Expand All @@ -814,7 +802,6 @@ coverage = ["03481e81d558d30d230bc12999e3edffe392d244349a90f4ef9b88425fac74ba",
doc8 = ["2df89f9c1a5abfb98ab55d0175fed633cae0cf45025b8b1e0ee5ea772be28543", "d12f08aa77a4a65eb28752f4bc78f41f611f9412c4155e2b03f1f5d4a45efe04"]
docutils = ["02aec4bd92ab067f6ff27a38a38a41173bf01bed8f89157768c1573f53e474a6", "51e64ef2ebfb29cae1faa133b3710143496eca21c530f3f71424d77687764274", "7a4bd47eaf6596e1295ecb11361139febe29b084a87bf005bf899f9a42edc3c6"]
flake8 = ["7253265f7abd8b313e3892944044a365e3f4ac3fcdcfb4298f55ee9ddf188ba0", "c7841163e2b576d435799169b78703ad6ac1bbb0f199994fc05f700b2a90ea37"]
flake8-blind-except = ["0d7d1adb4cabf2268d6eebb815a7a5014bcb7e8419f7a74339c46d0b8847b858", "aca3356633825544cec51997260fe31a8f24a1a2795ce8e81696b9916745e599"]
flake8-bugbear = ["07b6e769d7f4e168d590f7088eae40f6ddd9fa4952bed31602def65842682c83", "0ccf56975f4db1d69dc1cf3598c99d768ebf95d0cad27d76087954aa399b515a"]
flake8-builtins = ["8d806360767947c0035feada4ddef3ede32f0a586ef457e62d811b8456ad9a51", "cd7b1b7fec4905386a3643b59f9ca8e305768da14a49a7efb31fe9364f33cd04"]
flake8-coding = ["549c2b22c08711feda11795fb49f147a626305b602c547837bab405e7981f844", "f2ee7c3c8ae47f2d278111a2090655bcf170789c24ccfea519d93be2ede7571c"]
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "wemake-python-styleguide"
version = "0.0.12"
version = "0.0.13"
description = "The most opinionated linter ever, used by wemake.services"

license = "MIT"
Expand Down Expand Up @@ -46,7 +46,6 @@ flake8-builtins = "^1.4"
flake8-commas = "^2.0"
flake8-quotes = "^1.0"
flake8-comprehensions = "^1.4"
flake8-blind-except = "^0.1"
flake8-docstrings = "^1.3"
flake8-string-format = "^0.2"
flake8-coding = "^1.3"
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ filterwarnings =
addopts =
--doctest-modules
--flake8
--isort
--cov=wemake_python_styleguide
--cov-report=term:skip-covered
--cov-report=html
Expand Down
22 changes: 9 additions & 13 deletions tests/test_visitors/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import pytest

from wemake_python_styleguide.options import defaults
from wemake_python_styleguide.options.config import Configuration
from wemake_python_styleguide.visitors.base import BaseNodeVisitor


def maybe_set_parent(tree: ast.AST) -> ast.AST:
def _maybe_set_parent(tree: ast.AST) -> ast.AST:
"""
Sets parents for all nodes that do not have this prop.
Expand All @@ -31,11 +31,15 @@ def maybe_set_parent(tree: ast.AST) -> ast.AST:
return tree


def _to_dest_option(long_option_name: str) -> str:
return long_option_name[2:].replace('-', '_')


@pytest.fixture(scope='session')
def parse_ast_tree():
"""Helper function to convert code to ast."""
def factory(code: str) -> ast.AST:
return maybe_set_parent(ast.parse(dedent(code)))
return _maybe_set_parent(ast.parse(dedent(code)))

return factory

Expand All @@ -57,16 +61,8 @@ def factory(visitor: BaseNodeVisitor, errors: Sequence[str]):
def options():
"""Returns the options builder."""
default_values = {
'max_arguments': defaults.MAX_ARGUMENTS,
'max_expressions': defaults.MAX_EXPRESSIONS,
'max_local_variables': defaults.MAX_LOCAL_VARIABLES,
'max_returns': defaults.MAX_RETURNS,
'min_variable_length': defaults.MIN_VARIABLE_LENGTH,
'max_offset_blocks': defaults.MAX_OFFSET_BLOCKS,
'max_elifs': defaults.MAX_ELIFS,
'max_module_members': defaults.MAX_MODULE_MEMBERS,
'max_methods': defaults.MAX_METHODS,
'min_module_name_length': defaults.MIN_MODULE_NAME_LENGTH,
_to_dest_option(option.long_option_name): option.default
for option in Configuration.all_options()
}

Options = namedtuple('options', default_values.keys())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# -*- coding: utf-8 -*-

import pytest

from wemake_python_styleguide.visitors.ast.complexity.jones import (
JonesComplexityVisitor,
LineComplexityViolation,
)

line_simple = 'x = 2'
line_with_types = 'x: int = 2'
line_with_comprehension = 'x = [f for f in "abc"]'
line_with_math = 'x = y * 2 + 19 / 9.3'
line_inside_function = """
def some():
return 2 + 1
"""

line_inside_class = """
class Some():
field = 13 / 2
"""

function_declaration = 'def some(): ...'
class_declaration = 'class Some(object): ...'
empty_module = ''


@pytest.mark.parametrize('code', [
line_simple,
line_with_types,
line_with_comprehension,
line_with_math,
line_inside_function,
line_inside_class,
function_declaration,
class_declaration,
empty_module,
])
def test_regular_nodes(assert_errors, parse_ast_tree, code, default_options):
"""Testing that regular nodes do not raise errors."""
tree = parse_ast_tree(code)

visitor = JonesComplexityVisitor(default_options, tree=tree)
visitor.run()

assert_errors(visitor, [])


@pytest.mark.parametrize('code', [
line_simple,
line_inside_function,
line_inside_class,
])
def test_complex_lines(assert_errors, parse_ast_tree, code, options):
"""Testing that complex lines do raise errors."""
tree = parse_ast_tree(code)

option_values = options(max_line_complexity=1)
visitor = JonesComplexityVisitor(option_values, tree=tree)
visitor.run()

assert_errors(visitor, [LineComplexityViolation])


def test_same_complexity(parse_ast_tree, default_options):
"""Ensures that complexity is counted correctly."""
tree_without_types = parse_ast_tree(line_simple)
tree_with_types = parse_ast_tree(line_with_types)

simple_visitor = JonesComplexityVisitor(
default_options, tree=tree_without_types,
)
typed_visitor = JonesComplexityVisitor(
default_options, tree=tree_with_types,
)

simple_visitor.run()
typed_visitor.run()

assert len(simple_visitor._lines) == 1
assert len(simple_visitor._lines[1]) == 3
assert len(simple_visitor._lines[1]) == len(typed_visitor._lines[1])


@pytest.mark.parametrize('code, complexity', [
(line_with_comprehension, 6),
(line_with_math, 9),
])
def test_exact_complexity(parse_ast_tree, default_options, code, complexity):
"""Ensures that complexity is counted correctly."""
tree = parse_ast_tree(code)

visitor = JonesComplexityVisitor(default_options, tree=tree)
visitor.run()

assert len(visitor._lines) == 1
assert len(visitor._lines[1]) == complexity
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-

import pytest

from wemake_python_styleguide.visitors.ast.complexity.jones import (
JonesComplexityVisitor,
JonesScoreViolation,
)

module_without_nodes = ''
module_with_nodes = """
some = 1 + 2
other = [number for number in range(0, some)]
"""


@pytest.mark.parametrize('code', [
module_without_nodes,
module_with_nodes,
])
def test_module_score(assert_errors, parse_ast_tree, code, default_options):
"""Testing that regular nodes do not raise errors."""
tree = parse_ast_tree(code)

visitor = JonesComplexityVisitor(default_options, tree=tree)
visitor.run()

assert_errors(visitor, [])


@pytest.mark.parametrize('code', [
module_without_nodes,
module_with_nodes,
])
def test_module_score_error(assert_errors, parse_ast_tree, code, options):
"""Testing that regular nodes do raise errors."""
tree = parse_ast_tree(code)

option_values = options(max_jones_score=-1)
visitor = JonesComplexityVisitor(option_values, tree=tree)
visitor.run()

assert_errors(visitor, [JonesScoreViolation])
5 changes: 5 additions & 0 deletions wemake_python_styleguide/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
from wemake_python_styleguide.visitors.ast.complexity.function import (
FunctionComplexityVisitor,
)
from wemake_python_styleguide.visitors.ast.complexity.jones import (
JonesComplexityVisitor,
)
from wemake_python_styleguide.visitors.ast.complexity.nested import (
NestedComplexityVisitor,
)
Expand Down Expand Up @@ -70,6 +73,7 @@
OffsetVisitor,
ModuleMembersVisitor,
MethodMembersVisitor,
JonesComplexityVisitor,

# Modules:
WrongModuleNameVisitor,
Expand All @@ -90,6 +94,7 @@ class Checker(object):
config = Configuration()
options: ConfigurationOptions

# Receive `logic_line` as the first argument to make this plugin logical
def __init__(self, tree: Module, filename: str = constants.STDIN) -> None:
"""Creates new checker instance."""
self.tree = tree
Expand Down
Loading

0 comments on commit d5a9841

Please sign in to comment.