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

Consistency error in regex #40

Closed
hojgr opened this issue Feb 14, 2016 · 5 comments
Closed

Consistency error in regex #40

hojgr opened this issue Feb 14, 2016 · 5 comments

Comments

@hojgr
Copy link

hojgr commented Feb 14, 2016

Hello!

Awesome project!

I'm running it on my application and one of the warnings I get is this one

  Consistency                                                                                                                                                                                                                      
┃ 
┃ [C] ↗ There is no whitespace around parentheses/brackets most of the time, but here there is.
┃       web/models/user.ex:24 (Hosting.User)

Thing is, the 24th line in user.ex is

@username_regex ~r/^[A-z0-9 ]+$/

Thing is, this is regex. I want to match the whitespace. I think this is a bug :)

Michal Hojgr

rrrene added a commit that referenced this issue Feb 14, 2016
@rrrene
Copy link
Owner

rrrene commented Feb 14, 2016

Thanks for the bug report! I added a test reproducing the issue and will try to fix as soon as I can 👍

@hojgr
Copy link
Author

hojgr commented Feb 14, 2016

I thank you for your work for the community :)

@hojgr hojgr closed this as completed Feb 14, 2016
@c-rack
Copy link
Contributor

c-rack commented Feb 14, 2016

@rrrene I just looked at this issue and think it is best to just remove the regex before applying the checks. But this lead to the next problem: how to properly detect the end of the regex? Instead of trying to detect the end of the regex, I propose to just strip everything following the ~r prefix.

So I came up with a simple but working solution by inserting

    line = line |> String.replace(~r/\~r.*$/, "")

before this line:
https://github.com/rrrene/credo/blob/master/lib/credo/check/consistency/space_in_parentheses/with_space.ex#L19

Yes, it is far from being optimal and may remove too much code that could contain problems, but until we find a better solution it should work. What do you think?

@rrrene
Copy link
Owner

rrrene commented Feb 14, 2016

@hojgr I re-opened this issue since it is not fixed, yet.

@c-rack I agree something like that will be the way to go. There is also the Credo.Code.Sigils module, which was introduced to strip sigils from source code. That way we could at least remove the ~r sigils cleanly.

@rrrene rrrene reopened this Feb 17, 2016
@rrrene
Copy link
Owner

rrrene commented Feb 17, 2016

@hojgr v0.3.3 contains a fix. Thx again for reporting! 👍

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

No branches or pull requests

3 participants