Skip to content

Commit

Permalink
It's working (kind of)
Browse files Browse the repository at this point in the history
  • Loading branch information
huydhn authored Jan 18, 2025
1 parent 112d29f commit 07d7fd6
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions tools/linter/adapters/clickhouse_sql_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,26 @@ def run_command(

def check_file(
binary: str,
file: str,
filename: str,
) -> List[LintMessage]:
with open(filename) as f:
original = f.read()

try:
proc = run_command([binary, '--format','--query', file])
proc = run_command(
[
binary,
"--format",
"--comments",
"--max_line_length",
"80",
"--query",
original,
]
)
except OSError as err:
with open("debug.txt", "a") as f:
print("HERE", file=f)
return [
LintMessage(
path=None,
Expand All @@ -80,20 +95,23 @@ def check_file(
description=(f"Failed due to {err.__class__.__name__}:\n{err}"),
)
]
stdout = str(proc.stdout, "utf-8").strip()

replacement = proc.stdout
if original == replacement:
return []

return [
LintMessage(
path=match["file"],
name=match["code"],
description=match["message"],
line=int(match["line"]),
char=int(match["char"]),
path=filename,
line=None,
char=None,
code=LINTER_CODE,
severity=LintSeverity.ERROR,
original=None,
replacement=replacement,
severity=LintSeverity.WARNING,
name="format",
original=original,
replacement=replacement.decode("utf-8"),
description="See https://clickhouse.com/docs/en/operations/utilities/clickhouse-format.\nRun `lintrunner -a` to apply this patch.",
)
for match in RESULTS_RE.finditer(stdout)
]


Expand All @@ -115,7 +133,6 @@ def main() -> None:

args = parser.parse_args()


if not os.path.exists(args.binary):
err_msg = LintMessage(
path="<none>",
Expand Down Expand Up @@ -154,5 +171,6 @@ def main() -> None:
logging.critical('Failed at "%s".', futures[future])
raise


if __name__ == "__main__":
main()

0 comments on commit 07d7fd6

Please sign in to comment.