question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-ignored-replay-buffer not working when rxjs is imported as another alias

See original GitHub issue

Trying 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 image

But when rxjs is imported as an alias like import * as Rx from 'rxjs';, then the AST looks like this: image

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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
cartantcommented, Feb 15, 2019

You’re welcome to open a PR with the fix, if you have to time to do it.

1reaction
cartantcommented, Feb 15, 2019

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?

The problem with that selector is that the ReplaySubject can be anywhere within the NewExpression. For example, that selector will find the outermost new in this expression:

new Thing(new Rx.ReplaySubject<number>(1));

I would go with a selector something like this:

NewExpression Identifier[name="ReplaySubject"], NewExpression PropertyAccessExpression Identifier[name="ReplaySubject"]

which should find the ReplaySubject in all of these use cases:

const a = new Thing(new Rx.ReplaySubject<number>(1));
const b = new Rx.ReplaySubject<number>(1);
const c = new ReplaySubject<number>(1);
Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint-plugin-rxjs/no-ignored-replay-buffer.md at main - GitHub
This rule effects failures if the buffer size of a replay buffer is not explicitly specified. Rule details. Examples of incorrect code for...
Read more >
rxjs-tslint-rules
Enforces deep importation from within rxjs/operators - e.g. rxjs/operators/map . Until Webpack does not require configuration for tree shaking to work, there ...
Read more >
Best way to import Observable from rxjs - Stack Overflow
FlatMap: flatMap is alias to mergeMap so we need to import mergeMap to ... With this all your rxjs 5.x code should run...
Read more >
Importing instructions - RxJS
This new export site was introduced with RxJS version 6 where all pipeable operators could have been imported from 'rxjs/operators' . For example,...
Read more >
RxJS Operators
Creation Operators are the other kind of operator, which can be called as ... To explain how operators work, textual descriptions are often...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found