Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add no_empty_functions rule that triggers if an empty function is defined #254
In the past, I have been bitten by the following code:
What's wrong is that doSomethingSignificant is called no matter what after the call to someFunctionWithCallback, whereas what I really wanted to do is to call doSomethingSignificant from within the callback. It makes a big difference whether someFunctionWithCallback is asynchronous or not.
These kind of issues can sometimes be very tricky to find. This error is often located deep into the source code and when you look at it, it's hard to spot that an indentation token is missing. Moreover, the execution of such code may look perfectly valid, since you expected doSomethingSignificant to be called anyway.
The no_empty_functions rule triggers an error on such code.
I have never used empty functions myself, but I know that other programmers like to do so. When one wants to define an empty function, one only has to use undefined as the only expression within the function body, like so:
It states the intention clearly, and it's not too long to type. It's even similar to Python's pass statement.
@AsaAyers You are right. I set the rule to
referenced this pull request
Apr 10, 2014
@AsaAyers Yes, it does.
In order not to consider the following function an empty function
I guess I could check if the 'Code' node has a child 'Param' node that matches the following pattern:
However, the goal is to avoid these forms:
added a commit
this pull request
Apr 16, 2014
I recommend a 2nd pull request to edit the description.
I know it's awkward, but if you want to preview what will be generated for the next release run this series of commands.
When I prepare the release I'll update the changelog and run these commands.