From c147f32f9a107dc067ed97a6b1d104c78b8bde13 Mon Sep 17 00:00:00 2001 From: Rafael Santana Date: Tue, 10 Apr 2018 15:06:51 -0300 Subject: [PATCH] chore: remove noRxjsPatchImportsRule (#10765) --- CODING_STANDARDS.md | 15 ------- tools/tslint-rules/noRxjsPatchImportsRule.ts | 44 -------------------- tslint.json | 4 -- 3 files changed, 63 deletions(-) delete mode 100644 tools/tslint-rules/noRxjsPatchImportsRule.ts diff --git a/CODING_STANDARDS.md b/CODING_STANDARDS.md index 46864971d97..f7b79fd4236 100644 --- a/CODING_STANDARDS.md +++ b/CODING_STANDARDS.md @@ -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. diff --git a/tools/tslint-rules/noRxjsPatchImportsRule.ts b/tools/tslint-rules/noRxjsPatchImportsRule.ts deleted file mode 100644 index fdaa9421827..00000000000 --- a/tools/tslint-rules/noRxjsPatchImportsRule.ts +++ /dev/null @@ -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); - } -} diff --git a/tslint.json b/tslint.json index 5527f78619b..dcedaa2bdd6 100644 --- a/tslint.json +++ b/tslint.json @@ -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",