repolinter
repolinter copied to clipboard
feat: add any-file-contents rule
Motivation
The file-contents rule passes if all the files discovered include the content specified via a regular expression. However, for our use case we need to check whether the content is included in at least one of the discovered files.
Proposed Changes
Add any-file-contents rule, which mimics the functionality of the file-contents rule. However, the any-file-contents rule features a globsAny option, instead of globsAll.
To reduce code duplication, the fileContents method (which implements the logic of the file-contents rule) is extended with an optional boolean parameter (called any). If this parameter has the value true, then the rule passes if and only if there is at least one file with content matching the regex. Otherwise, the rule passes if and only if all files include content matching the regex.
Test Plan
- it returns passes if requested file contents exists in exactly one file
- it returns passes if requested file contents exists in two files
- it returns fails if the requested file contents does not exist in any file
- it returns failure if no file exists with failure flag enabled
- it should handle broken symlinks
Original Pull Request on: https://github.com/philips-forks/repolinter/pull/18