Skip to content
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

Regex rules with exists:0 fails #243

Open
ghostrider-05 opened this issue Jul 29, 2024 · 8 comments
Open

Regex rules with exists:0 fails #243

ghostrider-05 opened this issue Jul 29, 2024 · 8 comments
Assignees
Labels

Comments

@ghostrider-05
Copy link

I want to add a rule that does not allow files to be named image\d+ and according to the documentation exists:0 can be used as:

ls:
   .png: regex:image\d+ | exists:0

However, when running with this configuration all the files that are named image\d+ are passing and files not named image\d+ are failing with:

custom_image.png failed for `.png` rules: regex:image\d+

I thought exists:0 would be applied as a seperate rule, so I removed the | and tried again with the following configuration:

ls:
   .png: regex:image\d+ exists:0

With both images failing the test:

custom_image.png failed for `.png` rules: regex:image\d+ exists:0
image214.png failed for `.png` rules: regex:image\d+ exists:0

Is this intended behaviour? In the documentation I don't see an example with exists:N and regex rules so I thought it should be possible.

Version: 2.3.0-beta.1 on NPM

@loeffel-io
Copy link
Owner

loeffel-io commented Jul 29, 2024

Hey @ghostrider-05, thank you for your contribution!

this is intended.

The exists rule is exclusive - exists:0 just make sure that there is no file with this extension while it can make sense to combine exists:1 or exists:1-M with other rules.

i think you need something like a not_regex rule right?

@loeffel-io loeffel-io self-assigned this Jul 29, 2024
@ghostrider-05
Copy link
Author

ghostrider-05 commented Jul 29, 2024

Ah thank you for the clarification, sorry if this has been asked before. A not_regex rule would be perfect since regex lookahead is not possible (edit: - without other libraries)

@ccoVeille
Copy link

Well I would expect to have lookahead regexp instead of not_regexp.

Would it be possible?

@ccoVeille
Copy link

this is intended.\n\nThe exists rule is exclusive - exists:0 just make sure that there is no file with this extension while it can make sense to combine exists:1 or exists:1-M with other rules.

It could be added to the documentation then 🤭😅😬

@loeffel-io
Copy link
Owner

Well I would expect to have lookahead regexp instead of not_regexp.

Would it be possible?

this is not possible because golang do not support lookaheads

@ccoVeille
Copy link

Go standard regexp doesn't support it.

But you could use another lib

https://github.com/dlclark/regexp2

@loeffel-io
Copy link
Owner

yeah but i would prefer not_regex which is pretty clear instead of a third party lib with complex lookaheads - wdyt @ccoVeille

@ccoVeille
Copy link

ccoVeille commented Aug 7, 2024

👍. But then the reason is what you said (and I'm fine with it) and not "go doesn't support lookahead regexp"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants