Skip to content

Commit

Permalink
Make findlongcomments return non-zero if long comments were found
Browse files Browse the repository at this point in the history
  • Loading branch information
martinburchell committed Aug 27, 2024
1 parent 916a167 commit c6f4b5d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tablet_qt/tools/clang_format_camcops.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ def print_long_comments(
ignore_urls: bool = False,
bare: bool = False,
debugtokens: bool = False,
) -> None:
) -> int:
"""
Print any line in the file that is longer than maxlinelength and contains,
or is part of, a C++ comment.
or is part of, a C++ comment. Returns the number of long lines.
Args:
filename:
Expand All @@ -232,6 +232,9 @@ def print_long_comments(
log.debug(
f"Searching for comment lines >{maxlinelength} characters: {filename}"
)

num_long_lines = 0

lines_seen = set() # type: Set[int]
with open(filename) as f:
contents = f.read()
Expand All @@ -248,6 +251,9 @@ def print_long_comments(
if any(u in linetext for u in URL_INDICATORS):
continue
report_line(filename, linenum, linetext, bare=bare)
num_long_lines += 1

return num_long_lines


# =============================================================================
Expand Down Expand Up @@ -415,13 +421,15 @@ def clang_format_camcops_source() -> None:
elif command == Command.DIFF:
log.info(f"Diff: {filename}")
elif command == Command.FINDLONGCOMMENTS:
print_long_comments(
num_long_lines = print_long_comments(
filename,
maxlinelength=args.maxlinelength,
ignore_urls=args.ignore_urls,
bare=args.bare,
debugtokens=args.debugtokens,
)
if num_long_lines > 0:
success = False
continue
elif command == Command.LIST:
print(filename)
Expand Down

0 comments on commit c6f4b5d

Please sign in to comment.