Skip to content

Commit

Permalink
Merge daaf848 into 6846ccd
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Sep 23, 2018
2 parents 6846ccd + daaf848 commit 2f0db70
Show file tree
Hide file tree
Showing 75 changed files with 1,659 additions and 560 deletions.
27 changes: 24 additions & 3 deletions CHANGELOG.md
Expand Up @@ -4,10 +4,31 @@ 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
## Version 0.0.14

### Features

This release is the last feature release before `0.1.0`.
However, there might be some supporting releases.
- Adds `WrongModuleNamePatternViolation`
and `WrongModuleNameUnderscoresViolation`
- Adds `TooManyImportsViolation` error and `--max-imports` option
- Adds `--i-control-code` option to ignore `InitModuleHasLogicViolation`
- Adds check for underscored numbers
- Forbids `u''` strings
- Adds `noqa` and `type` comments checks

### Misc

- Changes how many errors are generated for limits violations
- Refactors how visitors are injected into the checker, now using presets
- Creates new visitor type: `BaseTokenVisitor` for working with `tokenize`
- Improves typing support
- Adds `flake8-bandit` plugin
- Adds `flake8-eradicate` plugin
- Adds `flake8-print` plugin for development
- Removes `delegate` concept from the codebase


## Version 0.0.13 aka The Jones Complexity

### Features

Expand Down
159 changes: 138 additions & 21 deletions pyproject.lock

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "wemake-python-styleguide"
version = "0.0.13"
version = "0.0.14"
description = "The most opinionated linter ever, used by wemake.services"

license = "MIT"
Expand All @@ -9,7 +9,7 @@ authors = [
"Nikita Sobolev <mail@sobolevn.me>"
]

readme = "README.md" # Markdown files are supported
readme = "README.md"

repository = "https://github.com/wemake-services/wemake-python-styleguide"
homepage = "https://github.com/wemake-services/wemake-python-styleguide"
Expand All @@ -20,10 +20,11 @@ keywords = [
"linting",
"wemake.services",
"styleguide",
"code quality"
]

