mirror of https://github.com/astral-sh/ruff
Restructuring parsing
This commit is contained in:
parent
250b226f16
commit
89f9803f4a
|
|
@ -101,7 +101,7 @@ def markdown_check_result(result: Result) -> str:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
diff_lines.append(
|
diff_lines.append(
|
||||||
add_permalink_to_diagnostic_line(comparison.repo, line.construct_line())
|
add_permalink_to_diagnostic_line(comparison.repo, line.to_string())
|
||||||
)
|
)
|
||||||
|
|
||||||
displayed_per_rule[rule_code] += 1
|
displayed_per_rule[rule_code] += 1
|
||||||
|
|
@ -273,7 +273,7 @@ class DiagnosticLine:
|
||||||
location: str
|
location: str
|
||||||
message: str
|
message: str
|
||||||
|
|
||||||
def construct_line(self) -> str:
|
def to_string(self) -> str:
|
||||||
"""
|
"""
|
||||||
Construct the line from the components
|
Construct the line from the components
|
||||||
"""
|
"""
|
||||||
|
|
@ -299,29 +299,29 @@ class DiagnosticLine:
|
||||||
**{**dataclasses.asdict(self), "is_added": None, "is_removed": None}
|
**{**dataclasses.asdict(self), "is_added": None, "is_removed": None}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def try_from_string(cls: type[Self], line: str) -> Self | None:
|
||||||
|
"""
|
||||||
|
Parse the rule code from a diagnostic line string
|
||||||
|
"""
|
||||||
|
match = CHECK_DIAGNOSTIC_LINE_RE.match(line)
|
||||||
|
|
||||||
def parse_diagnostic_line(line: str) -> DiagnosticLine | None:
|
if match is None:
|
||||||
"""
|
# Handle case where there are no regex match e.g.
|
||||||
Parse the rule code from a diagnostic line
|
# + "?application=AIRFLOW&authenticator=TEST_AUTH&role=TEST_ROLE&warehouse=TEST_WAREHOUSE" # noqa: E501, ERA001
|
||||||
"""
|
# Which was found in local testing
|
||||||
match = CHECK_DIAGNOSTIC_LINE_RE.match(line)
|
return None
|
||||||
|
|
||||||
if match is None:
|
match_items = match.groupdict()
|
||||||
# Handle case where there are no regex match e.g.
|
|
||||||
# + "?application=AIRFLOW&authenticator=TEST_AUTH&role=TEST_ROLE&warehouse=TEST_WAREHOUSE" # noqa: E501, ERA001
|
|
||||||
# Which was found in local testing
|
|
||||||
return None
|
|
||||||
|
|
||||||
match_items = match.groupdict()
|
return DiagnosticLine(
|
||||||
|
location=match_items["location"],
|
||||||
return DiagnosticLine(
|
is_removed=match_items.get("diff") == "-",
|
||||||
location=match_items["location"],
|
is_added=match_items.get("diff") == "+",
|
||||||
is_removed=match_items.get("diff") == "-",
|
fix_available=match_items.get("fixable") is not None,
|
||||||
is_added=match_items.get("diff") == "+",
|
rule_code=match_items["code"],
|
||||||
fix_available=match_items.get("fixable") is not None,
|
message=match_items["message"],
|
||||||
rule_code=match_items["code"],
|
)
|
||||||
message=match_items["message"],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class CheckDiff(Diff):
|
class CheckDiff(Diff):
|
||||||
|
|
@ -354,7 +354,7 @@ class CheckDiff(Diff):
|
||||||
parsed_lines: list[DiagnosticLine] = list(
|
parsed_lines: list[DiagnosticLine] = list(
|
||||||
filter(
|
filter(
|
||||||
None,
|
None,
|
||||||
(parse_diagnostic_line(line) for line in sorted_lines),
|
(DiagnosticLine.try_from_string(line) for line in sorted_lines),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -371,7 +371,7 @@ class CheckDiff(Diff):
|
||||||
if line.fix_available
|
if line.fix_available
|
||||||
else line.with_fix_available()
|
else line.with_fix_available()
|
||||||
)
|
)
|
||||||
if toggled.without_diff().construct_line() in other_set:
|
if toggled.without_diff().to_string() in other_set:
|
||||||
fix_only.add(line)
|
fix_only.add(line)
|
||||||
|
|
||||||
return CheckDiff(
|
return CheckDiff(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue