todogroup / repolinter

Repolinter, The Open Source Repository Linter
https://todogroup.github.io/repolinter/
Apache License 2.0
421 stars 72 forks source link

feat: add any-file-contents rule #290

Open Brend-Smits opened 1 year ago

Brend-Smits commented 1 year ago

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

Original Pull Request on: https://github.com/philips-forks/repolinter/pull/18

hinricht commented 8 months ago

We need a similar but different use case :) We want to ensure that all files in a glob don't include a certain content. Right now I didn't find a way to accomplish this.

hinricht commented 1 month ago

@Brend-Smits Ping, do you mind taking care of the feedback of @zhaoyuheng200 ? It would be nice to merge this !