diff --git a/tools/chapel-py/chplcheck.py b/tools/chapel-py/chplcheck.py index 44b5b9bb91de..b8f6fbfa1779 100644 --- a/tools/chapel-py/chplcheck.py +++ b/tools/chapel-py/chplcheck.py @@ -20,6 +20,7 @@ import chapel import chapel.core +import chapel.replace import re import sys import argparse @@ -134,6 +135,20 @@ def check_reserved_prefix(node): def check_redundant_block(node): return node.block_style() != "unnecessary" +def check_misleading_indentation(node): + prev = None + for child in node: + yield from check_misleading_indentation(child) + + if prev is not None: + if child.location().start()[1] == prev.location().start()[1]: + yield child + + if isinstance(child, chapel.core.Loop) and child.block_style() == "implicit": + grandchildren = list(child) + if len(grandchildren) > 0: + prev = list(grandchildren[-1])[0] + Rules = [ ("CamelCaseVariables", chapel.core.VarLikeDecl, check_camel_case_var), ("CamelCaseRecords", chapel.core.Record, check_camel_case), @@ -162,5 +177,8 @@ def main(): for group in consecutive_decls(ast): report_violation(group[1], "ConsecutiveDecls") + for node in check_misleading_indentation(ast): + report_violation(node, "MisleadingIndentation") + if __name__ == "__main__": main()