Rule Definition
"pipeable" operators are better than the "patch" operators for pulling in just the operators needed.
Problems with the patched operators for dot-chaining are:
Any library that imports a patch operator will augment the Observable.prototype for all consumers of that library, creating blind dependencies. If the library removes their usage, they unknowingly break everyone else. With pipeables, you have to import the operators you need into each file you use them in.
Operators patched directly onto the prototype are not "tree-shakeable" by tools like rollup or webpack. Pipeable operators will be as they are just functions pulled in from modules directly.
Unused operators that are being imported in apps cannot be detected reliably by any sort of build tooling or lint rule. That means that you might import scan, but stop using it, and it's still being added to your output bundle. With pipeable operators, if you're not using it, a lint rule can pick it up for you.
Functional composition is awesome. Building your own custom operators becomes much, much easier, and now they work and look just like all other operators from rxjs. You don't need to extend Observable or override lift anymore.
Remediation
Use "pipeable" operators which can be imported from "rxjs/operators".
Violation Code Sample
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/tap';
myObservable$
.tap(company=> console.log(`Before: ${company}`))
.map(company=> `${company.name}, ${company.country}`)
.tap(company=> console.log(`After: ${company}`))
Fixed Code Sample
import { map, tap } from 'rxjs/operators';
myObservable$
.pipe(
tap(company=> console.log(`Before: ${company}`)),
map(company=> `${company.name}, ${company.country}`),
tap(company=> console.log(`After: ${company}`))
)
Reference
https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md
Related Technologies
Technical Criterion
CWE-1062 - Parent Class with References to Child Class
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.