-
Notifications
You must be signed in to change notification settings - Fork 57
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
New rule: Prefer Unquoted Atoms #297
Comments
One thing I remembered is that language constructs need to be quoted as atoms. e.g. |
Maybe other formatters would leave atoms as-they-found-them, but at least rebar3_format (with the default formatter) will apply this concept appropriately (i.e., only atoms that need to be quoted will be quoted). |
Not saying "no" to the rule, just that it may be low priority since other tools cover this aspect. |
If you're analysing from BEAM this might not apply; if you're analysing from source it's still interesting. |
I spent much time exploring how these work in the repo, but I'm still confused. I see that we have several rules that require .erl files not .beam for example macro naming conventions. But I also see that in the Edit: I started working with the Edit2: nevermind, I found out that |
I think I made good progress today, it's not perfect but works. Could you please provide me with some suggestions? |
A while back, rules only supported analysis on
-spec all() -> [atom()].
all() ->
Exports = ?MODULE:module_info(exports),
[F || {F, _} <- Exports, not lists:member(F, ?EXCLUDED_FUNS)] ++ [{group, beam_files}]. and it outputs 120+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Common test
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% section of the identified file.
You should open a pull request (e.g. as a draft) so we can discuss the implementation details there. Edit: I briefly looked at the implementation; it seems to go in the right direction. A pull request will allow us to make inline comments that'll help you better. |
feat(#297): New rule: Prefer Unquoted Atoms
This can be closed, isn't it? |
I… think so. @paulo-ferraz-oliveira ? |
Depends... if we want to do nothing, assuming this is a concern for other tools, sure 😄. If, at the same time, the tools we use to parse the code for analysis already remove quotes when not required then we'd have to change those, and that's not something we wanna do 👍. So, yeah, I'll close it. If it becomes a hassle, in the future, we have history already. |
Name
prefer_unquoted_atoms
Brief Description
Prefer unquoted atoms unless quotes are necessary.
Reasoning
This one is not a technical concern, but a readability concern. The code will behave identical in both ways.
Refactoring Proposal
elvis
shall warn that your atoms are quoted when they don't have to be.Note: if you're using a formatter this could/should already be taken into account by it.
Origin
Inspired by Credo's https://hexdocs.pm/credo/Credo.Check.Readability.PreferUnquotedAtoms.html.
The text was updated successfully, but these errors were encountered: