Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-rxjs-angular

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-rxjs-angular - npm Package Compare versions

Comparing version 0.0.2-beta.6 to 1.0.0

1

.eslintrc.json

@@ -9,3 +9,2 @@ {

},
"plugins": ["@typescript-eslint", "import"],
"root": true,

@@ -12,0 +11,0 @@ "rules": {

2

dist/rules/prefer-takeuntil.js

@@ -7,3 +7,3 @@ "use strict";

noDestroy: "`ngOnDestroy` is not implemented.",
noTakeUntil: "Calling `subscribe` without an accompanying `takeUntil` is forbidden.",
noTakeUntil: "Forbids calling `subscribe` without an accompanying `takeUntil`.",
notCalled: "`{{name}}.{{method}}()` not called.",

@@ -10,0 +10,0 @@ notDeclared: "Subject `{{name}}` not a class property.",

@@ -1,3 +0,11 @@

# prefer-async-pipe
# Use container components and async pipe (`prefer-async-pipe`)
TK
This rule effects failures if explicit calls to `subscribe` are made within a component. Instead, use a child component to which a value is passed by using te async pipe in the parent component's template.
## Options
This rule has no options.
## Further reading
- [Connecting Components with Reactive Forms](https://ncjamieson.com/connecting-components-with-reactive-forms/)

@@ -1,3 +0,64 @@

# prefer-composition
# Use subscription composition (`prefer-composition`)
TK
This rule effects failures if `subscribe` calls are made with a component and the returned subscription is not composed into a subscription that is unsubscribed when the component is destroyed.
## Rule details
Examples of **incorrect** code for this rule:
```ts
import { Component, OnDestroy, OnInit } from "@angular/core";
import { Subscription } from "rxjs";
@Component({
selector: "some-component",
template: "<span>{{ value }}</span>"
})
export class SomeComponent implements OnInit {
value: string;
// ...
ngOnInit() {
this.values.subscribe(value => this.value = value);
}
}
```
Examples of **correct** code for this rule:
```ts
import { Component, OnDestroy, OnInit } from "@angular/core";
import { Subscription } from "rxjs";
@Component({
selector: "some-component",
template: "<span>{{ value }}</span>"
})
export class SomeComponent implements OnInit, OnDestroy {
value: string;
private subscription = new Subscription();
// ...
ngOnInit() {
this.subscription.add(this.values.subscribe(value => this.value = value));
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
}
```
## Options
This rule accepts a single option which is an object with a `checkDecorators` property which is an array containing the names of the decorators that determine whether or not a class is checked. By default, `checkDecorators` is `["Component"]`.
```json
{
"rxjs/prefer-composition": [
"error",
{ "checkDecorators": ["Component"] }
]
}
```
## Further reading
- [Composing Subscriptions](https://ncjamieson.com/composing-subscriptions/)

@@ -1,3 +0,77 @@

# prefer-takeuntil
# Use `takeUntil` and `ngOnDestroy` (`prefer-takeuntil`)
TK
This rule effects failures if `subscribe` is called within a component and the `takeUntil`-destroyed pattern is not used.
## Rule details
Examples of **incorrect** code for this rule:
```ts
import { Component, OnInit } from "@angular/core";
import { switchMap } from "rxjs/operators";
@Component({
selector: "some-component"
})
class SomeComponent implements OnInit {
// ...
ngOnInit() {
this.values.pipe(
switchMap((value) => something(value))
).subscribe();
}
}
```
Examples of **correct** code for this rule:
```ts
import { Component, OnDestroy, OnInit } from "@angular/core";
import { switchMap } from "rxjs/operators";
@Component({
selector: "some-component"
})
class SomeComponent implements OnDestroy, OnInit {
private destroy = new Subject<void>();
// ...
ngOnInit() {
this.values.pipe(
switchMap((value) => something(value)),
takeUntil(this.destroy)
).subscribe();
}
ngOnDestroy() {
this.destroy.next();
this.destroy.complete();
}
}
```
## Options
This rule accepts a single option which is an object with `checkComplete`, `checkDecorators`, `checkDestroy` and `alias` properties.
The `checkComplete` property is a boolean that determines whether or not `complete` must be called after `next` and the `checkDestroy` property is a boolean that determines whether or not a `Subject`-based `ngOnDestroy` must be implemented.
The `checkDecorators` property is an array containing the names of the decorators that determine whether or not a class is checked. By default, `checkDecorators` is `["Component"]`.
The `alias` property is an array of names of operators that should be treated similarly to `takeUntil`.
```json
{
"rxjs/prefer-composition": [
"error",
{
"alias": ["untilDestroyed"],
"checkComplete": true,
"checkDecorators": ["Component"],
"checkDestroy": true
}
]
}
```
## Further reading
- [Avoiding takeUntil leaks](https://ncjamieson.com/avoiding-takeuntil-leaks/)

@@ -15,3 +15,3 @@ {

"devDependencies": {
"@cartant/eslint-config": "^1.0.0",
"@cartant/eslint-config": "^2.0.0",
"@types/chai": "^4.2.0",

@@ -22,7 +22,5 @@ "@types/common-tags": "^1.8.0",

"@types/node": "^14.0.0",
"@typescript-eslint/eslint-plugin": "^4.0.0",
"@typescript-eslint/parser": "^4.0.0",
"chai": "^4.2.0",
"eslint": "^7.0.0",
"eslint-plugin-import": "^2.20.2",
"husky": "^4.0.0",

@@ -80,3 +78,3 @@ "lint-staged": "^10.1.1",

},
"version": "0.0.2-beta.6"
"version": "1.0.0"
}
# eslint-plugin-rxjs-angular
This repo is a WIP.
[![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/cartant/eslint-plugin-rxjs-angular/blob/master/LICENSE)
[![NPM version](https://img.shields.io/npm/v/eslint-plugin-rxjs-angular.svg)](https://www.npmjs.com/package/eslint-plugin-rxjs-angular)
[![Downloads](http://img.shields.io/npm/dm/eslint-plugin-rxjs-angular.svg)](https://npmjs.org/package/eslint-plugin-rxjs-angular)
[![Build status](https://img.shields.io/circleci/build/github/cartant/eslint-plugin-rxjs-angular?token=d3e3fd6613244558287da156fd9e0c4357a2170c)](https://app.circleci.com/pipelines/github/cartant)
[![dependency status](https://img.shields.io/david/cartant/eslint-plugin-rxjs-angular.svg)](https://david-dm.org/cartant/eslint-plugin-rxjs-angular)
[![devDependency Status](https://img.shields.io/david/dev/cartant/eslint-plugin-rxjs-angular.svg)](https://david-dm.org/cartant/eslint-plugin-rxjs-angular#info=devDependencies)
[![peerDependency Status](https://img.shields.io/david/peer/cartant/eslint-plugin-rxjs-angular.svg)](https://david-dm.org/cartant/eslint-plugin-rxjs-angular#info=peerDependencies)
Eventually, it will contain ESLint versions of the Angular rules in the [`rxjs-tslint-rules`](https://github.com/cartant/rxjs-tslint-rules) package.
This package contains ESLint versions of the Angular/RxJS rules that are in the [`rxjs-tslint-rules`](https://github.com/cartant/rxjs-tslint-rules) package.
There is no recommended configuration for this package, as all of the rules are opinionated.
# Install

@@ -46,4 +54,4 @@

| --- | --- | --- |
| [`prefer-async-pipe`](https://github.com/cartant/eslint-plugin-rxjs-angular/blob/main/source/rules/prefer-async-pipe.ts) | Forbids the calling of `subscribe` within Angular components. | TBD |
| [`prefer-composition`](https://github.com/cartant/eslint-plugin-rxjs-angular/blob/main/source/rules/prefer-composition.ts) | Not yet implemented. | TBD |
| [`prefer-takeuntil`](https://github.com/cartant/eslint-plugin-rxjs-angular/blob/main/source/rules/prefer-takeuntil.ts) | Not yet implemented. | TBD |
| [`prefer-async-pipe`](https://github.com/cartant/eslint-plugin-rxjs-angular/blob/main/docs/rules/prefer-async-pipe.md) | Forbids the calling of `subscribe` within Angular components. | No |
| [`prefer-composition`](https://github.com/cartant/eslint-plugin-rxjs-angular/blob/main/docs/rules/prefer-composition.md) | Forbids `subscribe` calls that are not composed within Angular components (and, optionally, within services, directives, and pipes). | No |
| [`prefer-takeuntil`](https://github.com/cartant/eslint-plugin-rxjs-angular/blob/main/docs/rules/prefer-takeuntil.md) | Forbids Calling `subscribe` without an accompanying `takeUntil`. | No |
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc