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

Extend naming conventions with things to avoid #151

Open
elbrujohalcon opened this issue Aug 7, 2020 · 7 comments · May be fixed by #377
Open

Extend naming conventions with things to avoid #151

elbrujohalcon opened this issue Aug 7, 2020 · 7 comments · May be fixed by #377
Milestone

Comments

@elbrujohalcon
Copy link
Member

Currently, our naming convention rules only allow for a single regex that identifies what is permitted/valid.
It would be nice to add an additional forbidden regex to identify things that are not valid, like function names starting with do_.

Ref: WhatsApp/erlfmt#91

@paulo-ferraz-oliveira
Copy link
Collaborator

For semantics purposes, a forbidden keyword might make sense... but then you'd always have to have an order in evaluation: if you accept and negate a given string, which one is valid?

Have you considered negative lookaheads, like ^(?!(^do_)).*$?

> {ok,RE} = re:compile("^(?!do_).*$").
{ok,{re_pattern,0,0,0,
                <<69,82,67,80,87,0,0,0,16,0,0,0,1,128,0,0,255,255,255,
                  255,255,255,...>>}}
> re:run("ado_", RE).                        
{match,[{0,4}]}
> re:run("do_", RE). 
nomatch

@elbrujohalcon
Copy link
Member Author

HA! I didn't know about negative lookaheads.
I still think that a forbidden regex would be clearer and the usual semantics is "allow everything that matches with regex except if it matches forbidden regex". I would go with that, with the default for forbidden being none.

@paulo-ferraz-oliveira
Copy link
Collaborator

with the default for forbidden being none.

It could even be undefined :-)

@elbrujohalcon elbrujohalcon transferred this issue from inaka/elvis Jan 7, 2021
@elbrujohalcon elbrujohalcon added this to the 2.0.0 milestone May 26, 2022
@elbrujohalcon elbrujohalcon modified the milestones: 4.1.0, 4.0.0 Nov 13, 2024
@bormilan
Copy link
Contributor

Could you help me with the regexes? What do we want to add to the forbidden regexes?
We have four naming conventions, function_, variable_, module_, and atom_naming_convention.

@elbrujohalcon
Copy link
Member Author

elbrujohalcon commented Nov 29, 2024

@bormilan the default should be none or undefined or something that means nothing.
As examples of forbidden regexes (for tests), you can use… say… "[0-9]" if you don't want numbers at all in your… atoms (maybe). Or you can exclude specific words, like "(is|maybe|do)". Or you may want to forbid names ending with an underscore, i.e. "_$". Use whatever expression you want as a regex example, be creative!

@bormilan
Copy link
Contributor

Oh, I understand now; the goal is to allow users to specify their forbidden cases if they wish, rather than adding specific rules.
Thanks!

@paulo-ferraz-oliveira
Copy link
Collaborator

... and make it explicit in the doc., as @elbrujohalcon states, that whatever is accepted in regex except if it matches forbidden.

@bormilan bormilan linked a pull request Dec 1, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants