Static analysis for finding capitalisation / case inconsistencies in file names

TLDR; I’m looking for ideas on how to flag code containing file names/paths that have inconsistent capitalisation with the actual file/directory.

Situation

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 Myclass.

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.

Questions

  1. 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).

  1. 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 vs. someFile.js) which is hard to unit test.

This is a task that defies static analysis. For example the not-unlikely code

def open_me(dir_path, filename, extension):
    return open(dir_path + filename + extension)

would be a tough one to catch. When faced with an insoluble problem, use heuristics. I’d go both directions with this.

  1. Assume that every filename in the tree is a candidate for being referenced in every file. I’d also add to the candidates someFile for every someFile.js. Then search the entire codebase for instances of the candidates and report them as possible defects which must be looked at. I recommend putting eyeballs in the loop because you don’t want to catch comments and string literals which may not be filenames. Tedious? Sure.
  2. The second direction is to look at every open() or similar function for filename-like things. This is tedious too.

There is only one way to prevent it happening in the future:

  1. Set a policy and enforce it through code reviews. You went to a new platform which has additional portability constraints. Because of the open_me gotcha above, additional discipline is needed by the development team.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật