This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 425200 - [eslint] Provide eslint rule to detect mixed return types
Summary: [eslint] Provide eslint rule to detect mixed return types
Status: RESOLVED FIXED
Alias: None
Product: Orion (Archived)
Classification: ECD
Component: JS Tools (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 11.0   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-09 10:26 EST by Michael Rennie CLA
Modified: 2016-01-08 14:04 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Rennie CLA 2014-01-09 10:26:36 EST
Its all too common to see functions that return more than one type (String and Number for example). We should detect this as an error by default, it makes the use of functions more difficult than they need to be - especially for ones with no doc
Comment 1 John Arthorne CLA 2015-05-05 16:19:15 EDT
Closing as part of a mass clean up of inactive bugs. Please reopen if this problem still occurs or is relevant to you. For more details see:


https://dev.eclipse.org/mhonarc/lists/orion-dev/msg03444.html
Comment 2 Michael Rennie CLA 2015-05-05 22:43:32 EDT
reopen
Comment 3 Olivier Thomann CLA 2015-12-16 10:14:12 EST
Michael, do you mean adding the rules "http://eslint.org/docs/rules/consistent-return" to fix this issue?
If yes, I'll take it.
Comment 4 Olivier Thomann CLA 2015-12-16 10:32:13 EST
This rule is actually not exactly what you expect as it doesn't check the actual return type. It only checks that all return points return a value or no value, but they are all consistent.
What you want is that not only they all return a value, but the value should be of the same type.
I'll see if I can simply modify the existing rule implementation.
Comment 5 Eclipse Genie CLA 2015-12-17 15:25:12 EST
New Gerrit change created: https://git.eclipse.org/r/62965
Comment 6 Curtis Windatt CLA 2015-12-17 15:53:45 EST
Problem message should be "Inconsistent return types"
Would be better to return a list of the different types
"Inconsistent return types: string, boolean"
"Inconsistent return types: string, undefined"

Or for missing return types we can use the ESLint language: Expected no return value.

I think we'll revisit this in January.
Comment 7 Olivier Thomann CLA 2015-12-18 10:12:03 EST
(In reply to Curtis Windatt from comment #6)
> Problem message should be "Inconsistent return types"
> Would be better to return a list of the different types
> "Inconsistent return types: string, boolean"
> "Inconsistent return types: string, undefined"
> Or for missing return types we can use the ESLint language: Expected no
> return value.
I thought about reporting the found types. I was not sure the best message for this.
Comment 8 Olivier Thomann CLA 2015-12-18 13:20:01 EST
I abandonned the change in gerrit. I made local improvements but I still need to be able to handle cases like:
return "" and return "" + 15;
In both cases, this returns a string. Need more work.
Comment 9 Eclipse Genie CLA 2016-01-04 10:32:24 EST
New Gerrit change created: https://git.eclipse.org/r/63472
Comment 10 Olivier Thomann CLA 2016-01-04 10:35:08 EST
(In reply to Eclipse Genie from comment #9)
> New Gerrit change created: https://git.eclipse.org/r/63472
Abandonned as well. Got created during a sync up with master by mistake.
Comment 11 Eclipse Genie CLA 2016-01-04 12:16:09 EST
New Gerrit change created: https://git.eclipse.org/r/63482
Comment 12 Eclipse Genie CLA 2016-01-05 20:02:25 EST
New Gerrit change created: https://git.eclipse.org/r/63604
Comment 13 Olivier Thomann CLA 2016-01-07 12:38:05 EST
(In reply to Eclipse Genie from comment #12)
> New Gerrit change created: https://git.eclipse.org/r/63604
Abandonned again as it doesn't apply cleanly on master anymore.
A new change is underway.
Comment 14 Eclipse Genie CLA 2016-01-07 12:41:06 EST
New Gerrit change created: https://git.eclipse.org/r/63759
Comment 15 Olivier Thomann CLA 2016-01-08 11:07:20 EST
Reverting the change and trying to create it again. For some reason, it looks like the change cannot be properly merged with master.
Comment 16 Eclipse Genie CLA 2016-01-08 11:12:32 EST
New Gerrit change created: https://git.eclipse.org/r/63865