百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

rxjs-tslint-rules

> 编程语言
开源

RxJS 的 TSLint 规则

374 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

RxJS 的 TSLint 规则

rxjs-tslint-rules

TSLint is deprecated. All of the rules in this package - with the exception of the RxJS-version-5-only rules - have equivalent ESLint rules in the eslint-plugin-rxjs and eslint-plugin-rxjs-angular packages.

If you've arrived here looking for the TSLint rules that automatically convert RxJS version 5 code to version 6, you can find those rules here: rxjs-tslint.

That said, if you've not already done so, you might want to checkout the rules in this package, too. Using them, you can avoid potential problems and questionable practices.

What is it?

rxjs-tslint-rules is set of TSLint rules to:

  • help manage projects that use rxjs/add/... imports;
  • enforce or disallow Finnish notation; and
  • highlight other potential problems (see the rules for details).

Why might you need it?

When using imports that patch Observable:

typescript
import { Observable } from "rxjs/Observable";
import "rxjs/add/observable/of";
import "rxjs/add/operator/map";

TypeScript will see the merged declarations in all modules, making it difficult to find rxjs/add/... imports that are missing from modules in which patched observables and operators are used.

This can cause problems, as whether or not Observable is patched then depends upon the order in which the modules are executed.

The rules in this package can be used to highlight missing - or unused - imports and other potential problems with RxJS.

There are some examples of policies that can be implemented using particular rule combinations in:

  • Managing RxJS Imports with TSLint; and
  • Understanding Lettable Operators.
  • TSLint Rules for Version 6

And Christian Liebel has written about his approach to importing RxJS in his blog post:

  • Angular & TypeScript: How to Import RxJS Correctly?

Install

Install the package using NPM:

bash
npm install rxjs-tslint-rules --save-dev

Update your tslint.json file to extend this package:

json
{
  "extends": [
    "rxjs-tslint-rules"
  ],
  "rules": {
    "rxjs-add": { "severity": "error" },
    "rxjs-no-unused-add": { "severity": "error" }
  }
}

Rules

WARNING: Before configuring any of the following rules, you should ensure that TSLint's no-unused-variable rule is not enabled in your configuration (or in any configuration that you extend). That rule has caused problems in the past - as it leaves the TypeScript program in an unstable state - and has a significant number of still-open issues. Consider using the no-unused-declaration rule from tslint-etc instead.

The package includes the following rules (none of which are enabled by default):

