Comments (10)
I found another construct to support: try/catch.
from eslint-plugin-fp.
I get this error (and fp/no-nil
too) for class constructors also, .e.g:
constructor(props) { // <- fp/no-nil error
super(props);
this.state = { display: 'static' }; // <- fp/no-mutation error
}
from eslint-plugin-fp.
Ah you're right. It also doesn't support if/else statements like
function foo() {
if (foo) {
return 1;
} else {
return 2;
}
// Error: does not end with return
}
I was pretty sure that there was a core ESLint rule that required a return statement in every possible path, but I can't find it, so I might be mistaken. I was thinking that I could stop checking the missing return statements, leave them to that rule and just check the return statements. But if I can't find it, never mind.
I can add support for the switch and if/else cases. Do you have other constructs in mind? I don't use loops anymore but there might be some constructs where you always return in the loop and never go past it. Would love some help on that. Not with the implementation (though if someone wants to have a go at it, let me know!), but with trying to find the cases to support.
Note to myself, this rule also needs to report return void value
, which I just learned also returns undefined.
from eslint-plugin-fp.
Yeah, I really want to keep the "no-nil" rule, but I use switch statements extensively with Redux. :/
from eslint-plugin-fp.
I'm experiencing this as well :(
from eslint-plugin-fp.
Since this is a fp plugin, I wouldn't worry about loops too much :)
So yeah I'd focus on switch and if/else as well.
from eslint-plugin-fp.
Well, this plugin aims to make JS into a really FP-like language when all the rules are turned on (would be curious how you all use it by the way), but that's not always the case.
I use it at my workplace, where we use it partially, as some rules are nice to have even in non-full-FP codebase (no-arguments, no-class, no-delete, no-events, no-get-set, no-loops, no-proxy, no-this...). But we still have files with mutation for instance. Therefore, I can't make the assumptions in the rules (as I may previously have thought) that the other rules will cover the other cases.
I have no problem with supporting if/else and switch, and wait for someone to ask me to support loops, but that would not be ideal :)
from eslint-plugin-fp.
from eslint-plugin-fp.
Is there any workaround for this issue?
from eslint-plugin-fp.
So, I've been taking a look at the plugin source code and think I have a few solutions to offer switch statement compatibility and would love to contribute but I'd like to discuss desired utility.
I believe the reportFunctions
use of endsWithReturnStatement
is too limiting and needs to be changed in some way to offer switch/if-else utility.
We could do away with the endsWithReturnStatement
check and replace with a check that just ensures that the block statement does contains a return statement. An extremely loose implementation but I do believes it addresses the intent of ensuring the function does return something and ReturnStatement
of create
already checks to ensure that the return value is not null. On a side point is there a reason the ReturnStatement
of create
only checks for null
and not undefined
as well?
As for specific switch statement implementation I can think of two possible scenarios, either require just the default case to contain a return statement or require all cases to contain a return statement. This is certainly a much more strict implementation but I do feel it is more in-line with how that implementation is used in functional programming even if it does pigeon-hole switch statements to just return value control flow.
Personally, I side with the first implementation as I'm not really a fan of limiting switch statement implementation for anyone who uses the rule. A third option would to be create an entirely new rule that addresses return values but I that's probably overkill.
from eslint-plugin-fp.
Related Issues (20)
- non-mutating slice reverse HOT 1
- Add more options for `no-unused-expression` rule HOT 1
- no-nil false positive
- merge eslint-plugin-better rule into eslint-plugin-fp HOT 2
- document the difference between no-unused-expressions
- CI build failing on Node 4
- no-nil false positive on switch statements HOT 1
- no-mutating-assign with any expression HOT 3
- (fp/no-nil) rule for callbacks? HOT 5
- Upgrade Lodash to avoid `npm update` security issue HOT 1
- fp/no-unused-expression for Node debug
- proposal: rule for limit arguments in function call
- fp/no-nil
- no-mutation and HTML DOM
- no-mutating-methods allowedObjects doesn't work if chained
- ESLint v6 HOT 4
- Fails when run in Jest via ESLint Node.js API
- Support ESLint 8.x HOT 3
- `fp/no-unused-expression` with `'use strict'` HOT 1
- `fp/no-throw`: Option to ignore inside `try`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-fp.