Skip to content

Conversation

pke
Copy link
Owner

@pke pke commented Jul 22, 2016

This is a WIP PR to fix #1. The docs are missing.

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

@pke
Copy link
Owner Author

pke commented Jul 22, 2016

@sompylasar Now only the docs are missing?

@pke
Copy link
Owner Author

pke commented Jul 22, 2016

I have added all test cases you mentioned in #1 (comment) except for the fork stories.

2 good tests are failing now, maybe you can have a look if they are really valid function generator use cases.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary empty line.

@sompylasar
Copy link

We may assume these failing cases as marginal and just really report them as errors.
There is no need in the real code to pre-create effects and then yield them later.

Copy link

@sompylasar sompylasar Jul 22, 2016

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.

Copy link
Owner Author

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.

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.

Copy link
Owner Author

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?

Copy link

@sompylasar sompylasar Jul 22, 2016

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.

@pke pke force-pushed the fix/detect-hiding-of-redux-effects-in-scope branch from 0d5e1af to 540d3c2 Compare July 22, 2016 20:37
@pke pke force-pushed the fix/detect-hiding-of-redux-effects-in-scope branch from 540d3c2 to ce831e2 Compare July 22, 2016 20:47
@pke
Copy link
Owner Author

pke commented Jul 22, 2016

Squashed for merge. What do you think? @sompylasar

@pke pke changed the title WIP: no-effect-override rule no-effect-override rule Jul 22, 2016
code: "import { take as sagaTake } from 'redux-saga';"
+ "export default function* saga() {"
+ " const sagaTakeEffect = sagaTake();"
+ " yield sagaTakeEffect;"

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.

Copy link
Owner Author

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

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)?

Copy link
Owner Author

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.

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

Copy link
Owner Author

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?

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 yielded, are imported from redux-saga itself:

import { call, put } from 'redux-saga/effects'
import { takeEvery } from 'redux-saga'

Note that yielding 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')
]

Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants