""" trainling_spaces - checker for vxnorm This file does not expose an explicite VxChecker object declaration to avoid dependencies handling, you just need to provide: ======================= =============================================== parse_file() Parse the source file ======================= =============================================== """ #--- # Public #--- def parse_file(checker, mfile, _): """ parse the mapped file The file is mapped using mmap() and seeked through offset 0 to avoid too many I/O operations with classical file primitive. @args > checker (VxChecker) - current checker instance for this file > mfile (mmap) - mmap instance of the file, seeked at 0 > pathname (str) - file pathname @return > Nothing """ counter = 0 checker.select_rule('trailing') for line in mfile.getlines(): counter += 1 line_end = len(line) - 1 line_end = line_end - (line[line_end] == '\n') if line_end <= 0: continue for i in range(line_end, 0, -1): if not line[i].isspace(): break if i != line_end: checker.notify( f"{counter}:{i+1}", f"trailing space at ({i+1} != {line_end})", )