-
Notifications
You must be signed in to change notification settings - Fork 171
Conversation
Can we have an option to allow implicit returns for one line functions? |
assert.lengthOf(errors, 3) | ||
for error in errors | ||
assert.equal(error.message, 'Implicit returns are forbidden') | ||
assert.equal(error.rule, 'no_implicit_return') |
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.
Consider adding this line to your test:
assert.notEqual(error.lineNumber, undefined)
If you add line numbers to your errors it will pass.
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 don't think it's possible to get line numbers from the AST. I would need to cross-reference with the source file. Could be done I suppose, I'll look into it.
Sorry it took me so long to get back to you on this. I agree with your comments about line numbers and one-line functions, but the changes are impossible to implement without extending the |
I don't know enough about the AST but I would say that if you have trouble determining function length have the |
@omarkhan CoffeeScript is trying to add line number support for source maps, so I think they'll end up on AST nodes. Maybe check in with that effort. That being said, if you want no implicit returns, I'd stay simple and enforce that rule for functions of any length. @brysgo Thanks for the nice code review in this thread. |
So what's the situation with this rule? I also don't really like the implicit return that coffeescript has... and coffeelint is a perfect tool to force our team's development work to use the same conventions and adding a return statement is easy to forget. CoffeeLint would be a perfect tool for detecting and notifying about implicit returns. Though I agree it'd be nice to have the possibility for allowing implicit returns for one line functions, but even the plain "boolean rule" of handling all implicit returns would help! |
This patch should work, although you might need to do some merge conflict resolution as it's quite old. There is not yet a straightforward way to detect whether the return is on the same line as the '->', this will be easier when/if coffeescript starts including line numbers in the AST. |
Looks like this might be easier now that we have source locations in the AST: jashkenas/coffeescript@ac9d0e1 I'll give this another look when I get the chance |
@omarkhan Very nice of you :) |
Is there still interest in this issue? It seems like it's probably possible now to identify single line functions. That seems like it would be a critical part of this rule. |
I'm very interested in adding this rule to my project if it could exist. |
I believe everything needed to build this rule is in place, except I have not use for this rule. I'd rather let someone with a use for it build it, I greatly simplified the rule system to help people get started. |
This rule will definitely be used in our organization. +1 |
+1 |
1 similar comment
+1 |
@saifelse has published this as a 3rd party rule. https://github.com/saifelse/coffeelint-no-implicit-returns I read through the code and it looks good to me 👍. It doesn't match my style, so I haven't take the time to run it yet. This is mentioned on coffeelint.org under "Loading Custom Rules", but as a reminder rules can be found at https://www.npmjs.org/search?q=coffeelintrule |
I don't like coffeescript's implicit returns and try not to use them. This is a patch that allows coffeelint to detect implicit returns.