Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
lint: add primitive const checker
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Sep 7, 2024
1 parent 5009823 commit d23bb2a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tools/libtrx/linting.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
import re
import json
from collections.abc import Callable, Iterable
from dataclasses import dataclass
Expand Down Expand Up @@ -45,10 +46,21 @@ def lint_trailing_whitespace(path: Path) -> Iterable[LintWarning]:
yield LintWarning(path, "trailing whitespace", line=i)


def lint_const_primitives(path: Path) -> Iterable[LintWarning]:
if path.suffix != ".h":
return
for i, line in enumerate(path.open("r"), 1):
if re.search(r"const (int[a-z0-9_]*|bool)\b\s*[a-z]", line):
yield LintWarning(path, "useless const", line=i)
if re.search(r"\*\s*const", line):
yield LintWarning(path, "useless const", line=i)


ALL_LINTERS: list[Callable[[], Iterable[LintWarning]]] = [
lint_json_validity,
lint_newlines,
lint_trailing_whitespace,
lint_const_primitives,
]


Expand Down

0 comments on commit d23bb2a

Please sign in to comment.