Skip to content

Conversation

@drgs
Copy link

@drgs drgs commented Aug 16, 2022

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

@drgs drgs added the enhancement New feature or request label Aug 16, 2022
@drgs drgs requested a review from Brend-Smits August 16, 2022 13:59
@drgs drgs self-assigned this Aug 16, 2022
Copy link
Member

@Brend-Smits Brend-Smits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, let's see if we can create some more awesome rulesets with this addition! Nice!

@Brend-Smits
Copy link
Member

@drgs drgs force-pushed the feature/add-globs-any-to-file-contents-rule branch 5 times, most recently from 9d4febf to b9bbf30 Compare August 29, 2022 11:42
@drgs drgs force-pushed the feature/add-globs-any-to-file-contents-rule branch from b9bbf30 to cf9ba50 Compare August 29, 2022 11:43
@Brend-Smits Brend-Smits merged commit 22c89e3 into master Aug 29, 2022
@Brend-Smits Brend-Smits deleted the feature/add-globs-any-to-file-contents-rule branch August 29, 2022 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants