-
Notifications
You must be signed in to change notification settings - Fork 16
no-effect-override rule #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
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.
Semicolon is invalid after a function declaration (results in an extra empty statement following the declaration).
@sompylasar Now only the docs are missing? |
I have added all test cases you mentioned in #1 (comment) except for the 2 good tests are failing now, maybe you can have a look if they are really valid function generator use cases. |
docs/rules/yield-effects.md
Outdated
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.
Unnecessary empty line.
We may assume these failing cases as marginal and just really report them as errors. |
test/lib/rules/yield-effects-spec.js
Outdated
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.
Here and below should be no "noyield" because the actual take
effect from the redux-saga
is simply unused.
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 would consider that still an override error since the take
override hides the saga effect import. That its most likely a serious error. If not, the user can still disable the rule for that section of the file.
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.
Yes, there should only be the override error, but not noyield error.
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.
so the same is true for all overrides_and_noyield
tests? The only error that should be thrown is override
?
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.
Yes. You can't say an effect wasn't yielded because what you found is not an effect, it's something else, named the same.
0d5e1af
to
540d3c2
Compare
540d3c2
to
ce831e2
Compare
Squashed for merge. What do you think? @sompylasar |
code: "import { take as sagaTake } from 'redux-saga';" | ||
+ "export default function* saga() {" | ||
+ " const sagaTakeEffect = sagaTake();" | ||
+ " yield sagaTakeEffect;" |
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.
Do we allow yielding something that is not an effect or array of effects?
BTW, the test for yielding array of effects is missing.
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 think general function generator linting should be done in a separate plugin or eslint core.
I'll add the other tests for arrays
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.
It's a valid piece of code, you can generally yield any value from a generator. The question is, do we allow that for sagas (the files where the redux-saga
module is imported)?
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 would say thats for another linter plugin that specifically deals with generators. The case tested above seems very unlikely to happen in a real program.
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.
Another plugin that would deal with generators should treat this code as valid, because it is. You can yield anything.
But, when using redux-saga
, you should only yield the return values of the effect creators (or arrays of such).
So, it's this eslint-plugin-redux-saga
's responsibility to limit the usage of generators to only yield redux-saga
effects when a saga file is detected (by assuming files which import redux-saga
as files that declare sagas, and generators inside them are sagas).
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.
Ok, I agree. So which additional tests / checks you suggesting to complete this rule?
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.
Sorry for the delay.
I would test for the patterns described in the redux-saga documentation, starting from here: http://yelouafi.github.io/redux-saga/docs/basics/UsingSagaHelpers.html and here: http://yelouafi.github.io/redux-saga/docs/advanced/RunningTasksInParallel.html
Note that the effect creators are imported from redux-saga/effects
, but the helpers which are to be yield*
ed, not yield
ed, are imported from redux-saga
itself:
import { call, put } from 'redux-saga/effects'
import { takeEvery } from 'redux-saga'
Note that yield
ing an array of calls to effect creators is also valid:
// correct, effects will get executed in parallel
const [users, repos] = yield [
call(fetch, '/users'),
call(fetch, '/repos')
]
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.
Will be able to work on that more now.
This is a WIP PR to fix #1. The docs are missing.