Beispiel #1
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)
    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), )
    def _ensure_reserved_name(
        self,
        node: ast.AST,
        name: str,
        *,
        is_first_argument: bool,
    ) -> None:
        if is_first_argument:
            return

        if not logical.is_wrong_name(name, SPECIAL_ARGUMENT_NAMES_WHITELIST):
            return

        self._error_callback(
            naming.ReservedArgumentNameViolation(node, text=name),
        )
Beispiel #4
0
    def check_name(
        self,
        node: ast.AST,
        name: str,
        is_first_argument: bool = False,
    ) -> None:
        if logical.is_wrong_name(name, 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 logical.does_contain_unicode(name):
            self._error_callback(naming.UnicodeNameViolation(node, text=name))

        self._ensure_length(node, name)
        self._ensure_underscores(node, name)