# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import json import os import re import signal import subprocess from pathlib import Path
if config.get("exclude"):
args.append(f"--extend-exclude={','.join(config['exclude'])}")
if lintargs.get("extra_args"):
args.extend(lintargs["extra_args"])
warning_rules = set(config.get("warning-rules", [])) if lintargs.get("fix"): # Do a first pass with --fix-only as the json format doesn't return the # number of fixed issues.
fix_args = args + ["--fix-only"] ifnot lintargs.get("warning"): # Don't fix warnings to limit unrelated changes sneaking into patches. # except when --fix -W is passed
fix_args.append(f"--extend-ignore={','.join(warning_rules)}")
# Merge pyproject.toml excludes with config excludes. # This is needed because ruff format's --exclude replaces rather than extends # the pyproject.toml excludes (unlike ruff check which has --extend-exclude). if config.get("exclude"):
exclude_patterns.extend(config["exclude"])
for exclude in exclude_patterns:
args.append(f"--exclude={exclude}")
if lintargs.get("fix"): # Do a first pass to fix, as JSON output doesn't include fix counts
log.debug(f"Running --fix: {args}")
output, returncode = run_process(args, log) if returncode == 2:
log.error(
f"ruff terminated abnormally (invalid config, CLI options, or internal error): {output}"
) return {"results": [], "fixed": 0}
match = re.search(r"(\d+) files? reformatted", output) if match:
fixed = int(match.group(1))
args += ["--check", "--output-format=json"]
log.debug(f"Running with args: {args}")
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.