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 _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),
         )