def process_module(self, node: nodes.Module) -> None: with node.stream() as stream: for (line_num, line) in enumerate(stream): line = line.rstrip() if line.endswith(b"#"): if not is_line_commented(line[:-1]): self.add_message("empty-comment", line=line_num + 1)
def process_module(self, node: nodes.Module) -> None: """inspect the source file to find encoding problem""" encoding = node.file_encoding if node.file_encoding else "ascii" with node.stream() as stream: for lineno, line in enumerate(stream): self._check_encoding(lineno + 1, line, encoding)
def process_module(self, node: nodes.Module) -> None: """Process a module. the module's content is accessible via node.stream() function """ with node.stream() as stream: for (lineno, line) in enumerate(stream): if line.rstrip().endswith("\\"): self.add_message("backslash-line-continuation", line=lineno)
def process_module(self, node: nodes.Module) -> None: """process a module the module's content is accessible via the stream object stream must implement the readlines method """ with node.stream() as stream: self.append_stream(self.linter.current_name, stream, node.file_encoding)
def process_module(self, node: nodes.Module) -> None: r"""Check whether the copyright notice is correctly placed in the source file of a module. Compare the first lines of a source file against the standard copyright notice (i.e., the `golden` variable below). Suffix whitespace (including newline symbols) is not considered during the comparison. Pylint will report a message if the copyright notice is not correctly placed. Args: node: the module to be checked. """ # Exit if the checker is disabled in the source file. if not self.linter.is_message_enabled( "wrong-or-nonexistent-copyright-notice"): return golden = [ b'# Copyright 20XX The Cirq Developers', b'#', b'# Licensed under the Apache License, Version 2.0 (the "License");', b'# you may not use this file except in compliance with the License.', b'# You may obtain a copy of the License at', b'#', b'# https://www.apache.org/licenses/LICENSE-2.0', b'#', b'# Unless required by applicable law or agreed to in writing, software', b'# distributed under the License is distributed on an "AS IS" BASIS,', b'# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.', b'# See the License for the specific language governing permissions and', b'# limitations under the License.', ] with node.stream() as stream: for expected_line, (lineno, line) in zip(golden, enumerate(stream)): for expected_char, (colno, char) in zip(expected_line, enumerate(line)): # The text needs to be same as the template except for the year. if expected_char != char and not (lineno == 0 and 14 <= colno <= 15): self.add_message( "wrong-or-nonexistent-copyright-notice", line=lineno + 1, col_offset=colno, ) return # The line cannot be shorter than the template or contain extra text. if len(line) < len(expected_line) or line[ len(expected_line):].strip() != b'': self.add_message( "wrong-or-nonexistent-copyright-notice", line=lineno + 1, col_offset=min(len(line), len(expected_line)), ) return
def process_module(self, node: nodes.Module) -> None: """Process a module. the module's content is accessible via the stream object stream must implement the readlines method """ if self.linter.current_name is None: warnings.warn( ("In pylint 3.0 the current_name attribute of the linter object should be a string. " "If unknown it should be initialized as an empty string."), DeprecationWarning, ) with node.stream() as stream: self.append_stream(self.linter.current_name, stream, node.file_encoding) # type: ignore[arg-type]
def process_module(self, node: nodes.Module) -> None: """Perform the actual check by checking module stream.""" with node.stream() as stream: codec, codec_line = self._determine_codec(stream) self._check_codec(codec, codec_line) stream.seek(0) # Check for invalid content (controls/chars) for (lineno, line) in enumerate(_fix_utf16_32_line_stream(stream, codec), start=1): if lineno == 1: line = _remove_bom(line, codec) self._check_bidi_chars(line, lineno, codec) self._check_invalid_chars(line, lineno, codec)
def tokenize_module(node: nodes.Module) -> List[tokenize.TokenInfo]: with node.stream() as stream: readline = stream.readline return list(tokenize.tokenize(readline))