CLI: Warn if user tries to exclude header files.

Filename exclusion (with -i) works only for the source files.
Print a warning if user tries to exclude header file. The warning
instructs user to use --suppress for ignoring warnings from the
header files.
This commit is contained in:
Kimmo Varis 2011-08-06 12:29:51 +03:00
parent b976445be7
commit 371838b9cb
4 changed files with 40 additions and 4 deletions

View File

@ -99,6 +99,27 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
if (!filenames.empty())
{
// Remove header files from the list of ignored files.
// Also output a warning for the user.
// TODO: Remove all unknown files? (use FileLister::acceptFile())
bool warned = false;
std::vector<std::string> ignored = parser.GetIgnoredPaths();
std::vector<std::string>::iterator iterIgnored = ignored.begin();
for (int i = (int)ignored.size() - 1; i >= 0; i--)
{
const std::string extension = Path::getFilenameExtension(ignored[i]);
if (extension == ".h" || extension == ".hpp")
{
ignored.erase(iterIgnored + i);
if (!warned)
{
std::cout << "cppcheck: filename exclusion does not apply to header (.h and .hpp) files." << std::endl;
std::cout << "cppcheck: Please use --suppress for ignoring results from the header files." << std::endl;
warned = true; // Warn only once
}
}
}
PathMatch matcher(parser.GetIgnoredPaths());
std::vector<std::string>::iterator iterBegin = filenames.begin();
for (int i = (int)filenames.size() - 1; i >= 0; i--)

View File

@ -33,11 +33,9 @@ static int tolowerWrapper(int c)
bool FileLister::acceptFile(const std::string &filename)
{
std::string::size_type dotLocation = filename.find_last_of('.');
if (dotLocation == std::string::npos)
std::string extension = Path::getFilenameExtension(filename);
if (extension == "")
return false;
std::string extension = filename.substr(dotLocation);
std::transform(extension.begin(), extension.end(), extension.begin(), tolowerWrapper);
if (extension == ".cpp" ||

View File

@ -127,3 +127,13 @@ std::string Path::removeQuotationMarks(const std::string &path)
editPath.erase(std::remove(editPath.begin(), editPath.end(), '\"'), editPath.end());
return editPath;
}
std::string Path::getFilenameExtension(const std::string &path)
{
const std::string::size_type dotLocation = path.find_last_of('.');
if (dotLocation == std::string::npos)
return "";
const std::string extension = path.substr(dotLocation);
return extension;
}

View File

@ -70,6 +70,13 @@ public:
* @return Cleaned path without quotation marks.
*/
static std::string removeQuotationMarks(const std::string &path);
/**
* @brief Get an extension of the filename.
* @param path Path containing filename.
* @return Filename extension (containing the dot, e.g. ".h").
*/
static std::string getFilenameExtension(const std::string &path);
};
/// @}