Exemple #1
0
    def _check_empty_line_after_codding(
        self,
        token: tokenize.TokenInfo,
    ) -> None:
        """
        Checks that we have a blank line after the magic comments.

        PEP-263 says: a magic comment must be placed into the source
        files either as first or second line in the file

        See also:
            https://www.python.org/dev/peps/pep-0263/

        """
        if token.start == (1, 0):
            tokens = iter(self.file_tokens[self.file_tokens.index(token):])
            available_offset = 2  # comment + newline
            while True:
                next_token = next(tokens)
                if not available_offset:
                    available_offset = self._offset_for_comment_line(
                        next_token,
                    )

                if available_offset > 0:
                    available_offset -= 1
                    continue

                if next_token.exact_type not in self._allowed_newlines:
                    self.add_violation(EmptyLineAfterCodingViolation(token))
                break
    def _check_comment_capitalization(
        self,
        token: tokenize.TokenInfo,
    ) -> None:
        """
        Checks that single line comments start with capital letters.

        for comment test if starts with
            lowercase: lookup if multiline starts with capital
            uppercase: check if it is single line or no previous comment
        """
        if token.start[0] == 1:
            tokens = iter(self.file_tokens[self.file_tokens.index(token):])
            available_offset = 2  # comment + newline
            while True:
                next_token = next(tokens)
                if not available_offset:
                    available_offset = self._offset_for_comment_line(
                        next_token,
                    )

                if available_offset > 0:
                    available_offset -= 1
                    continue

                if next_token.exact_type not in self._allowed_newlines:
                    self.add_violation(EmptyLineAfterCodingViolation(token))
                break
    def _check_empty_line_after_codding(
        self,
        token: tokenize.TokenInfo,
    ) -> None:
        """
        Checks that we have a blank line after the magic comments.

        PEP-263 says: a magic comment must be placed into the source
        files either as first or second line in the file

        See also:
            https://www.python.org/dev/peps/pep-0263/

        """
        if token.start != (1, 0):
            return

        tokens = iter(self.file_tokens[self.file_tokens.index(token):])
        available_offset = 2  # comment + newline

        while True:
            next_token = next(tokens)
            if not available_offset:
                available_offset = self._offset_for_comment_line(
                    next_token,
                )

            if available_offset > 0:
                available_offset -= 1
                continue

            # We have a coverage error here.
            # It reports, that this line is not covered.
            # While we do have test cases for both correct and wrong cases.
            if next_token.exact_type not in self._newlines:  # pragma: no cover
                self.add_violation(EmptyLineAfterCodingViolation(token))
            break