-
Notifications
You must be signed in to change notification settings - Fork 87
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
rule idea: elvis should work on the real code as well #500
Comments
Not a bad idea. All in all, I would not be against implementing your idea, but I would not make it a priority and I would definitely make it optional. |
Of course if someone intentionally wants to trick some security/code_smell checks it is always doable, does not matter how strong the checker is. I actually have a similar plugin working only on the abstract code, but it does completely different checks. Simple no_call checks and maybe some other validation would be good in elvis running on the abstract code, so then elvis would be the right tool for implementing both code_smell checks and function call validation as well. |
In the meantime I've started implementing it.
So if there is an src/mymod.erl, there should be a mymod.beam somewhere. If we are using rebar3 it should be in _build/${REBAR_PROFILE}/lib/myapp/ebin/myapp.beam . Only problem is what if Maybe the path to the beam should come from the configuration.
Using this config elvis should be able to find out where the beam files are stored. What should happen if the beam is not there because compile has not been called? |
As I see the
elvis also won't be able to find that io:format was called. Would it be ok to have the above mentioned
If the |
To be honest, I'm still not convinced about requiring compilation before running the linter (even as an option). I think that…
[{elvis, [
{config, [
#{dirs => ["src"],
filter => "*.erl",
ruleset => erl_files
},
#{dirs => ["_build/default/lib/*/ebin"],
filter => "*.beam",
ruleset => beam_files
}
]}
]}]. |
I've already implemented it differently, but your idea is very good, so I will change the implementation. For the other question: we use elvis by calling
If it is enforced by rebar3_lint plugin and elvis is always called from the plugin, the beam files will be always stored in the given folder by the time elvis is called. |
I see… that sounds very reasonable. |
Also, do you mind opening bug reports for |
Using this implementation the following rules should be moved from the erl_files section to beam_files:
I can open a ticket for the |
Yeah, that's the thing: I believe we can still fix them to work correctly on source files. |
Ok. I've seen when I was debugging the no_call rule, that the parse_tree actually contained the information ?DBG is macro, and it is actually io:format/2 so the code be modified to fix the issue. I will create the ticket. |
I've created a PR: inaka/elvis_core#108. Now the mentioned rules will use abstract code only if they are called from the beam_files section. Current config I use:
I had to modify the specs at some places which is mainly because of the declaration of
rules are written like this in elvis_style.erl:
I think the first parameter is a map here which contains the config, not a list containing maps as it is indicated by the type declaration. Do you have any ideas about possible testing? |
You can test this project by updating deps (or using |
Some rules like variable_naming_convention, line_length, module_naming_convention should use the actual source of the code, but for calls like no_call, no_debug_call, no_common_caveats_call it is not enough to check the source. With a simple parse transform the generated abstract code can easily call anything we don't want to.
Because of this the abstract code should be decompiled into source, it should be passed to modules implementing elvis checks together with the original data generated directly from source, so the abstract code can be validated using ktn_code. The above mentioned checks should operate only on the decompiled code.
The text was updated successfully, but these errors were encountered: