lint.py: use pathlib and support Windows

This commit is contained in:
linsui 2021-06-09 15:46:52 +08:00
parent 8b17fbf703
commit 6bafb036ee
3 changed files with 334 additions and 202 deletions

View file

@ -3983,9 +3983,7 @@ YAML_LINT_CONFIG = {'extends': 'default',
def run_yamllint(path, indent=0):
# TODO: Remove this
path = str(path)
path = Path(path)
try:
import yamllint.config
import yamllint.linter
@ -3993,10 +3991,10 @@ def run_yamllint(path, indent=0):
return ''
result = []
with open(path, 'r', encoding='utf-8') as f:
with path.open('r', encoding='utf-8') as f:
problems = yamllint.linter.run(f, yamllint.config.YamlLintConfig(json.dumps(YAML_LINT_CONFIG)))
for problem in problems:
result.append(' ' * indent + path + ':' + str(problem.line) + ': ' + problem.message)
result.append(' ' * indent + str(path) + ':' + str(problem.line) + ': ' + problem.message)
return '\n'.join(result)