Module rulebook-pylint.rulebook_pylint.illegal_class_final_name
Functions
def register(linter: PyLinter)
-
Expand source code
def register(linter: 'PyLinter') -> None: linter.register_checker(IllegalClassFinalNameChecker(linter))
Classes
class IllegalClassFinalNameChecker (linter: PyLinter)
-
Expand source code
class IllegalClassFinalNameChecker(RulebookChecker): """See detail: https://hanggrian.github.io/rulebook/rules/#illegal-class-final-name""" MSG_ALL: str = 'illegal-class-final-name-all' MSG_UTIL: str = 'illegal-class-final-name-util' TITLE_CASE_REGEX: Pattern = \ regex.compile( r'((^[a-z]+)|([0-9]+)|([A-Z]{1}[a-z]+)|' + r'([A-Z]+(?=([A-Z][a-z])|($)|([0-9]))))', ) name: str = 'illegal-class-final-name' msgs: dict[str, MessageDefinitionTuple] = Messages.of(MSG_ALL, MSG_UTIL) options: Options = ( ( 'rulebook-illegal-class-final-names', { 'default': ('Util', 'Utility', 'Helper', 'Manager', 'Wrapper'), 'type': 'csv', 'metavar': '<comma-separated names>', 'help': 'A set of banned words.', }, ), ) _illegal_class_final_names: list[str] def open(self) -> None: self._illegal_class_final_names = self.linter.config.rulebook_illegal_class_final_names def visit_classdef(self, node: ClassDef) -> None: # checks for violation for word in [ m[0] for m in self.TITLE_CASE_REGEX.findall(node.name) \ if m[0] in self._illegal_class_final_names \ ]: if word in ('Util', 'Utility'): self.add_message( self.MSG_UTIL, node=node, args=node.name[:node.name.index(word)] + 's', col_offset=node.col_offset + 6, ) return self.add_message(self.MSG_ALL, node=node, args=word, col_offset=node.col_offset + 6)
See detail: https://hanggrian.github.io/rulebook/rules/#illegal-class-final-name
Checker instances should have the linter as argument.
Ancestors
- rulebook_pylint.checkers.RulebookChecker
- pylint.checkers.base_checker.BaseChecker
- pylint.config.arguments_provider._ArgumentsProvider
Class variables
var MSG_ALL : str
-
The type of the None singleton.
var MSG_UTIL : str
-
The type of the None singleton.
var TITLE_CASE_REGEX : _regex.Pattern
-
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._illegal_class_final_names = self.linter.config.rulebook_illegal_class_final_names
Called before visiting project (i.e. set of modules).
def visit_classdef(self, node: astroid.nodes.scoped_nodes.scoped_nodes.ClassDef) ‑> None
-
Expand source code
def visit_classdef(self, node: ClassDef) -> None: # checks for violation for word in [ m[0] for m in self.TITLE_CASE_REGEX.findall(node.name) \ if m[0] in self._illegal_class_final_names \ ]: if word in ('Util', 'Utility'): self.add_message( self.MSG_UTIL, node=node, args=node.name[:node.name.index(word)] + 's', col_offset=node.col_offset + 6, ) return self.add_message(self.MSG_ALL, node=node, args=word, col_offset=node.col_offset + 6)
class Pattern
-
Compiled regex object
Instance variables
var flags
-
The regex matching flags.
var groupindex
-
A dictionary mapping group names to group numbers.
var groups
-
The number of capturing groups in the pattern.
var named_lists
-
The named lists used by the regex.
var pattern
-
The pattern string from which the regex object was compiled.
Methods
def findall(string, pos=None, endpos=None, overlapped=False, concurrent=None, timeout=None)
-
findall(string, pos=None, endpos=None, overlapped=False, concurrent=None, timeout=None) –> list. Return a list of all matches of pattern in string. The matches may be overlapped if overlapped is True.
def finditer(string, pos=None, endpos=None, overlapped=False, concurrent=None, timeout=None)
-
finditer(string, pos=None, endpos=None, overlapped=False, concurrent=None, timeout=None) –> iterator. Return an iterator over all matches for the RE pattern in string. The matches may be overlapped if overlapped is True. For each match, the iterator returns a MatchObject.
def fullmatch(string, pos=None, endpos=None, concurrent=None, timeout=None)
-
fullmatch(string, pos=None, endpos=None, concurrent=None, timeout=None) –> MatchObject or None. Match zero or more characters against all of the string.
def match(string, pos=None, endpos=None, concurrent=None, timeout=None)
-
match(string, pos=None, endpos=None, concurrent=None, timeout=None) –> MatchObject or None. Match zero or more characters at the beginning of the string.
def scanner(string, pos=None, endpos=None, overlapped=False, concurrent=None, timeout=None)
-
scanner(string, pos=None, endpos=None, overlapped=False, concurrent=None, timeout=None) –> scanner. Return an scanner for the RE pattern in string. The matches may be overlapped if overlapped is True.
def search(string, pos=None, endpos=None, concurrent=None, timeout=None)
-
search(string, pos=None, endpos=None, concurrent=None, timeout=None) –> MatchObject or None. Search through string looking for a match, and return a corresponding match object instance. Return None if no match is found.
def split(string, maxsplit=0, concurrent=None, timeout=None)
-
split(string, maxsplit=0, concurrent=None, timeout=None) –> list. Split string by the occurrences of pattern.
def splititer(string, maxsplit=0, concurrent=None, timeout=None)
-
splititer(string, maxsplit=0, concurrent=None, timeout=None) –> iterator. Return an iterator yielding the parts of a split string.
def sub(repl, string, count=0, flags=0, pos=None, endpos=None, concurrent=None, timeout=None)
-
sub(repl, string, count=0, flags=0, pos=None, endpos=None, concurrent=None, timeout=None) –> newstring Return the string obtained by replacing the leftmost (or rightmost with a reverse pattern) non-overlapping occurrences of pattern in string by the replacement repl.
def subf(format, string, count=0, flags=0, pos=None, endpos=None, concurrent=None, timeout=None)
-
subf(format, string, count=0, flags=0, pos=None, endpos=None, concurrent=None, timeout=None) –> newstring Return the string obtained by replacing the leftmost (or rightmost with a reverse pattern) non-overlapping occurrences of pattern in string by the replacement format.
def subfn(...)
-
subfn(format, string, count=0, flags=0, pos=None, endpos=None, concurrent=None, timeout=None) –> (newstring, number of subs) Return the tuple (new_string, number_of_subs_made) found by replacing the leftmost (or rightmost with a reverse pattern) non-overlapping occurrences of pattern with the replacement format.
def subn(...)
-
subn(repl, string, count=0, flags=0, pos=None, endpos=None, concurrent=None, timeout=None) –> (newstring, number of subs) Return the tuple (new_string, number_of_subs_made) found by replacing the leftmost (or rightmost with a reverse pattern) non-overlapping occurrences of pattern with the replacement repl.