パッケージの詳細

eslint-plugin-rxjs

cartant1.1mMIT5.0.3

ESLint rules for RxJS

lint, rules, eslint, rxjs

readme

eslint-plugin-rxjs

GitHub License NPM version Downloads Build status dependency status devDependency Status peerDependency Status

This package contains a bunch of ESLint rules for RxJS. Essentially, it's a re-implementation of the rules that are in the rxjs-tslint-rules package. (The Angular-specific rules in rxjs-tslint-rules have been re-implemented in eslint-plugin-rxjs-angular.)

Some of the rules are rather opinionated and are not included in the recommended configuration. Developers can decide for themselves whether they want to enable opinionated rules.

Almost all of these rules require the TypeScript parser for ESLint.

Install

Install the ESLint TypeScript parser using npm:

npm install @typescript-eslint/parser --save-dev

Install the package using npm:

npm install eslint-plugin-rxjs --save-dev

Configure the parser and the parserOptions for ESLint. Here, I use a .eslintrc.js file for the configuration:

const { join } = require("path");
module.exports = {
  parser: "@typescript-eslint/parser",
  parserOptions: {
    ecmaVersion: 2019,
    project: join(__dirname, "./tsconfig.json"),
    sourceType: "module"
  },
  plugins: ["rxjs"],
  extends: [],
  rules: {
    "rxjs/no-async-subscribe": "error",
    "rxjs/no-ignored-observable": "error",
    "rxjs/no-ignored-subscription": "error",
    "rxjs/no-nested-subscribe": "error",
    "rxjs/no-unbound-methods": "error",
    "rxjs/throw-error": "error"
  }
};

Or, using the recommended configuration:

const { join } = require("path");
module.exports = {
  parser: "@typescript-eslint/parser",
  parserOptions: {
    ecmaVersion: 2019,
    project: join(__dirname, "./tsconfig.json"),
    sourceType: "module"
  },
  extends: ["plugin:rxjs/recommended"],
};

Rules

The package includes the following rules.

Rules marked with ✅ are recommended and rules marked with 🔧 have fixers.

Rule Description
ban-observables Forbids the use of banned observables.
ban-operators Forbids the use of banned operators.
finnish Enforces the use of Finnish notation.
just Enforces the use of a just alias for of. 🔧
no-async-subscribe Forbids passing async functions to subscribe.
no-compat Forbids importation from locations that depend upon rxjs-compat.
no-connectable Forbids operators that return connectable observables.
no-create Forbids the calling of Observable.create.
no-cyclic-action Forbids effects and epics that re-emit filtered actions.
no-explicit-generics Forbids explicit generic type arguments.
no-exposed-subjects Forbids exposed (i.e. non-private) subjects.
no-finnish Forbids the use of Finnish notation.
no-ignored-error Forbids the calling of subscribe without specifying an error handler.
no-ignored-notifier Forbids observables not composed from the repeatWhen or retryWhen notifier.
no-ignored-observable Forbids the ignoring of observables returned by functions.
no-ignored-replay-buffer Forbids using ReplaySubject, publishReplay or shareReplay without specifying the buffer size.
no-ignored-subscribe Forbids the calling of subscribe without specifying arguments.
no-ignored-subscription Forbids ignoring the subscription returned by subscribe.
no-ignored-takewhile-value Forbids ignoring the value within takeWhile.
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. 🔧
no-index Forbids the importation from index modules - for the reason, see this issue.
no-internal Forbids the importation of internals. 🔧
no-nested-subscribe Forbids the calling of subscribe within a subscribe callback.
no-redundant-notify Forbids redundant notifications from completed or errored observables.
no-sharereplay Forbids using the shareReplay operator.
no-subclass Forbids subclassing RxJS classes.
no-subject-unsubscribe Forbids calling the unsubscribe method of a subject instance.
no-subject-value Forbids accessing the value property of a BehaviorSubject instance.
no-subscribe-handlers Forbids the passing of handlers to subscribe.
no-topromise Forbids the use of the toPromise method.
no-unbound-methods Forbids the passing of unbound methods.
no-unsafe-catch Forbids unsafe catchError usage in effects and epics.
no-unsafe-first Forbids unsafe first/take usage in effects and epics.
no-unsafe-subject-next Forbids unsafe optional next calls.
no-unsafe-switchmap Forbids unsafe switchMap usage in effects and epics.
no-unsafe-takeuntil Forbids the application of operators after takeUntil.
prefer-observer Forbids the passing separate handlers to subscribe and tap. 🔧
suffix-subjects Enforces the use of a suffix in subject identifiers.
throw-error Enforces the passing of Error values to error notifications.

更新履歴

5.0.3 (2023-03-28)

Fixes

  • Widen the TypeScript peer dependency. (e9ed8b3)

5.0.2 (2022-01-26)

Fixes

  • Don't ignore $-suffixed properties in the suffix-subjects rule. (d4a94c0)

5.0.1 (2022-01-12)

Fixes

  • The no-ignored-takewhile-value rule is now aware of array and object destructuring patterns. (f0f0cf3)

5.0.0 (2022-01-06)

Breaking Changes

  • The prefer-observer rule now has a fixer. (d40b0a0)

4.0.4 (2021-12-31)

Fixes

  • The alias option of the no-unsafe-takeuntil rule now supports method calls. See this PR. (4fe7423)

4.0.3 (2021-11-19)

Fixes

  • Escape RegExp characters in the suffix-subjects rule's suffix option. See this issue. (a23a69c)
  • Don't effect failures for inner first-like operators in the no-unsafe-first rule. See this issue. (19806a4)

4.0.2 (2021-11-08)

Fixes

  • Don't effect failures in the throw-error rule when unknown is thrown. See this issue. (784f463)

4.0.1 (2021-10-26)

Features

  • Add no-subscribe-handlers rule. (ea36a6d)

4.0.0 (2021-10-17)

Breaking Changes

  • Support eslint v8 and @typescript-eslint v5. (644953a)

3.3.7 (2021-08-29)

Fixes

  • Allow multiple takeUntil operators with other operators placed in between. (e66478c)

3.3.6 (2021-08-14)

Fixes

  • Don't attempt to ban shallow/root operator imports - introduced in RxJS 7.2 - in the ban-operators. (489a72e)

3.3.5 (2021-07-09)

Fixes

  • Support shallow/root operator imports - introduced in RxJS 7.2 - in the ban-operators and no-tap rules. (009381f)

3.3.4 (2021-06-26)

Fixes

  • Check for non-RxJS takeWhile imports in no-ignored-takewhile-value. (476fc29)

3.3.3 (2021-05-29)

Fixes

  • Bump eslint-etc version. (ca61caa)

3.3.2 (2021-05-28)

Fixes

  • Support factories in the throw-error rule. (f4e8835)

3.3.1 (2021-05-19)

Changes

  • Remove the no-subject-value rule from recommended configuration. This was an oversight. Personally, I use the rule, but it's probably too opinionated to be in the recommended configuration. (79b7bc0)

3.3.0 (2021-05-01)

Features

  • The no-internal rule now has a fixer. (dc480b2)

3.2.0 (2021-04-25)

Features

  • The no-ignored-subscribe and no-nested-subscribe rules now support types that implement Subscribable. (57f6e3f)

3.1.5 (2021-04-08)

Fixes

  • Match only subscribe calls that are nested in arguments. (0dc28aa)

3.1.4 (2021-04-05)

Fixes

  • Allow takeUntil after takeUntil. (d1a2549)

3.1.3 (2021-03-22)

Fixes

  • Set minimum eslint-etc version. (4fae336)

3.1.2 (2021-03-20)

Fixes

  • Enable TypeScript's strict option and fix related problems. (2bea9e0)

3.1.1 (2021-02-14)

Changes

  • Improve no-unsafe-takeuntil docs and fix failure message grammar. (e3e8fed)

3.1.0 (2021-02-13)

Features

  • Added a strict option to the finnish rule. (8bf0d1d)

3.0.1 (2021-02-03)

Fixes

  • Support arrow functions without parameter parentheses in no-implicit-any-catch. (37427ad)

3.0.0 (2021-01-30)

Breaking Changes

  • Check for an Observable type in no-implicit-any-catch - a breaking change because the previous version of this rule didn't require type information. (ebfb553)

Fixes

  • Check for an Observable type in prefer-observer. (30012be)

2.1.7 (2021-01-19)

Fixes

  • Don't insist on type references when checking for obserables. (521fe55)

2.1.6 (2021-01-11)

Changes

  • Fix GitHub URL for docs. (a238c2d)

2.1.5 (2020-11-28)

Changes

  • Use files in package.json instead of .npmignore. (99cb9ec)

2.1.4 (2020-11-21)

Fixes

  • Fixed a problem with no-cyclic-action when used with effects/epics that return Observable<void>. (79b9e82)

2.1.3 (2020-11-05)

Fixes

  • no-ignored-subscription should not effect failures for Subscriber instances passed to subscribe. (72e11ec)

2.1.2 (2020-11-03)

Changes

  • Use the public TypeScript API (getTypeArguments) to obtain the type arguments in the no-cyclic-action rule. (7f55bcb)

2.1.1 (2020-11-03)

Changes

  • Use the public TypeScript API (getTypeOfSymbolAtLocation) to obtain the action type in the no-cyclic-action rule. (56687db)

2.1.0 (2020-11-03)

Changes

  • Added the no-cyclic-action rule for effects and epics. (5e03092)

2.0.1 (2020-11-03)

Changes

  • Update rule metadata.

2.0.0 (2020-10-29)

Breaking Changes

  • no-implicit-any-catch is now enforced for error callbacks - and error methods on observers - passed to subscribe and tap, too. (1b9234b)

1.0.3 (2020-10-27)

Changes

  • Specify Node 10 as the minimum engines in package.json and downlevel to ES2018.

1.0.2 (2020-10-25)

Changes

  • Deprecate no-tap in favour of ban-operators. no-do/no-tap was an early TSLint rule and ban-operators is the preferred rule for banning operators as it allows a message to be specified.

1.0.1 (2020-10-23)

Changes

  • Specify engines in package.json.
  • Downlevel the TypeScript output to ES2019.