TLDR; I'm looking for ideas on how to flag code containing file names/paths that have inconsistent capitalisation with the actual file/directory.
I am migrating a significant code base written in an interpreted language from a Windows/OSX dev environment and a Windows prod environment to Linux prod and dev (via vagrant) environment.
The problem is that I've discovered over the years various developers have been sloppy in ensuring references to files have consistent capitalisation with the actual file.
This is not just an issue for including other code files, but also in referencing template names and auto-loading classes from their name. For example someone might render a template by referencing
mytemplate but the actual file is called
myTemplate.html, or they reference
MyClass but the file is called
Previously the developers have failed to notice these instances because they're using case-insensitive file systems that hide the issue. Now that the production environment is case-sensitive a heap usually obscure bugs have arisen caused by case inconsistencies.
- What is the best way to identify possible instances of this via static analysis of the code.
I've realised that dealing with this reactively (ie. in response to bug reports) is insufficient - I need to find all the instances where this is possibly an issue and manually review it, but finding every instance is painstaking. I was hoping that there might be an existing static analysis tool for this kind of issue but I couldn't find one.
I was thinking of maybe putting something together that would list all file and directory names, then search the code for any references to these but with a different case. This wouldn't be particularly intelligent but it would probably work (although there would probably be a significant number of false positives from variables names, etc. to work through).
- How do I prevent this from happening in future
While developers are now using a Linux dev environment, vagrant shared folders are case-insensitive (on Windows systems at least). In some instances I've been able to add "fast-fail" conditions (so it explicitly checks the case and fails if they don't match, even if the file operation is successful), but I can't do that where file paths are passed directly into a native function for example. Unit testing on a prod environment is one solution, but some of these issues occur within templates (eg.
someFile.js) which is hard to unit test.