Have ideas to improve npm?Join in the discussion! »

eslint-plugin-rxjs

2.1.6 • Public • Published

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:

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

Install

npm i eslint-plugin-rxjs

DownloadsWeekly Downloads

25,192

Version

2.1.6

License

MIT

Unpacked Size

142 kB

Total Files

88

Last publish

Collaborators

  • avatar