-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @license Use of this source code is governed by an MIT-style license that | ||
* can be found in the LICENSE file at https://github.com/cartant/rxjs-tslint-rules | ||
*/ | ||
/*tslint:disable:no-use-before-declare*/ | ||
|
||
import * as Lint from "tslint"; | ||
import * as ts from "typescript"; | ||
|
||
export class Rule extends Lint.Rules.AbstractRule { | ||
public static metadata: Lint.IRuleMetadata = { | ||
deprecationMessage: undefined, | ||
description: "Disallows the importation from index modules.", | ||
options: null, | ||
optionsDescription: "Not configurable.", | ||
requiresTypeInfo: false, | ||
ruleName: "rxjs-no-index", | ||
type: "functionality", | ||
typescriptOnly: false | ||
}; | ||
|
||
public static FAILURE_STRING = | ||
"RxJS imports from index modules are forbidden"; | ||
|
||
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { | ||
return this.applyWithWalker(new Walker(sourceFile, this.getOptions())); | ||
} | ||
} | ||
|
||
class Walker extends Lint.RuleWalker { | ||
public visitImportDeclaration(node: ts.ImportDeclaration): void { | ||
const moduleSpecifier = node.moduleSpecifier.getText(); | ||
const match = moduleSpecifier.match(/^['"]rxjs(\/\w+)?\/index/); | ||
if (match) { | ||
this.addFailureAtNode( | ||
node.moduleSpecifier, | ||
"RxJS imports from index are forbidden - see https://github.com/ReactiveX/rxjs/issues/4230" | ||
); | ||
} | ||
super.visitImportDeclaration(node); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Observable } from "rxjs/index"; | ||
~~~~~~~~~~~~ [no-index] | ||
import { map } from "rxjs/operators/index"; | ||
~~~~~~~~~~~~~~~~~~~~~~ [no-index] | ||
import { TestScheduler } from "rxjs/testing/index"; | ||
~~~~~~~~~~~~~~~~~~~~ [no-index] | ||
import { WebSocketSubject } from "rxjs/webSocket/index"; | ||
~~~~~~~~~~~~~~~~~~~~~~ [no-index] | ||
|
||
[no-index]: RxJS imports from index are forbidden - see https://github.com/ReactiveX/rxjs/issues/4230 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"lib": ["es2015"], | ||
"noEmit": true, | ||
"paths": { | ||
"rxjs": ["../../node_modules/rxjs"] | ||
}, | ||
"skipLibCheck": true, | ||
"target": "es5" | ||
}, | ||
"include": ["fixture.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"defaultSeverity": "error", | ||
"jsRules": {}, | ||
"rules": { | ||
"rxjs-no-index": { "severity": "error" } | ||
}, | ||
"rulesDirectory": "../../../../../build/rules" | ||
} |