-
Notifications
You must be signed in to change notification settings - Fork 56
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 elvis_style
rule: max_function_clause_length
#365
Conversation
I'm thinking about merging the two rule codes because they are so similar. I should make only one function, that gets parameters(e.g. function or clause), and then call that with the appropriate values. But on the other hand, I think it's more readable and simple. What do you think about it? Oh, and I don't know that the error message is well enough. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some comments regarding the error message.
Personally, I would not merge the functions. In general, issues are usually raised for one particular rule and not for all the rules that work in the same way so (once again: in general) it's usually better to keep each rule's logic in its own function, instead of sharing it… But this might be the exception, of course.
src/elvis_style.erl
Outdated
|
||
ResultFun = | ||
fun({StartPos, L}) -> | ||
Info = [L, MaxLength], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Info = [L, MaxLength], | |
Info = [ClauseNumber, L, MaxLength], |
…aaaaand you would need to somehow compute the clause number 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, I'm on it :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to apply the nth/snd/rd translation here, if you decide to go that way.
Thanks much. In general, this looks solid. I propose a few tweaks. From my end, I prefer it if you don't resolve the comments while you handle them, since it allows me to check your reply easier (and not having to press "Show resolved" all the time). |
I'm thinking about that, we should check the error messages during the tests, to make sure we caught the error message we want. We should make a function that takes the expected message/messages and returns a boolean based on the result. If you think it's useful I would be happy to implement it in another issue maybe, or if not I will just write this test by checking the messages by hand. |
In general, I don't like to check error messages (or other strings, FWIW). They're too variable. |
I have a short time now, that's why it's half done. I want to add better test cases, and unit tests for the And the "function name" is now bad, so maybe I need to parse the clause_nodes and add the function name and arity to it. |
Now, I fixed it a little bit, I hope you find it better too. |
Sorry, @bormilan … but I still fail to see why you need all the recursiveness in that function. In the end it just needs to return a number in string format, doesn't it? |
Do you mean why do I need the function |
Ooooh… but why isn't it enough to do |
Oh maybe my fault was that I searched all the clauses in the |
This solution would be good in my opinion, but because the fact that I need the function name and arity too, I need to switch to the two-deep solution. When I started this looked better because of simplicity, but I was wrong now I see. (sad) |
Now I made the new version, with this I don't need that plus function for the clause numbers. I made a new test, and before merging, I want to make an assertion about the messages(to prove that clause numbers and the message itself are correct) if you think it's good too. (and of course, I will delete the comments) |
I'm approving. I think this is mergeable as it is, but if you feel like adding a test for the clause numbers, running elvis on a file like this should produce one error per clause. -module( … ).
-elvis([{max_length_function_clause, #{max_length => 0}}]).
-export([clause/1]).
clause(1) -> "1st";
clause(2) -> "2nd";
…
clause(111) -> "111th";
clause(112) -> "112th";
clause(113) -> "113th";
–
clause(125) -> "125th". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it. I'll defer final approval to @paulo-ferraz-oliveira … but everything looks good from my perspective.
745979e
to
ffb754f
Compare
Thank you so much! |
elvis_style
rule: max_function_clause_length
I tweaked the PR title since this'll go directly into the generated release Changelog. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm Ok, I guess, but I don't know what changed since my last review, since all the commits were squashed.
I left a couple of comments above, that should be handled; after that we're good to go. Thanks. |
Oh, sorry next time I will wait with it till the very end. |
2b4ed0d
to
8cbcdb6
Compare
Almost there, @bormilan |
8c15264
to
33dc2d7
Compare
Thanks, @bormilan !!! Amazing work. |
Description
I added a new rule called
max_function_clause_length
.The old rule
max_function_length
stays the same, it checks the length of an entire function, but now we can check the size of the clauses separately.Closes #335