no-ignored-replay-buffer not working when rxjs is imported as another alias
See original GitHub issueTrying to turn on the rxjs-no-ignored-replay-buffer
and the rule fails for expressions like
new Rx.ReplaySubject<number>(1);
when rxjs
is imported like such import * as Rx from 'rxjs';
After playing around with the two cases in the TSQuery playground and checking out the rxjsNoIgnoredReplayBufferRule.ts
it seems that the rule does not work for this case.
Currently the rules’ logic gets the the direct parent of the Identifier
i.e
const newExpression = identifier.parent as ts.NewExpression;
This works for cases where you’re just using the ReplaySubject
directly
const b = new ReplaySubject<string>();
, which has AST
But when rxjs
is imported as an alias like import * as Rx from 'rxjs';
, then the AST looks like this:
Which is a case that the current logic misses because it gets the direct parent of the Identifier
node, and in this case, it is the PropertyAccessExpression
node. Then it is trying to access the arguments
property of the PropertyAccessExpression
node, but we actually wanted the NewExpression
node, another level up. But because we only get the direct parent of the Identifier
, it cannot find that there is a buffer for this replay subject declaration.
Not sure what the best way to fix this is but I was thinking to have the tsquery be NewExpression:has(Identifier[name="ReplaySubject"])
to just get the actual NewExpression
, so we wouldn’t lose its arguments, and then get the identifier text and location later?
Let me know what you think
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top GitHub Comments
You’re welcome to open a PR with the fix, if you have to time to do it.
The problem with that selector is that the
ReplaySubject
can be anywhere within theNewExpression
. For example, that selector will find the outermostnew
in this expression:I would go with a selector something like this:
which should find the
ReplaySubject
in all of these use cases: