Exemplo n.º 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)
Exemplo n.º 2
0
    def _check_module_name(self) -> None:
        if logical.is_wrong_name(self.stem, constants.MODULE_NAMES_BLACKLIST):
            self.add_violation(naming.WrongModuleNameViolation())

        if access.is_magic(self.stem):
            if self.stem not in constants.MAGIC_MODULE_NAMES_WHITELIST:
                self.add_violation(naming.WrongModuleMagicNameViolation())

        if access.is_private(self.stem):
            self.add_violation(naming.PrivateNameViolation(text=self.stem))

        if logical.does_contain_unicode(self.stem):
            self.add_violation(naming.UnicodeNameViolation(text=self.stem))
Exemplo n.º 3
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)