third_party.pylibs.pylint.src/examples/custom_raw.py

41 lines
1.1 KiB
Python
Raw Normal View History

from astroid import nodes
2006-04-26 10:48:09 +00:00
from pylint.checkers import BaseChecker
from pylint.interfaces import IRawChecker
2006-04-26 10:48:09 +00:00
class MyRawChecker(BaseChecker):
"""check for line continuations with '\' instead of using triple
quoted string or parenthesis
"""
2006-04-26 10:48:09 +00:00
__implements__ = IRawChecker
name = "custom_raw"
msgs = {
"W9901": (
"use \\ for line continuation",
"backslash-line-continuation",
(
"Used when a \\ is used for a line continuation instead"
" of using triple quoted string or parenthesis."
),
)
}
2006-04-26 10:48:09 +00:00
options = ()
def process_module(self, node: nodes.Module) -> None:
2006-04-26 10:48:09 +00:00
"""process a module
the module's content is accessible via node.stream() function
2006-04-26 10:48:09 +00:00
"""
with node.stream() as stream:
for (lineno, line) in enumerate(stream):
if line.rstrip().endswith("\\"):
self.add_message("backslash-line-continuation", line=lineno)
2006-04-26 10:48:09 +00:00
2006-04-26 10:48:09 +00:00
def register(linter):
"""required method to auto register this checker"""
linter.register_checker(MyRawChecker(linter))