mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
chore: remove noRxjsPatchImportsRule (#10765)
This commit is contained in:
committed by
tinayuangao
parent
e60f5fc391
commit
c147f32f9a
@@ -126,21 +126,6 @@ class ConfigBuilder {
|
||||
}
|
||||
```
|
||||
|
||||
#### RxJS
|
||||
When dealing with RxJS operators, import the pipeable operator (e.g.
|
||||
`import {map} from 'rxjs/operators/map'`), as opposed to using the "patch" imports which pollute the
|
||||
user's global Observable object (e.g. `import 'rxjs/add/operator/map'`):
|
||||
|
||||
```ts
|
||||
// NO
|
||||
import 'rxjs/add/operator/map';
|
||||
someObservable.map(...).subscribe(...);
|
||||
|
||||
// YES
|
||||
import {map} from 'rxjs/operators/map';
|
||||
someObservable.pipe(map(...)).subscribe(...);
|
||||
```
|
||||
|
||||
#### Access modifiers
|
||||
* Omit the `public` keyword as it is the default behavior.
|
||||
* Use `private` when appropriate and possible, prefixing the name with an underscore.
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
import * as Lint from 'tslint';
|
||||
import * as minimatch from 'minimatch';
|
||||
|
||||
const ERROR_MESSAGE = 'Uses of RxJS patch imports are forbidden.';
|
||||
|
||||
/**
|
||||
* Rule that prevents uses of RxJS patch imports (e.g. `import 'rxjs/add/operator/map'`).
|
||||
* Supports whitelisting via `"no-patch-imports": [true, "\.spec\.ts$"]`.
|
||||
*/
|
||||
export class Rule extends Lint.Rules.AbstractRule {
|
||||
apply(sourceFile: ts.SourceFile) {
|
||||
return this.applyWithWalker(new Walker(sourceFile, this.getOptions()));
|
||||
}
|
||||
}
|
||||
|
||||
class Walker extends Lint.RuleWalker {
|
||||
|
||||
/** Whether the walker should check the current source file. */
|
||||
private _enabled: boolean;
|
||||
|
||||
constructor(sourceFile: ts.SourceFile, options: Lint.IOptions) {
|
||||
super(sourceFile, options);
|
||||
|
||||
// Globs that are used to determine which files to lint.
|
||||
const fileGlobs = options.ruleArguments || [];
|
||||
|
||||
// Relative path for the current TypeScript source file.
|
||||
const relativeFilePath = path.relative(process.cwd(), sourceFile.fileName);
|
||||
|
||||
// Whether the file should be checked at all.
|
||||
this._enabled = fileGlobs.some(p => minimatch(relativeFilePath, p));
|
||||
}
|
||||
|
||||
visitImportDeclaration(node: ts.ImportDeclaration) {
|
||||
// Walk through the imports and check if they start with `rxjs/add`.
|
||||
if (this._enabled && node.moduleSpecifier.getText().startsWith('rxjs/add', 1)) {
|
||||
this.addFailureAtNode(node, ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
super.visitImportDeclaration(node);
|
||||
}
|
||||
}
|
||||
@@ -109,10 +109,6 @@
|
||||
true,
|
||||
"src/+(lib|cdk|material-experimental|cdk-experimental|demo-app)/**/!(*.spec).ts"
|
||||
],
|
||||
"no-rxjs-patch-imports": [
|
||||
true,
|
||||
"src/+(lib|cdk|material-experimental|cdk-experimental)/**/*.ts"
|
||||
],
|
||||
"missing-rollup-globals": [
|
||||
true,
|
||||
"./tools/package-tools/rollup-globals.ts",
|
||||
|
||||
Reference in New Issue
Block a user