Example #1
0
    def _check_executable_mismatch(self, shebang_token) -> None:
        is_executable = is_executable_file(self.filename)

        if is_executable and shebang_token is None:
            self.add_violation(
                ShebangViolation(
                    text='file is executable but no shebang is present', ), )

        if not is_executable and shebang_token is not None:
            self.add_violation(
                ShebangViolation(
                    text='shebang is present but the file is not executable',
                ), )
    def _check_valid_shebang(self, token: tokenize.TokenInfo) -> None:
        if self._python_executable not in token.line:
            self.add_violation(
                ShebangViolation(
                    text='shebang is present but does not contain `python`', ),
            )

        if token.start[1] != 0:
            self.add_violation(
                ShebangViolation(
                    text='there is a whitespace before shebang', ), )

        if token.start[0] != 1:
            self.add_violation(
                ShebangViolation(
                    text='there are blank or comment lines before shebang', ),
            )
Example #3
0
    def _check_valid_shebang(self, shebang_token: tokenize.TokenInfo) -> None:
        token_line = shebang_token.line
        on_first_line = shebang_token.start[0] == 1
        first_line_token = shebang_token.start[1] == 0
        if self._python_executable not in token_line:
            self.add_violation(
                ShebangViolation(
                    text='shebang is present but does not contain `python`', ),
            )

        if not first_line_token:
            self.add_violation(
                ShebangViolation(
                    text='there is whitespace before shebang', ), )

        if not on_first_line:
            self.add_violation(
                ShebangViolation(
                    text='there are blank or comment lines before shebang', ),
            )
    def _check_executable_mismatch(
        self,
        token: tokenize.TokenInfo,
        *,
        is_shebang: bool,
    ) -> None:
        if is_windows() or self.filename == STDIN:
            # Windows does not have this concept of "executable" file.
            # The same for STDIN inputs.
            return

        is_executable = is_executable_file(self.filename)
        if is_executable and not is_shebang:
            self.add_violation(
                ShebangViolation(
                    text='file is executable but no shebang is present', ), )
        elif not is_executable and is_shebang:
            self.add_violation(
                ShebangViolation(
                    text='shebang is present but the file is not executable',
                ), )