Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@angular-extensions/lint-rules
Advanced tools
Readme
https://github.com/angular-extensions/lint-rules
This repository offers some tslint rules useful for angular projects, see Rules.
npm install @angular-extensions/lint-rules --save-dev
@angular-extensions/lint-rules
to the extensions
list in your tslint.json
:
{
"extends": [
"tslint:recommended",
"@angular-extensions/lint-rules"
]
}
ng lint
The package includes the following rules:
Rule | Description | Details | Enabled by default? |
---|---|---|---|
angular-call-super-lifecycle-method-in-extended-class | Enforces the application to call parent lifecycle function e.g. super.ngOnDestroy() when using inheritance within an Angular component or directive. | Details | yes |
angular-rxjs-takeuntil-before-subscribe | Enforces the application of the takeUntil operator when calling of subscribe within an Angular component or directive. | Details | yes |
This rule tries to avoid memory leaks and other problems in angular components and directives by ensuring that
a life-cycle method, e.g. ngOnDestroy(){}
, overriding its parent implementation
must call the parent implementation with super.ngOnDestroy()
.
This should trigger an error:
class MyClass {
ngOnDestroy() {
const a = 5;
}
}
@Component({
selector: 'app-my'
})
class MyComponent2 extends MyClass {
ngOnDestroy() {
~~~~~~~~~~~ call to super.ngOnDestroy() is missing
const b = 6;
}
}
while this should be fine:
class MyClass {
ngOnDestroy() {
const a = 5;
}
}
@Component({
selector: 'app-my'
})
class MyComponent extends MyClass {
ngOnDestroy() {
super.ngOnDestroy();
const b = 6;
}
}
@Component({
selector: 'app-my2'
})
class MyComponent2 {
ngOnDestroy() {
const b = 6;
}
}
This rule tries to avoid memory leaks in angular components and directives when calling .subscribe()
without properly unsubscribing
by enforcing the application of the takeUntil(this.destroy$)
operator before the .subscribe()
as well as before certain operators (shareReplay
without refCount: true
)
and ensuring the component implements the ngOnDestroy
method invoking this.destroy$.next()
.
All classes with a @Component
or @Directive
decorator and all their parent classes will be checked.
This should trigger an error:
@Component({
selector: 'app-my',
template: '<div>{{k$ | async}}</div>'
})
class MyComponent {
~~~~~~~~~~~ component containing subscribe must implement the ngOnDestroy() method
k$ = a.pipe(shareReplay(1));
~~~~~~~~~~~~~~ the shareReplay operator used within a component must be preceded by takeUntil
someMethod() {
const e = a.pipe(switchMap(_ => b)).subscribe();
~~~~~~~~~ subscribe within a component must be preceded by takeUntil
}
}
while this should be fine:
@Component({
selector: 'app-my',
template: '<div>{{k$ | async}}</div>'
})
class MyComponent implements SomeInterface, OnDestroy {
private destroy$: Subject<void> = new Subject<void>();
k$ = a.pipe(takeUntil(this.destroy$), shareReplay(1));
someMethod() {
const e = a.pipe(switchMap(_ => b), takeUntil(this.destroy$)).subscribe();
}
ngOnDestroy() {
this.destroy$.next();
}
}
Note: this project is based on work in https://github.com/cartant/rxjs-tslint-rules/pull/107
Clone the repository and install the dependencies with npm install
.
Note: using the build artifacts with npm link
does not work correctly,
since there will be a mismatch between the typescript version used by the consumer code
and the typescript version used by the lint rules code.
To test the package in a project, run
npm run build
cd dist
npm install --production
Then copy the content of the /dist
folder (including the node_modules
folder) into node_modules/@angular-extensions/lint-rules
in the consumer project.
To publish the package, run
npm run publish-package
FAQs
tslint rules for angular projects
The npm package @angular-extensions/lint-rules receives a total of 672 weekly downloads. As such, @angular-extensions/lint-rules popularity was classified as not popular.
We found that @angular-extensions/lint-rules demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.