Module rulebook-pylint.rulebook_pylint.file_size
Functions
def register(linter: PyLinter)
-
Expand source code
def register(linter: 'PyLinter') -> None: linter.register_checker(FileSizeChecker(linter))
Classes
class FileSizeChecker (linter: PyLinter)
-
Expand source code
class FileSizeChecker(RulebookFileChecker): """See detail: https://hanggrian.github.io/rulebook/rules/#file-size""" MSG: str = 'file-size' name: str = 'file-size' msgs: dict[str, MessageDefinitionTuple] = Messages.of(MSG) options: Options = ( ( 'rulebook-max-file-size', { 'default': 1000, 'type': 'int', 'metavar': '<int>', 'help': 'Max lines of code that is allowed.', }, ), ) _max_file_size: int def open(self) -> None: self._max_file_size = self.linter.config.rulebook_max_file_size def process_module(self, node: Module) -> None: # checks for violation with node.stream() as stream: size: int = len(stream.readlines()) if size < self._max_file_size: return self.add_message(self.MSG, line=0, args=self._max_file_size)
See detail: https://hanggrian.github.io/rulebook/rules/#file-size
Checker instances should have the linter as argument.
Ancestors
- rulebook_pylint.checkers.RulebookFileChecker
- pylint.checkers.base_checker.BaseRawFileChecker
- pylint.checkers.base_checker.BaseChecker
- pylint.config.arguments_provider._ArgumentsProvider
- abc.ABC
Class variables
var MSG : str
-
The type of the None singleton.
var msgs : dict[str, tuple[str, str, str] | tuple[str, str, str, pylint.typing.ExtraMessageOptions]]
-
The type of the None singleton.
var name : str
-
The type of the None singleton.
var options : tuple[tuple[str, dict[str, str | bool | int | re.Pattern[str] | Iterable[str | int | re.Pattern[str]] | type['_CallbackAction'] | Callable[[Any], Any] | Callable[[Any, Any, Any, Any], Any] | None]], ...]
-
The type of the None singleton.
Methods
def open(self) ‑> None
-
Expand source code
def open(self) -> None: self._max_file_size = self.linter.config.rulebook_max_file_size
Called before visiting project (i.e. set of modules).
def process_module(self, node: astroid.nodes.scoped_nodes.scoped_nodes.Module) ‑> None
-
Expand source code
def process_module(self, node: Module) -> None: # checks for violation with node.stream() as stream: size: int = len(stream.readlines()) if size < self._max_file_size: return self.add_message(self.MSG, line=0, args=self._max_file_size)
Process a module.
The module's content is accessible via
astroid.stream