1 Star 0 Fork 0

systechn/tinc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
lint.py 1.91 KB
一键复制 编辑 原始数据 按行查看 历史
Kirill Isakov 提交于 2022-05-29 11:24 . Add Markdown reformat to lint.py
#!/usr/bin/env python3
"""Run linters on project code. Add --fix to autofix files with linters that support it."""
import sys
import subprocess as subp
from glob import glob
from os import path, environ, chdir
DRY = "--fix" not in sys.argv or environ.get("CI")
HEADER = "#" * 24
if DRY:
MSG = """
You're running linters in non-destructive readonly mode.
Some of them support automated fixes (like reformatting code).
To apply them, run `lint.py --fix` or `ninja -C build reformat`.
"""
print(MSG, file=sys.stderr)
source_root = path.dirname(path.realpath(__file__))
source_root = environ.get("MESON_SOURCE_ROOT", source_root)
chdir(source_root)
# It's best not to use globs that cover everything in the project — if integration
# tests are run with a large --repeat value, test working directory can reach
# enormous sizes, and linters either get very slow, or start crashing.
linters = (
[
"astyle",
"--recursive",
"--options=.astylerc",
"--dry-run" if DRY else "--formatted",
"./*.c",
"./*.h",
],
["shfmt", "-d" if DRY else "-w", "-i", "2", "-s", "."],
["black", "--check" if DRY else ".", "."],
["pylint", "."],
["mypy", "--exclude", "build", "."],
["shellcheck", "-x", *glob(".ci/**/*.sh", recursive=True)],
["markflow", "--line-length", "80", "--check" if DRY else "--verbose", ".", ".ci"],
)
failed: bool = False
for cmd in linters:
exe = cmd[0]
print(f"{HEADER} Running linter '{exe}' {HEADER}")
try:
res = subp.run(
cmd,
check=False,
stdout=subp.PIPE,
encoding="utf-8",
)
failed = (
failed
or bool(res.returncode)
or (exe == "astyle" and "Formatted " in res.stdout)
)
print(res.stdout)
except FileNotFoundError as e:
print(f"Warning: linter {exe} is missing", file=sys.stderr)
sys.exit(int(failed))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/systechn/tinc.git
git@gitee.com:systechn/tinc.git
systechn
tinc
tinc
1.1

搜索帮助

0d507c66 1850385 C8b1a773 1850385