Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions scripts/lint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Runs custom linting on Rust code.
"""
Expand Down Expand Up @@ -50,32 +50,27 @@ def lint_lines(filepath, lines_in):
stripped = prev_line.strip()
last_line_was_empty = (
stripped == ""
or stripped.startswith("#")
or stripped.startswith("//")
or stripped.endswith("{")
or stripped.endswith("(")
or stripped.endswith("\\")
or stripped.endswith('r"')
or stripped.endswith("]")
or stripped.startswith(("#", "//"))
or stripped.endswith(("{", "(", "\\", 'r"', "]"))
)
if not last_line_was_empty:
errors.append(
f"{filepath}:{line_nr}: for readability, add newline before `{line.strip()}`"
)
lines_out.append("\n")

if re.search(r"\(mut self.*-> Self", line) and "pub(crate)" not in line:
if prev_line.strip() != "#[inline]":
errors.append(
f"{filepath}:{line_nr}: builder methods should be marked #[inline]"
)
lines_out.append("#[inline]")


if re.search(r"TODO[^(]", line):
if (
re.search(r"\(mut self.*-> Self", line)
and "pub(crate)" not in line
and prev_line.strip() != "#[inline]"
):
errors.append(
f"{filepath}:{line_nr}: write 'TODO(username):' instead"
f"{filepath}:{line_nr}: builder methods should be marked #[inline]"
)
lines_out.append("#[inline]")

if re.search(r"TODO[^(]", line):
errors.append(f"{filepath}:{line_nr}: write 'TODO(username):' instead")

if (
"(target_os" in line
Expand Down Expand Up @@ -136,8 +131,6 @@ def test_lint():
errors, _ = lint_lines("test.py", code.split("\n"))
assert len(errors) > 0, f"expected this to fail:\n{code}"

pass


def main():
test_lint() # Make sure we are bug free before we run!
Expand Down Expand Up @@ -166,7 +159,7 @@ def main():
root_dirpath = os.path.abspath(f"{script_dirpath}/..")
os.chdir(root_dirpath)

exclude = set(["target", "target_ra", "target_wasm"])
exclude = {"target", "target_ra", "target_wasm"}
for root, dirs, files in os.walk(".", topdown=True):
dirs[:] = [d for d in dirs if d not in exclude]
for filename in files:
Expand Down
Loading