Module rulebook-pylint.rulebook_pylint.class_name_abbreviation

Functions

def register(linter: PyLinter)
Expand source code
def register(linter: 'PyLinter') -> None:
    linter.register_checker(ClassNameAbbreviationChecker(linter))

Classes

class ClassNameAbbreviationChecker (linter: PyLinter)
Expand source code
class ClassNameAbbreviationChecker(RulebookChecker):
    """See detail: https://hanggrian.github.io/rulebook/rules/#class-name-abbreviation"""
    MSG: str = 'class-name-abbreviation'

    ABBREVIATION_REGEX: Pattern = regex.compile(r'[A-Z]{3,}')

    name: str = 'class-name-abbreviation'
    msgs: dict[str, MessageDefinitionTuple] = Messages.of(MSG)

    def visit_classdef(self, node: ClassDef) -> None:
        # checks for violation
        if not bool(self.ABBREVIATION_REGEX.search(node.name)):
            return
        self.add_message(
            self.MSG,
            node=node,
            args=self._transform(node.name),
            col_offset=node.col_offset + 6,
        )

    @staticmethod
    def _transform(name: str) -> str:
        def replace_match(match):
            group_value: str = match.group()
            return group_value[0] + group_value[1:].lower() \
                if match.end() == len(name) \
                else group_value[0] + group_value[1:-1].lower() + group_value[-1]

        return ClassNameAbbreviationChecker.ABBREVIATION_REGEX.sub(replace_match, name)

See detail: https://hanggrian.github.io/rulebook/rules/#class-name-abbreviation

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 ABBREVIATION_REGEX : _regex.Pattern

The type of the None singleton.

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.

Methods

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
    if not bool(self.ABBREVIATION_REGEX.search(node.name)):
        return
    self.add_message(
        self.MSG,
        node=node,
        args=self._transform(node.name),
        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.