repolinter icon indicating copy to clipboard operation
repolinter copied to clipboard

feat: add any-file-contents rule

Open Brend-Smits opened this issue 1 year ago • 1 comments

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

Brend-Smits avatar Mar 31 '23 09:03 Brend-Smits