if not otherfile:
reporter.code_issue(includedfile,
"includes non-local file as {0}".format(includedfile))
- # TODO: Reinstantiate a check once there is clarity on what we want
- # to enforce.
- #elif fileobj.is_installed() and not includedfile.is_relative():
- # reporter.code_issue(includedfile,
- # "installed header includes {0} using non-relative path"
- # .format(includedfile))
if not otherfile:
return
if fileobj.is_installed() and not otherfile.is_installed():
check_file(fileobj, reporter)
for includedfile in fileobj.get_includes():
check_include(fileobj, includedfile, reporter)
- if fileobj.should_includes_be_sorted() \
- and not includesorter.check_sorted(fileobj):
- reporter.code_issue(fileobj, "include style/order is not consistent")
+ if fileobj.should_includes_be_sorted():
+ is_sorted, details = includesorter.check_sorted(fileobj)
+ if not is_sorted:
+ details.append("You can use includesorter.py to do the sorting automatically; see docs/dev-manual/gmxtree.rst")
+ reporter.code_issue(fileobj,
+ "include style/order is not consistent; see docs/dev-manual/includestyle.rst", details)
for classobj in tree.get_classes():
check_class(classobj, reporter)
"""Check that includes within a file are sorted."""
# TODO: Make the checking work without full contents of the file
lines = fileobj.get_contents()
- self._changed = False
+ is_sorted = True
+ details = None
for block in fileobj.get_include_blocks():
- self._sort_include_block(block, lines)
- return not self._changed
+ self._changed = False
+ sorted_lines = self._sort_include_block(block, lines)
+ if self._changed:
+ is_sorted = False
+ # TODO: Do a proper diff to show the actual changes.
+ if details is None:
+ details = ["Correct order/style is:"]
+ else:
+ details.append(" ...")
+ details.extend([" " + x.rstrip() for x in sorted_lines])
+ return (is_sorted, details)
def main():
"""Run the include sorter script."""