Feat: ignore directives
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import logging
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
|
||||
import click
|
||||
import restructuredtext_lint
|
||||
from docutils.parsers.rst.directives import register_directive
|
||||
from git import Repo
|
||||
|
||||
formatter = logging.Formatter("%(name)s :: %(levelname)s :: %(message)s")
|
||||
@@ -39,12 +40,20 @@ def select_by_extension(files, ext="rst"):
|
||||
# Rst linter
|
||||
|
||||
|
||||
def rst_lint(filename):
|
||||
def rst_lint(filename, ignore_directives=["big_button"]):
|
||||
with open(filename, "r") as f:
|
||||
errors = restructuredtext_lint.lint(f.read())
|
||||
filtered_errors = []
|
||||
for e in errors:
|
||||
logger.warning(f"{filename} \n{e.full_message}\n")
|
||||
return errors
|
||||
if "directive" in e.message and any(
|
||||
[i in e.message for i in ignore_directives]
|
||||
):
|
||||
pass
|
||||
else:
|
||||
logger.warning(f"{filename} \n{e.full_message}\n")
|
||||
filtered_errors.append(e)
|
||||
|
||||
return filtered_errors
|
||||
|
||||
|
||||
# Rst parameters normalize
|
||||
@@ -115,7 +124,16 @@ NORMALIZERS_NEW = {
|
||||
}
|
||||
|
||||
|
||||
def main(argv: list[str] = None) -> int:
|
||||
@click.command()
|
||||
@click.argument("commited_files", nargs=-1)
|
||||
@click.option(
|
||||
"--ignore_directive",
|
||||
multiple=True,
|
||||
default=[],
|
||||
help="List of ignored directives for restructuredtext_lint",
|
||||
)
|
||||
def main(commited_files: list, ignore_directive: list) -> int:
|
||||
|
||||
r = Repo()
|
||||
diff = get_commited_files(r)
|
||||
|
||||
@@ -124,11 +142,11 @@ def main(argv: list[str] = None) -> int:
|
||||
|
||||
# New files
|
||||
for f in select_by_extension(diff["A"], "rst"):
|
||||
errors += rst_lint(f)
|
||||
errors += rst_lint(f, ignore_directives=ignore_directive)
|
||||
modified += normalize_file(f, NORMALIZERS_NEW)
|
||||
# Modified files
|
||||
for f in select_by_extension(diff["M"], "rst"):
|
||||
errors += rst_lint(f)
|
||||
errors += rst_lint(f, ignore_directives=ignore_directive)
|
||||
modified += normalize_file(f, NORMALIZERS_MODIFIED)
|
||||
|
||||
return int(len(errors) > 0)
|
||||
|
||||
Reference in New Issue
Block a user