-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add any-file-contents rule #290
base: main
Are you sure you want to change the base?
feat: add any-file-contents rule #290
Conversation
Signed-off-by: Brend Smits <[email protected]>
Signed-off-by: Brend Smits <[email protected]>
Co-authored-by: Dragos Serban <[email protected]> Signed-off-by: Brend Smits <[email protected]>
Signed-off-by: Brend Smits <[email protected]>
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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