TabWidth = 4 noncompliantFiles = 0 files = nkt.getCXXFiles() for file in files: rw = nkt.FileRewriter(file) for line in rw.lines(): x = 0 skip = 0 for (i, c) in enumerate(line): if c == '\t': x += TabWidth - (x % TabWidth) elif c == ' ': x += 1 else: skip = i break rw.write((" " * int(x)) + line[i:]) if not rw.isIdentical(): nkt.reportChange(file + " is (partially) indented with tabs") rw.commit() noncompliantFiles += 1 print("Scanned %d files. Non-compliant files: %d." % (len(files), noncompliantFiles)) if noncompliantFiles > 0: nkt.failIfReadonly(__file__)
numberNonCompliant = 0 numberFileSkipped = 0 clangFormatCommand = findClangFormat() with tempfile.TemporaryDirectory(dir=nkt.getNetworKitRoot()) as tempDir: files = nkt.getCXXFiles() for file in files: if not subscribedToFormat(file): numberFileSkipped += 1 continue tempFile = os.path.join(tempDir, 'cfOutput') runClangFormat(file, tempFile, clangFormatCommand) if not filecmp.cmp(file, tempFile, shallow=False): numberNonCompliant += 1 nkt.reportChange(file + " is non-compliant") if nkt.doReportDiff(): nkt.computeAndReportDiff(file, tempFile) if not nkt.isReadonly(): os.replace(tempFile, file) print( "Scanned %d files (skipped %d files without subscription). Non-compliant files: %d." % (len(files), numberFileSkipped, numberNonCompliant)) if numberNonCompliant > 0: nkt.failIfReadonly(__file__)
labelStack.append(None) elif sline.startswith("#endif"): label = labelStack.pop() if not label is None: indent = line[:line.find("#endif")] rw.write("%s#endif // %s\n" % (indent, label)) continue rw.write(line) if oldGuard is None: raise Exception("%s no include guard found" % file) if not rw.isIdentical(): nkt.reportChange(file + " changed.") rw.commit() numNoncompliantFiles += 1 except Exception as e: if str(e): print("[PARSE_ERROR] ", e) else: print("[PARSE_ERROR] ", file, "unknown error") numIllegalFiles += 1 print("Scanned %d files. Non-compliant files: %d. Illegal files: %d" % (len(files), numNoncompliantFiles, numIllegalFiles)) if numNoncompliantFiles > 0: