-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
no-unsafe-takeuntil: Accept object properties as operators #90
Conversation
I think we could make this change without introducing the ATM - i.e. without your change - this wouldn't behave the way it should: import * as rxjs from "rxjs";
rxjs.of(null)
.pipe(
rxjs.takeUntil(rxjs.NEVER),
rxjs.tap(() => {}),
)
.subscribe(() => {}); So your change is more of a general fix, I think. |
Yes, I think you're right. In that case, I'll delete the option. |
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.
Thanks.
@@ -83,7 +84,7 @@ const rule = ruleCreator({ | |||
const { couldBeObservable } = getTypeServices(context); | |||
|
|||
return { | |||
[`CallExpression[callee.property.name='pipe'] > CallExpression[callee.name=${checkedOperatorsRegExp}]`]: | |||
[`CallExpression[callee.property.name='pipe'] > CallExpression[callee.name=${checkedOperatorsRegExp}], CallExpression[callee.property.name=${checkedOperatorsRegExp}]`]: |
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.
This will match calls via member expressions that are outside of pipe
, as the ,
separates the member-expression selector from the pipe
selector.
If you're curious, you can verify that this is how the selectors behave using http://estools.github.io/esquery/ with:
of(null).pipe(foo())
x.bar()
as the source and
CallExpression[callee.property.name='pipe'] > CallExpression[callee.name='foo'], CallExpression[callee.property.name='bar']
as the selector.
I'm going to merge this and fix it with a subsequent commit. My preference, in these situations, is to have two separate selectors/properties calling shared function.
Your change should be in 4.0.4 - which has just been published. |
Great, thanks! |
Motivation
I wanted to add the rule for the custom
takeUntilDestroy
operator in our working project. The operator is the method of an angular component, which fires whenngOnDestroy
is called. But I stumbled upon the issue that the rule ignores my method:Solution
I added the new option
acceptObjectProperties
(false
by default) which allows adding not only functions but object properties and class members. So with this config:eslint would highlight the problem method: