-
-
Notifications
You must be signed in to change notification settings - Fork 43
feat: add no-internal #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /** | ||
| * @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/eslint-plugin-rxjs | ||
| */ | ||
|
|
||
| import { Rule } from "eslint"; | ||
| import * as es from "estree"; | ||
|
|
||
| const rule: Rule.RuleModule = { | ||
| meta: { | ||
| docs: { | ||
| category: "RxJS", | ||
| description: "Disallows the importation of internals.", | ||
| recommended: true | ||
| }, | ||
| fixable: null, | ||
| messages: { | ||
| forbidden: "RxJS imports from internal are forbidden." | ||
| }, | ||
| schema: [] | ||
| }, | ||
| create: context => { | ||
| return { | ||
| ["ImportDeclaration Literal[value=/^rxjs\\u002finternal/]"]: ( | ||
| node: es.Literal | ||
| ) => { | ||
| context.report({ | ||
| messageId: "forbidden", | ||
| node | ||
| }); | ||
| } | ||
| }; | ||
| } | ||
| }; | ||
|
|
||
| export = rule; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /** | ||
| * @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/eslint-plugin-rxjs | ||
| */ | ||
|
|
||
| import { stripIndent } from "common-tags"; | ||
| import rule = require("../../source/rules/no-internal"); | ||
| import { ruleTester } from "../utils"; | ||
|
|
||
| ruleTester({ types: false }).run("no-internal", rule, { | ||
| valid: [ | ||
| `import { Observable } from "rxjs";`, | ||
| `import { map } from "rxjs/operators";` | ||
| ], | ||
| invalid: [ | ||
| { | ||
| code: stripIndent` | ||
| import { concat } from "rxjs/internal/observable/concat"; | ||
| import { map } from "rxjs/internal/operators/map";`, | ||
| errors: [ | ||
| { | ||
| messageId: "forbidden", | ||
| line: 1, | ||
| column: 24, | ||
| endLine: 1, | ||
| endColumn: 57 | ||
| }, | ||
| { | ||
| messageId: "forbidden", | ||
| line: 2, | ||
| column: 21, | ||
| endLine: 2, | ||
| endColumn: 50 | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| code: stripIndent` | ||
| import { concat } from 'rxjs/internal/observable/concat'; | ||
| import { map } from 'rxjs/internal/operators/map';`, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this test identical to the one above? Did you intend to split the the two imports into two tests, so that each test includes only a single import?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One for single quotes and the other one for double quotes.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🙈 |
||
| errors: [ | ||
| { | ||
| messageId: "forbidden", | ||
| line: 1, | ||
| column: 24, | ||
| endLine: 1, | ||
| endColumn: 57 | ||
| }, | ||
| { | ||
| messageId: "forbidden", | ||
| line: 2, | ||
| column: 21, | ||
| endLine: 2, | ||
| endColumn: 50 | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow. I love this!!! I don't think it needs to be a computed property though. A quoted key should be fine, AFAICT.