diff options
author | Marc Mutz <[email protected]> | 2025-06-04 07:46:11 +0200 |
---|---|---|
committer | Marc Mutz <[email protected]> | 2025-06-04 15:30:52 +0000 |
commit | 8b194e24b8ae8f8bcaf15bad1388a70cdcae48ac (patch) | |
tree | 195fa5b9001654ffaa78bedd0f552805cdcc69f0 | |
parent | bc3407b440b087db90fc84c817d5c6d1c920c676 (diff) |
There's no reason why SIGNAL()/SLOT() usage should be limited to .cpp
files, and, indeed, running normalize on qt5.git with this change
applied produces additional hits in headers, Obj-C++ and qdoc files.
Also add some other file types that may contain SIGNAL/SLOT macros.
Change-Id: I65082bcf54e977e55f8cb1f95d7a84ede087c9d2
Reviewed-by: Ivan Solovev <[email protected]>
-rw-r--r-- | util/normalize/main.cpp | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/util/normalize/main.cpp b/util/normalize/main.cpp index 4ff96ff..ea872b1 100644 --- a/util/normalize/main.cpp +++ b/util/normalize/main.cpp @@ -114,11 +114,46 @@ void check(const QString &fileName) void traverse(const QString &path) { + auto needsChecking = [] (QStringView path) { + // list of file extensions that + constexpr char extensions[][5] = { + // C++ impl files: + "C", // will also match .c (because we're matching case-insensitively, but ¯\_(ツ)_/¯ + "cpp", + "cxx", + "c++", + // header files: + "h", + "hpp", + "hxx", + // Obj-C++ impl: + "mm", + // Parser generators: + "g", + // documentation may also include SIGNAL/SLOT macros: + "qdoc", + }; + + // treat .in files like the underlying file + if (path.endsWith(QLatin1StringView{".in"}, Qt::CaseInsensitive)) + path = path.chopped(3); + + for (const char *extension : extensions) { + const QLatin1StringView ext{extension}; + if (path.endsWith(ext, Qt::CaseInsensitive) && + path.chopped(ext.size()).endsWith(u'.')) + { + return true; + } + } + return false; + }; + QDirIterator dirIterator(path, QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files | QDir::NoSymLinks); while (dirIterator.hasNext()) { QString filePath = dirIterator.next(); - if (filePath.endsWith(".cpp")) + if (needsChecking(filePath)) check(filePath); else if (QFileInfo(filePath).isDir()) traverse(filePath); // recurse @@ -141,7 +176,7 @@ int main(int argc, char *argv[]) parser.addOption(modifyOption); parser.addPositionalArgument(QStringLiteral("path"), - QStringLiteral("can be a single file or a directory (in which case, look for *.cpp recursively)")); + QStringLiteral("can be a single file or a directory (in which case, look for file types that may contain SIGNALs and SLOTs recursively)")); parser.process(app); |