Repository navigation
Fix #15081 (usability: try to report misuse of exclude options) #8906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,6 +148,23 @@ CmdLineParser::CmdLineParser(CmdLineLogger &logger, Settings &settings, Suppress | |
| , mSuppressions(suppressions) | ||
| {} | ||
|
|
||
| // The file lister does not walk into an excluded directory, so a pattern that only matches paths in | ||
| // there looks unused. Walk the paths again without excluding anything to find out which of the | ||
| // remaining patterns match something. This is only done when some patterns look unused. | ||
| static std::vector<std::string> unmatchedIgnoredPaths(const PathMatch &matcher, const std::vector<std::string> &pathnames, const std::set<std::string> &extra) | ||
| { | ||
| std::vector<std::string> unmatched = matcher.unmatched(); | ||
| if (unmatched.empty()) | ||
| return unmatched; | ||
|
|
||
| PathMatch recorder(std::move(unmatched), Path::getCurrentPath()); | ||
| recorder.setRecordOnly(true); | ||
| std::list<FileWithDetails> files; | ||
| for (const std::string &pathname : pathnames) | ||
| (void)FileLister::recursiveAddFiles(files, Path::toNativeSeparators(pathname), extra, recorder); | ||
| return recorder.unmatched(); | ||
| } | ||
|
|
||
| bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[]) | ||
| { | ||
| const Result result = parseFromArgs(argc, argv); | ||
|
|
@@ -247,7 +264,7 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[]) | |
| std::list<FileWithDetails> filesResolved; | ||
| // Execute recursiveAddFiles() to each given file parameter | ||
| // TODO: verbose log which files were ignored? | ||
| const PathMatch matcher(ignored, Path::getCurrentPath()); | ||
| PathMatch matcher(ignored, Path::getCurrentPath()); | ||
| for (const std::string &pathname : pathnamesRef) { | ||
| const std::string err = FileLister::recursiveAddFiles(filesResolved, Path::toNativeSeparators(pathname), mSettings.library.markupExtensions(), matcher, mSettings.debugignore); | ||
| if (!err.empty()) { | ||
|
|
@@ -264,6 +281,12 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[]) | |
| return false; | ||
| } | ||
|
|
||
| const std::vector<std::string> unmatched = unmatchedIgnoredPaths(matcher, pathnamesRef, mSettings.library.markupExtensions()); | ||
| if (!unmatched.empty()) { | ||
| mLogger.printError("unused ignore/exclude path '" + unmatched.front() + "'. To hide warnings in certain files use suppressions instead."); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A couple of points about making this a hard error:
|
||
| return false; | ||
| } | ||
|
|
||
| std::list<FileWithDetails> files; | ||
| if (!mSettings.fileFilters.empty()) { | ||
| files = filterFiles(mSettings.fileFilters, filesResolved); | ||
|
|
@@ -1723,12 +1746,16 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a | |
| mPathNames = project.guiProject.pathNames; | ||
|
|
||
| if (!project.fileSettings.empty()) { | ||
| project.ignorePaths(mIgnoredPaths, mSettings.debugignore); | ||
| const auto& unmatched = project.ignorePaths(mIgnoredPaths, mSettings.debugignore); | ||
| if (project.fileSettings.empty()) { | ||
| mLogger.printError("no C or C++ source files found."); | ||
| mLogger.printMessage("all paths were ignored"); // TODO: log this differently? | ||
| return Result::Fail; | ||
| } | ||
| if (!unmatched.empty()) { | ||
| mLogger.printError("unused ignore/exclude path '" + unmatched.front() + "'. To hide warnings in certain files use suppressions instead."); | ||
| return Result::Fail; | ||
| } | ||
| mFileSettings = project.fileSettings; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,8 +90,9 @@ void FileList::addPathList(const QStringList &paths) | |
| } | ||
| } | ||
|
|
||
| QStringList FileList::getFileList() const | ||
| QStringList FileList::getFileList() | ||
| { | ||
| mUnmatchedExcludes.clear(); | ||
| if (mExcludedPaths.empty()) { | ||
| QStringList names; | ||
| for (const QFileInfo& item : mFileList) { | ||
|
|
@@ -103,6 +104,11 @@ QStringList FileList::getFileList() const | |
| return applyExcludeList(); | ||
| } | ||
|
|
||
| const QStringList& FileList::getUnmatchedExcludes() & | ||
| { | ||
| return mUnmatchedExcludes; | ||
| } | ||
|
|
||
| void FileList::addExcludeList(const QStringList &paths) | ||
| { | ||
| mExcludedPaths = paths; | ||
|
|
@@ -117,9 +123,9 @@ static std::vector<std::string> toStdStringList(const QStringList &stringList) | |
| return ret; | ||
| } | ||
|
|
||
| QStringList FileList::applyExcludeList() const | ||
| QStringList FileList::applyExcludeList() | ||
| { | ||
| const PathMatch pathMatch(toStdStringList(mExcludedPaths), QDir::currentPath().toStdString()); | ||
| PathMatch pathMatch(toStdStringList(mExcludedPaths), QDir::currentPath().toStdString()); | ||
|
|
||
| QStringList paths; | ||
| for (const QFileInfo& item : mFileList) { | ||
|
|
@@ -129,5 +135,10 @@ QStringList FileList::applyExcludeList() const | |
| if (!pathMatch.match(canonical.toStdString())) | ||
| paths << canonical; | ||
| } | ||
|
|
||
| for (const std::string& excludePath: pathMatch.unmatched()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI review
Reproduced with Possible fix: also match the directories that |
||
| mUnmatchedExcludes << QString::fromStdString(excludePath); | ||
| } | ||
|
|
||
| return paths; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.