Conversation
Signed-off-by: Brend Smits <brend.smits@philips.com>
Signed-off-by: Brend Smits <brend.smits@philips.com>
Co-authored-by: Dragos Serban <dragos.serban@philips.com> Signed-off-by: Brend Smits <brend.smits@philips.com>
Signed-off-by: Brend Smits <brend.smits@philips.com>
| async function fileContents(fs, options, not = false, any = false) { | ||
| // support legacy configuration keys | ||
| const fileList = options.globsAll || options.files | ||
| const fileList = (any ? options.globsAny : options.globsAll) || options.files |
There was a problem hiding this comment.
Let's not change the file-contents function parameter, keep the function always take globsAll and it matches the intention of if all of the files returned by the globs match the supplied string, or if no files are returned..
You can move this part to any-file-contents.js instead.
|
|
||
| | Input | Required | Type | Default | Description | | ||
| | ------------------------ | -------- | ---------- | ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | `globsAny` | **Yes** | `string[]` | | A list of globs to get files for. This rule passes if at least one of the files returned by the globs match the supplied string, or if no files are returned. | |
There was a problem hiding this comment.
Quote:
However, for our use case we need to check whether the content is included in at least one of the discovered files.
I think it doesn't make sense for the rule to pass if no files are returned. It would make sense if the rule fails if no files are returned., since we are looking for at least there is one file has this thing there.
That means the fail-on-non-existent would be success-on-non-existent.
|
We need a similar but different use case :) |
|
@Brend-Smits Ping, do you mind taking care of the feedback of @zhaoyuheng200 ? It would be nice to merge this ! |
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: philips-forks#18