Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions source/rules/no-internal.ts
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/]"]: (
Copy link
Owner

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.

node: es.Literal
) => {
context.report({
messageId: "forbidden",
node
});
}
};
}
};

export = rule;
59 changes: 59 additions & 0 deletions tests/rules/no-internal.ts
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';`,
Copy link
Owner

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One for single quotes and the other one for double quotes.
In the tslint code the selector checked for quotes because it used the "raw" value of the import. We know check on the value (so without any quotes) so, this can indeed be removed 👍

Copy link
Owner

Choose a reason for hiding this comment

The 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
}
]
}
]
});