Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Latest commit

 

History

History
97 lines (81 loc) · 3.78 KB

File metadata and controls

97 lines (81 loc) · 3.78 KB

Notes

Snippets

Minimal boilerplate for the Plugin class:

import ast
import importlib.metadata
from typing import Any, Generator, Tuple, Type


class Plugin:
    name = __name__
    version = importlib.metadata.version(__name__)

    def __init__(self, tree: ast.AST) -> None:
        # The AST that represents a single file
        self._tree = tree

    def run(self) -> Generator[Tuple[int, int, str, Type[Any]], None, None]:
        # Tuple[line number, character offset, message]
        # Type[Any] is not being used (use `type(self)`)
        pass

Syntactic sugar for attr.ib(default=attr.Factory(f)):

@attr.s
class C(object):
    x = attr.ib(factory=list)
    # instead of
    # x = attr.ib(default=attr.Factory(list))

from X import ... is not allowed. X must be imported as a module. (from Marc Gibbons' flake8-datetime-import plugin):

ERRORS = {
    "DTI100": (
        "`from datetime import ...` is not allowed. `datetime` must be "
        "imported as a module."
    ),
}


class Visitor(ast.NodeVisitor):
    def __init__(self):
        self.problems = []

    def visit_ImportFrom(self, node):
        if node.module == "datetime":
            self.problems.append((node.lineno, node.col_offset, "DTI100"))
        if node.module == "time":
            self.problems.append((node.lineno, node.col_offset, "DTI200"))

        self.generic_visit(node)