-
-
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.
feat(no-compat): Add no-compat rule.
- Loading branch information
Showing
5 changed files
with
94 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,47 @@ | ||
/** | ||
* @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"; | ||
import { tsquery } from "@phenomnomnominal/tsquery"; | ||
|
||
export class Rule extends Lint.Rules.AbstractRule { | ||
|
||
public static metadata: Lint.IRuleMetadata = { | ||
deprecationMessage: undefined, | ||
description: "Disallows importation from locations that depend upon 'rxjs-compat'.", | ||
options: null, | ||
optionsDescription: "Not configurable.", | ||
requiresTypeInfo: false, | ||
ruleName: "rxjs-no-compat", | ||
type: "functionality", | ||
typescriptOnly: false | ||
}; | ||
|
||
public static FAILURE_STRING = "'rxjs-compat' dependent import locations are forbidden"; | ||
|
||
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { | ||
const failures: Lint.RuleFailure[] = []; | ||
const importDeclarations = tsquery( | ||
sourceFile, | ||
`ImportDeclaration:has(StringLiteral[value=/^rxjs/])` | ||
); | ||
importDeclarations.forEach(node => { | ||
const importDeclaration = node as ts.ImportDeclaration; | ||
const { moduleSpecifier } = importDeclaration; | ||
if (!/^['"]rxjs(\/(ajax|operators|testing|webSocket))?['"]$/.test(moduleSpecifier.getText())) { | ||
failures.push(new Lint.RuleFailure( | ||
sourceFile, | ||
moduleSpecifier.getStart(), | ||
moduleSpecifier.getStart() + moduleSpecifier.getWidth(), | ||
Rule.FAILURE_STRING, | ||
this.ruleName | ||
)); | ||
} | ||
}); | ||
return failures; | ||
} | ||
} |
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,25 @@ | ||
import { Observable } from "rxjs"; | ||
import { ajax } from "rxjs/ajax"; | ||
import { concatMap } from "rxjs/operators"; | ||
import { TestScheduler } from "rxjs/testing"; | ||
import { webSocket } from "rxjs/webSocket"; | ||
|
||
import * as Rx from "rxjs/Rx"; | ||
~~~~~~~~~ [no-compat] | ||
import { Observable } from "rxjs/Observable"; | ||
~~~~~~~~~~~~~~~~~ [no-compat] | ||
import { Subject } from "rxjs/Subject"; | ||
~~~~~~~~~~~~~~ [no-compat] | ||
import { merge } from "rxjs/observable/merge"; | ||
~~~~~~~~~~~~~~~~~~~~~~~ [no-compat] | ||
import { mergeMap } from "rxjs/operator/mergeMap"; | ||
~~~~~~~~~~~~~~~~~~~~~~~~ [no-compat] | ||
import { asap } from "rxjs/scheduler/asap"; | ||
~~~~~~~~~~~~~~~~~~~~~ [no-compat] | ||
|
||
import "rxjs/add/observable/merge"; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [no-compat] | ||
import "rxjs/add/operator/mergeMap"; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [no-compat] | ||
|
||
[no-compat]: 'rxjs-compat' dependent import locations are forbidden |
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-compat": { "severity": "error" } | ||
}, | ||
"rulesDirectory": "../../../../../build/rules" | ||
} |