Add a way to detect if a file exists.
See original GitHub issueIs your feature request related to a problem? Please describe. We want to make a rule that detects if a file exists in the filesystem, because it would be related to a functionality itself (for example, if we detect a tsconfig.json named file, we can infer that the project uses Typescript)
Describe the solution you’d like One solution would be using the “applies_to_file_regex” field, but if the rule hasn’t patterns to match, it will generate one match for each file that exists with this name o regex name. For example, a rule like this:
{ "name": "Typescript", "id": "TEST0001", "description": "Typescript", "tags":[ "Test.Product.Typescript" ], "severity": "critical", "applies_to_file_regex": [ "tsconfig.json" ] }
will generate one match in the result like this:
{ "ruleId": "TEST0001", "ruleName": "Typescript", "ruleDescription": "Typescript", "tags": [ "Test.Product.Typescript" ], "severity": "Critical", "pattern": "", "confidence": "", "type": "", "language": "json", "fileName": "./tsconfig.json", "sample": "", "excerpt": "", "startLocationLine": 0, "startLocationColumn": 0, "endLocationLine": 0, "endLocationColumn": 0 }
In order to generalize the behaviour, it would work with “applies_to” field too, and will generate one match for each file of the types setted in appplies_to field. For example, a rule without patterns that “applies_to”: “json”, will generate one match for each json file detected.
We are open to other solutions of course.
Thanks a lot! regards.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (6 by maintainers)
Top GitHub Comments
Hello @gfs , We can cover our use case with this solution, we tested it and it works. Thanks for the quick solution!
I tested this and while the regex is valid we had a separate check that was skipping empty files. #413 will change this to allow rules to be checked against empty files.
Here is a sample rule, again using metric, that will match empty files named
application.yml
.