classifiers = [
"Development Status :: 3 - Alpha",
"Development Status :: 4 - Beta",
"Environment :: Console",
"Framework :: Flake8",
"Intended Audience :: Developers",
Expand All @@ -38,6 +39,7 @@ Z = "wemake_python_styleguide.checker:Checker"
[tool.poetry.dependencies]
python = "^3.6 || ^3.7"
flake8 = "^3.5"
attrs = "^18.2"

# This is a fix for issue-118
pycodestyle = "==2.3.1"
Expand All @@ -49,27 +51,29 @@ flake8-comprehensions = "^1.4"
flake8-docstrings = "^1.3"
flake8-string-format = "^0.2"
flake8-coding = "^1.3"
flake8-module-name = "^0.1"
flake8-bugbear = "^18.2"
flake8-pep3101 = "^1.2"
flake8-super-call = "^1.0"
flake8-debugger = "^3.1"
flake8-isort = "^2.5"
flake8-eradicate = "^0.1"
pep8-naming = "^0.7"
flake8-bandit = "^1.0"

[tool.poetry.dev-dependencies]
pytest-cov = "^2.6"
pytest-flake8 = "^1.0"
pytest-randomly = "^1.2"
pytest-isort = "^0.2"
pytest = "^3.8"
flake8-pytest = "^1.3"
mypy = "^0.610.0"
flake8-print = "^3.1"
mypy = "^0.630"
sphinx = "^1.8"
sphinx-autodoc-typehints = "^1.3"
sphinxcontrib-napoleon = "^0.6"
doc8 = "^0.8"
m2r = "^0.2"
sphinx_readable_theme = "^1.3"
typing_extensions = "^3.6"
added-value = "^0.8.0"
pytest-isort = "^0.2.1"
added-value = "^0.8"
4 changes: 2 additions & 2 deletions setup.cfg
Expand Up @@ -27,8 +27,8 @@ flake8-ignore =
wemake_python_styleguide/visitors/ast/*.py N802
# These modules should contain a lot of classes:
wemake_python_styleguide/errors/*.py Z208
# Disable filename checks for regression testing:
tests/test_checkers/test_regression/*.py N999
# There are `assert`s and subprocesses in tests:
tests/*.py S
# Disable some pydocstyle checks:
*.py D100 D104 D106 D401

Expand Down
1 change: 0 additions & 1 deletion tests/fixtures/config/wrong_arguments.py
Expand Up @@ -34,4 +34,3 @@ def static_normal_method(one, two, *three, four=4, five=5):
@staticmethod
def static_error_method(one, two, three, four, five, six):
pass

6 changes: 6 additions & 0 deletions tests/fixtures/noqa.py
Expand Up @@ -5,7 +5,13 @@
"""

from __future__ import print_function # noqa: Z102

from .version import get_version # noqa: Z100

full_name = u'Nikita Sobolev' # noqa: Z001
phone_number = 555_123_999 # noqa: Z002


def some():
from my_module import some_function # noqa: Z101

Expand Down
24 changes: 22 additions & 2 deletions tests/test_errors.py
@@ -1,16 +1,36 @@
# -*- coding: utf-8 -*-

import ast

from wemake_python_styleguide.errors.base import (
ASTStyleViolation,
BaseStyleViolation,
)


def test_visitor_returns_location():
"""Ensures that `BaseNodeVisitor` return correct error message."""
visitor = ASTStyleViolation(node=ast.parse(''), text='error')
visitor.error_template = '{0} {1}'
visitor.code = 1
assert visitor.node_items() == (0, 0, 'Z001 error')


def test_checker_default_location():
"""Ensures that `BaseStyleViolation` returns correct location."""
assert BaseStyleViolation(None)._location() == (0, 0)


def test_all_unique_error_codes(all_errors):
"""Ensures that all errors have unique error codes."""
codes = []
for error in all_errors:
codes.append(error.code)
codes.append(int(error.code))

assert len(set(codes)) == len(all_errors)


def test_all_errors_have_description_with_code(all_errors):
"""Ensures that all errors have description with error code."""
for error in all_errors:
assert error.code in error.__doc__
assert str(error.code) in error.__doc__
6 changes: 3 additions & 3 deletions tests/test_version.py
Expand Up @@ -2,7 +2,7 @@

import subprocess

from wemake_python_styleguide.version import version
from wemake_python_styleguide.version import pkg_name, pkg_version


def test_call_flake8_version():
Expand All @@ -13,5 +13,5 @@ def test_call_flake8_version():
)

output_text = output.decode('utf-8')
assert 'wemake-python-styleguide' in output_text
assert version in output_text
assert pkg_name in output_text
assert pkg_version in output_text
37 changes: 3 additions & 34 deletions tests/test_visitors/conftest.py
@@ -1,53 +1,22 @@
# -*- coding: utf-8 -*-

import ast
from collections import namedtuple
from textwrap import dedent
from typing import Sequence

import pytest

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:
"""
Sets parents for all nodes that do not have this prop.
This step is required due to how `flake8` works.
It does not set the same properties as `ast` module.
This function was the cause of `issue-112`.
Version changed: 0.0.11
"""
for statement in ast.walk(tree):
for child in ast.iter_child_nodes(statement):
if not hasattr(child, 'parent'): # noqa: Z112
setattr(child, 'parent', statement)

return tree
from wemake_python_styleguide.visitors.base import BaseVisitor


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 factory


@pytest.fixture(scope='session')
def assert_errors():
"""Helper function to assert visitor errors."""
def factory(visitor: BaseNodeVisitor, errors: Sequence[str]):
def factory(visitor: BaseVisitor, errors: Sequence[str]):
for index, error in enumerate(visitor.errors):
assert len(errors) > index, visitor.errors
assert error.code == errors[index].code
Expand All @@ -62,7 +31,7 @@ def options():
"""Returns the options builder."""
default_values = {
_to_dest_option(option.long_option_name): option.default
for option in Configuration.all_options()
for option in Configuration.options
}

Options = namedtuple('options', default_values.keys())
Expand Down
35 changes: 35 additions & 0 deletions tests/test_visitors/test_ast/conftest.py
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-

import ast
from textwrap import dedent

import pytest


def _maybe_set_parent(tree: ast.AST) -> ast.AST:
"""
Sets parents for all nodes that do not have this prop.
This step is required due to how `flake8` works.
It does not set the same properties as `ast` module.
This function was the cause of `issue-112`.
.. versionchanged:: 0.0.11
"""
for statement in ast.walk(tree):
for child in ast.iter_child_nodes(statement):
if not hasattr(child, 'parent'): # noqa: Z112
setattr(child, 'parent', statement)

return tree


@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 factory
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-

import pytest

from wemake_python_styleguide.visitors.ast.complexity.counts import (
ImportMembersVisitor,
TooManyImportsViolation,
)

module_import = ''
module_with_regular_imports = """
import sys
import os
"""

module_with_from_imports = """
from os import path
from sys import version
"""


@pytest.mark.parametrize('code', [
module_import,
module_with_regular_imports,
module_with_from_imports,
])
def test_module_import_counts_normal(
assert_errors, parse_ast_tree, code, default_options,
):
"""Testing that imports in a module work well."""
tree = parse_ast_tree(code)

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

assert_errors(visitor, [])


@pytest.mark.parametrize('code', [
module_with_regular_imports,
module_with_from_imports,
])
def test_module_import_counts_violation(
assert_errors, parse_ast_tree, code, options,
):
"""Testing that violations are raised when reaching max value."""
tree = parse_ast_tree(code)

option_values = options(max_imports=1)
visitor = ImportMembersVisitor(option_values, tree=tree)
visitor.run()

assert_errors(visitor, [TooManyImportsViolation])
Expand Up @@ -32,8 +32,8 @@ def test_module_counts_normal(
"""Testing that classes and functions in a module work well."""
tree = parse_ast_tree(code)

visitor = ModuleMembersVisitor(default_options, None)
visitor.visit(tree)
visitor = ModuleMembersVisitor(default_options, tree=tree)
visitor.run()

assert_errors(visitor, [])

Expand All @@ -49,7 +49,7 @@ def test_module_counts_violation(
tree = parse_ast_tree(code)

option_values = options(max_module_members=1)
visitor = ModuleMembersVisitor(option_values, None)
visitor.visit(tree)
visitor = ModuleMembersVisitor(option_values, tree=tree)
visitor.run()

assert_errors(visitor, [TooManyModuleMembersViolation])
Expand Up @@ -2,7 +2,7 @@

import pytest

from wemake_python_styleguide.visitors.ast.wrong_function_call import (
from wemake_python_styleguide.visitors.ast.general.wrong_function_call import (
BAD_FUNCTIONS,
WrongFunctionCallViolation,
WrongFunctionCallVisitor,
Expand Down
Expand Up @@ -2,7 +2,7 @@

import pytest

from wemake_python_styleguide.visitors.ast.wrong_import import (
from wemake_python_styleguide.visitors.ast.general.wrong_import import (
DottedRawImportViolation,
WrongImportVisitor,
)
Expand Down
Expand Up @@ -3,7 +3,7 @@
import pytest

from wemake_python_styleguide.constants import FUTURE_IMPORTS_WHITELIST
from wemake_python_styleguide.visitors.ast.wrong_import import (
from wemake_python_styleguide.visitors.ast.general.wrong_import import (
FutureImportViolation,
WrongImportVisitor,
)
Expand Down

0 comments on commit 2f0db70

Please sign in to comment.