def _ensure_complex_naming(
        self,
        node: ast.AST,
        name: str,
        *,
        is_first_argument: bool,
    ) -> None:
        if logical.is_wrong_name(name, self._variable_names_blacklist):
            self._error_callback(
                naming.WrongVariableNameViolation(node, text=name), )

        if not is_first_argument:
            if logical.is_wrong_name(name, SPECIAL_ARGUMENT_NAMES_WHITELIST):
                self._error_callback(
                    naming.ReservedArgumentNameViolation(node, text=name), )

        if access.is_unused(name) and len(name) > 1:
            self._error_callback(
                naming.WrongUnusedVariableNameViolation(node, text=name), )

        unreadable_sequence = alphabet.get_unreadable_characters(
            name,
            UNREADABLE_CHARACTER_COMBINATIONS,
        )
        if unreadable_sequence:
            self._error_callback(
                naming.UnreadableNameViolation(node,
                                               text=unreadable_sequence), )
Beispiel #2
0
    def check_name(
        self,
        node: ast.AST,
        name: str,
        *,
        is_first_argument: bool = False,
    ) -> None:
        if logical.is_wrong_name(name, self._variable_names_blacklist):
            self._error_callback(
                naming.WrongVariableNameViolation(node, text=name),
            )

        if not is_first_argument:
            if logical.is_wrong_name(name, SPECIAL_ARGUMENT_NAMES_WHITELIST):
                self._error_callback(
                    naming.ReservedArgumentNameViolation(node, text=name),
                )

        if alphabet.does_contain_unicode(name):
            self._error_callback(naming.UnicodeNameViolation(node, text=name))

        unreadable_sequence = alphabet.get_unreadable_characters(
            name, UNREADABLE_CHARACTER_COMBINATIONS,
        )
        if unreadable_sequence:
            self._error_callback(
                naming.UnreadableNameViolation(node, text=unreadable_sequence),
            )

        self._ensure_length(node, name)
        self._ensure_underscores(node, name)
Beispiel #3
0
def test_unreadable_name(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    own_naming_template,
    expression,
    default_options,
    mode,
):
    """Ensures that unreadable names are not allowed."""
    tree = parse_ast_tree(
        mode(own_naming_template.format(expression, expression)), )

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

    unreadable = get_unreadable_characters(
        expression,
        constants.UNREADABLE_CHARACTER_COMBINATIONS,
    )

    assert_errors(
        visitor,
        [UnreadableNameViolation],
        ignored_types=UpperCaseAttributeViolation,
    )
    assert_error_text(
        visitor,
        unreadable,
        ignored_types=UpperCaseAttributeViolation,
    )
 def _check_module_name_readability(self) -> None:
     unreadable_sequence = alphabet.get_unreadable_characters(
         self.stem,
         constants.UNREADABLE_CHARACTER_COMBINATIONS,
     )
     if unreadable_sequence:
         self.add_violation(
             naming.UnreadableNameViolation(text=self.stem), )
 def _ensure_readable_name(self, node: ast.AST, name: str) -> None:
     unreadable_sequence = alphabet.get_unreadable_characters(
         name, UNREADABLE_CHARACTER_COMBINATIONS,
     )
     if unreadable_sequence:
         self._error_callback(
             naming.UnreadableNameViolation(node, text=unreadable_sequence),
         )
def test_unreadable_name(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    code,
    expression,
    default_options,
    mode,
):
    """Ensures that unreadable names are not allowed."""
    tree = parse_ast_tree(mode(code.format(expression, expression)))

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

    unreadable = get_unreadable_characters(
        expression,
        constants.UNREADABLE_CHARACTER_COMBINATIONS,
    )

    assert_errors(visitor, [UnreadableNameViolation])
    assert_error_text(visitor, unreadable)