nsiqcppstyle
nsiqcppstyle copied to clipboard
Files with UPPERCASE extensions are not processed
Problem Description
NsiqCppStyle processes C++ files that have an extension found in the list (see nsiqcppstyle_exe.py
for the extension name logic):
["cpp", "h", "c", "hxx", "cxx", "hpp", "cc", "hh", "m", "mm"]
When I attempted to process a file (under Windows) with the external name of "ACCESSDB.CPP", NsiqCppStyle did not process it.
Technical Reason
nsiqcppstyle_exe.py
defines accepted extensions:
extLangMap = {
"Html": set(["htm", "html"]),
"Java": set(["java"]),
"Javascript/ActionScript": set(["js", "as"]),
"JSP/PHP": set(["jsp", "php", "JSP", "PHP"]),
"C/C++": set(["cpp", "h", "c", "hxx", "cxx", "hpp", "cc", "hh", "m", "mm"])
}
...
cExtendstionSet = extLangMap.get("C/C++")
...
# if the target is file, analyze it without condition
if os.path.isfile(targetPath):
`= targetPath[targetPath.rfind('.') + 1:]
if fileExtension in cExtendstionSet:
ProcessFile(ruleManager, targetPath, analyzedFiles)
The search for fileExtension
in cExtendstionSet
is case-sensitive. This is correct for Linux, but for Windows the engine should perform a case-insensitive search.
Suggested fix
If running under Windows, the search should be case-insensitive.
I don't think we should limit to Windows, since case insensitivity is based on filesystem, not OS.
Better solution would be to test if the fs is case insensitive and then modify the name to lowercase. Eg: https://stackoverflow.com/a/7870076
Excellent point that case sensitivity/insensitivity is a file system attribute, not OS. I like Steve Cohen's solution (https://stackoverflow.com/a/36580834/562242), which uses setattr() on the function itself to determine the case sensitivity mode only once. Expect a fix from me in the near future. :-D
PS: Check the comment. If you're doing that, better take the file path into account since this property changes from path to path. The next solution is better: https://stackoverflow.com/a/36612604
And you can use @functools.cache
to speed up if required