Module rulebook-pylint.rulebook_pylint.todo_comment

Functions

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

Classes

class Match

Match object

Instance variables

var endpos

The final position beyond which the regex engine won't search.

var fuzzy_changes

A tuple of the positions of the substitutions, insertions and deletions.

var fuzzy_counts

A tuple of the number of substitutions, insertions and deletions.

var lastgroup

The name of the last matched capturing group, or None.

var lastindex

The group number of the last matched capturing group, or None.

var partial

Whether it's a partial match.

var pos

The position at which the regex engine starting searching.

var re

The regex object that produced this match object.

var regs

A tuple of the spans of the capturing groups.

var string

The string that was searched, or None if it has been detached.

Methods

def allcaptures(self, /)

allcaptures() –> list of strings or tuple of list of strings. Return the captures of all the groups of the match and the whole match.

def allspans(self, /)

allspans() –> list of 2-tuple of ints or tuple of list of 2-tuple of ints. Return the spans (a 2-tuple of the indices of the start and end) of all the captures of all the groups of the match and the whole match.

def captures(...)

captures([group1, …]) –> list of strings or tuple of list of strings. Return the captures of one or more subgroups of the match. If there is a single argument, the result is a list of strings; if there are multiple arguments, the result is a tuple of lists with one item per argument; if there are no arguments, the captures of the whole match is returned. Group 0 is the whole match.

def capturesdict(self, /)

capturesdict() –> dict. Return a dictionary containing the captures of all the named subgroups of the match, keyed by the subgroup name.

def detach_string(self, /)

detach_string() Detaches the target string from the match object. The 'string' attribute will become None.

def end(...)

end([group1, …]) –> int or tuple of ints. Return the index of the end of one or more subgroups of the match. If there is a single argument, the result is an index, or -1 if the group did not contribute to the match; if there are multiple arguments, the result is a tuple with one item per argument; if there are no arguments, the index of the end of the whole match is returned. Group 0 is the whole match.

def ends(...)

ends([group1, …]) –> list of ints or tuple of list of ints. Return the indices of the ends of the captures of one or more subgroups of the match. If there is a single argument, the result is a list of indices; if there are multiple arguments, the result is a tuple of lists with one item per argument; if there are no arguments, the indices of the ends of the captures of the whole match is returned. Group 0 is the whole match.

def expand(self, object, /)

expand(template) –> string. Return the string obtained by doing backslash substitution on the template, as done by the sub() method.

def expandf(self, object, /)

expandf(format) –> string. Return the string obtained by using the format, as done by the subf() method.

def group(...)

group([group1, …]) –> string or tuple of strings. Return one or more subgroups of the match. If there is a single argument, the result is a single string, or None if the group did not contribute to the match; if there are multiple arguments, the result is a tuple with one item per argument; if there are no arguments, the whole match is returned. Group 0 is the whole match.

def groupdict(default=None)

groupdict(default=None) –> dict. Return a dictionary containing all the named subgroups of the match, keyed by the subgroup name. The argument is the value to be given for groups that did not participate in the match.

def groups(default=None)

groups(default=None) –> tuple of strings. Return a tuple containing all the subgroups of the match. The argument is the default for groups that did not participate in the match.

def span(...)

span([group1, …]) –> 2-tuple of int or tuple of 2-tuple of ints. Return the span (a 2-tuple of the indices of the start and end) of one or more subgroups of the match. If there is a single argument, the result is a span, or (-1, -1) if the group did not contribute to the match; if there are multiple arguments, the result is a tuple with one item per argument; if there are no arguments, the span of the whole match is returned. Group 0 is the whole match.

def spans(...)

spans([group1, …]) –> list of 2-tuple of ints or tuple of list of 2-tuple of ints. Return the spans (a 2-tuple of the indices of the start and end) of the captures of one or more subgroups of the match. If there is a single argument, the result is a list of spans; if there are multiple arguments, the result is a tuple of lists with one item per argument; if there are no arguments, the spans of the captures of the whole match is returned. Group 0 is the whole match.

def start(...)

start([group1, …]) –> int or tuple of ints. Return the index of the start of one or more subgroups of the match. If there is a single argument, the result is an index, or -1 if the group did not contribute to the match; if there are multiple arguments, the result is a tuple with one item per argument; if there are no arguments, the index of the start of the whole match is returned. Group 0 is the whole match.

def starts(...)

starts([group1, …]) –> list of ints or tuple of list of ints. Return the indices of the starts of the captures of one or more subgroups of the match. If there is a single argument, the result is a list of indices; if there are multiple arguments, the result is a tuple of lists with one item per argument; if there are no arguments, the indices of the starts of the captures of the whole match is returned. Group 0 is the whole match.

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.

class TodoCommentChecker (linter: PyLinter)
Expand source code
class TodoCommentChecker(RulebookFileChecker):
    """See detail: https://hanggrian.github.io/rulebook/rules/#todo-comment"""
    MSG_KEYWORD: str = 'todo-comment-keyword'
    MSG_SEPARATOR: str = 'todo-comment-separator'

    KEYWORD_REGEX: Pattern = regex.compile(r'\b(?i:fixme|todo)(?<!FIXME|TODO)\b')
    SEPARATOR_REGEX: Pattern = regex.compile(r'\b(todo|fixme)\S', IGNORECASE)

    name: str = 'todo-comment'
    msgs: dict[str, MessageDefinitionTuple] = Messages.of(MSG_KEYWORD, MSG_SEPARATOR)

    def process_module(self, node: Module) -> None:
        with node.stream() as stream:
            for i, line in enumerate(stream):
                # obtain comment content
                line_no: int = i + 1
                parts: list[bytes] = line.split(b'#', 1)
                if len(parts) < 2:
                    continue
                comment_content: str = decode(parts[1])

                # checks for violation
                match: Match = self.KEYWORD_REGEX.search(comment_content)
                if match:
                    self.add_message(self.MSG_KEYWORD, line=line_no, args=match.group(0))
                match: Match = self.SEPARATOR_REGEX.search(comment_content)
                if match:
                    self.add_message(self.MSG_SEPARATOR, line=line_no, args=match.group(0)[-1])

See detail: https://hanggrian.github.io/rulebook/rules/#todo-comment

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

The type of the None singleton.

var MSG_KEYWORD : str

The type of the None singleton.

var MSG_SEPARATOR : str

The type of the None singleton.

var SEPARATOR_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.

Methods

def process_module(self, node: astroid.nodes.scoped_nodes.scoped_nodes.Module) ‑> None
Expand source code
def process_module(self, node: Module) -> None:
    with node.stream() as stream:
        for i, line in enumerate(stream):
            # obtain comment content
            line_no: int = i + 1
            parts: list[bytes] = line.split(b'#', 1)
            if len(parts) < 2:
                continue
            comment_content: str = decode(parts[1])

            # checks for violation
            match: Match = self.KEYWORD_REGEX.search(comment_content)
            if match:
                self.add_message(self.MSG_KEYWORD, line=line_no, args=match.group(0))
            match: Match = self.SEPARATOR_REGEX.search(comment_content)
            if match:
                self.add_message(self.MSG_SEPARATOR, line=line_no, args=match.group(0)[-1])

Process a module.

The module's content is accessible via astroid.stream