Rule Description Options
rxjs-add Enforces the importation of patched observables and operators used in the module. See below
rxjs-ban-observables Disallows the use of banned observables. See below
rxjs-ban-operators Disallows the use of banned operators. See below
rxjs-deep-operators Enforces deep importation from within rxjs/operators - e.g. rxjs/operators/map. Until Webpack does not require configuration for tree shaking to work, there will be situations where deep imports are preferred. None
rxjs-finnish Enforces the use of Finnish notation. See below
rxjs-just Enforces the use of a just alias for of. Some other Rx implementations use just and if that's your preference, this is the rule for you. (There was some discussion about deprecating of in favour of just, but it was decided to stick with of.) This rule includes a fixer. None
rxjs-no-add Disallows the importation of patched observables and operators. See below
rxjs-no-async-subscribe Disallows passing async functions to subscribe. None
rxjs-no-compat Disallows importation from locations that depend upon rxjs-compat. None
rxjs-no-connectable Disallows operators that return connectable observables. None
rxjs-no-create Disallows the calling of Observable.create. Use new Observable instead. None
rxjs-no-deep-operators Disallows deep importation from rxjs/operators. Deep imports won't be in available in RxJS v6. None
rxjs-no-do I do without do operators. Do you not? Well, do isn't always a code smell, but this rule can be useful as a warning. None
rxjs-no-explicit-generics Disallows the explicit specification of generic type arguments when calling operators. Rely upon TypeScript's inference instead. None
rxjs-no-exposed-subjects Disallows exposed subjects. In classes, Subject properties and methods that return a Subject must be private. See below
rxjs-no-finnish Disallows the use of Finnish notation. None
rxjs-no-ignored-error Disallows the calling of subscribe without specifying an error handler. None
rxjs-no-ignored-notifier Disallows observables not composed from the repeatWhen or retryWhen notifier. None
rxjs-no-ignored-observable Disallows the ignoring of observables returned by functions. None.
rxjs-no-ignored-replay-buffer Disallows using ReplaySubject, publishReplay or shareReplay without specifying the buffer size. None
rxjs-no-ignored-subscribe Disallows the calling of subscribe without specifying arguments. None
rxjs-no-ignored-subscription Disallows ignoring the subscription returned by subscribe. None
rxjs-no-ignored-takewhile-value Disallows the ignoring of the takeWhile value. None
rxjs-no-implicit-any-catch Like the no-implicit-any-catch rule in @typescript-eslint/eslint-plugin, but for the catchError operator instead of catch clauses.
rxjs-no-index Disallows importation from rxjs/index, etc. - for the reason, see this issue. None
rxjs-no-internal Disallows importation from rxjs/internal. None
rxjs-no-nested-subscribe Disallows the calling of subscribe within a subscribe callback. None
rxjs-no-operator Disallows importation from rxjs/operator. Useful if you prefer 'pipeable' operators - which are located in the operators directory. None
rxjs-no-patched Disallows the calling of patched methods. Methods must be imported and called explicitly - not via Observable or Observable.prototype. See below
rxjs-no-redundant-notify Disallows redundant notifications from completed or errored observables. None
rxjs-no-sharereplay Disallows using the shareReplay operator. Prior to version 6.4.0, that operator had some surprising behaviour. See below
rxjs-no-subclass Disallows subclassing RxJS classes. None
rxjs-no-subject-unsubscribe Disallows calling the unsubscribe method of a Subject instance. For an explanation of why this can be a problem, see this Stack Overflow answer. None
rxjs-no-subject-value Disallows accessing the value property of a BehaviorSubject instance. None
rxjs-no-tap An alias for rxjs-no-do. None
rxjs-no-topromise Forbids the use of the toPromise method. None
rxjs-no-unbound-methods Disallows the passing of unbound methods as callbacks. None
rxjs-no-unsafe-catch Disallows unsafe catch and catchError usage in NgRx effects and redux-observable epics. See below
rxjs-no-unsafe-first Disallows unsafe first and take usage in NgRx effects and redux-observable epics. None
rxjs-no-unsafe-scope Disallows the use of variables/properties from unsafe/outer scopes in operator callbacks. See below
rxjs-no-unsafe-subject-next Disallows unsafe optional next calls. The argument passed to next is optional, but not passing it is often unsafe. None
rxjs-no-unsafe-switchmap Disallows unsafe switchMap usage in NgRx effects and redux-observable epics. See below
rxjs-no-unsafe-takeuntil Disallows the application of operators after takeUntil. Operators placed after takeUntil can effect subscription leaks. See below
rxjs-no-unused-add Disallows the importation of patched observables or operators that are not used in the module. None
rxjs-no-wholesale Disallows the wholesale importation of rxjs or rxjs/Rx. None
rxjs-prefer-angular-async-pipe Disallows the calling of subscribe within an Angular component. None
rxjs-prefer-angular-composition Enforces the composition of subscriptions within an Angular component. The rule ensures that subscriptions are composed into a class-property Subscription and that the Subscription is unsubscribed in ngOnDestroy. (For an example, see the tests.) None
rxjs-prefer-angular-takeuntil Enforces the application of the takeUntil operator when calling subscribe within Angular components (and, optionally, within services, directives, and pipes). The rule (optionally) ensures that takeUntil is passed a class-property Subject and that the Subject is notified in ngOnDestroy. (For an example, see the tests.) See below
rxjs-prefer-observer Enforces the passing of observers to subscribe and tap. See this RxJS issue. See below
rxjs-suffix-subjects Disalllows subjects that don't end with the specified suffix option. See below
rxjs-throw-error Enforces the passing of Error values to error notifications. None

Options

rxjs-add

The rxjs-add rule takes an optional object with the property file. This is the path of the module - relative to the tsconfig.json - that imports the patched observables and operators.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptrxjstslint

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言