Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Add "no_implicit_return" option #30

Closed
wants to merge 2 commits into from

Conversation

omarkhan
Copy link
Contributor

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.

@brysgo
Copy link
Contributor

brysgo commented Jun 23, 2012

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')
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@omarkhan
Copy link
Contributor Author

omarkhan commented Aug 7, 2012

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 ASTLinter to look at the source file itself. What do you think the best approach would be?

@brysgo
Copy link
Contributor

brysgo commented Aug 8, 2012

I don't know enough about the AST but I would say that if you have trouble determining function length have the LexicalLinter record it somehow.

@clutchski
Copy link
Owner

@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.

@aripalo
Copy link

aripalo commented Feb 7, 2013

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!

@omarkhan
Copy link
Contributor Author

omarkhan commented Feb 8, 2013

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.

@omarkhan
Copy link
Contributor Author

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

@aripalo
Copy link

aripalo commented Feb 27, 2013

@omarkhan Very nice of you :)

@AsaAyers
Copy link
Collaborator

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.

@Quazie
Copy link

Quazie commented Nov 27, 2013

I'm very interested in adding this rule to my project if it could exist.

@AsaAyers
Copy link
Collaborator

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.cyclomatic_complexity.coffee, no_unnecessary_fat_arrows.coffee, and missing_fat_arrows.coffee are our 3 AST based rules that would be most similar to what is needed.

@JohnTheodore
Copy link

This rule will definitely be used in our organization. +1

@keitheis
Copy link

+1

1 similar comment
@chrisspiegl
Copy link

+1

@AsaAyers
Copy link
Collaborator

@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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants