Skip to content

Commit

Permalink
test(eslint-plugin): improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Aug 22, 2021
1 parent 0fa9b63 commit 2ff917f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
17 changes: 7 additions & 10 deletions packages/eslint-plugin/src/rules/no-restricted-imports.ts
Expand Up @@ -72,9 +72,6 @@ function isObjectOfPatterns(
function isOptionsArrayOfStringOrObject(
options: Options,
): options is ArrayOfStringOrObject {
if (options.length > 1) {
return true;
}
if (isObjectOfPaths(options[0])) {
return false;
}
Expand All @@ -85,12 +82,12 @@ function isOptionsArrayOfStringOrObject(
}

function getRestrictedPaths(options: Options): ArrayOfStringOrObject {
if (isObjectOfPaths(options[0])) {
return options[0].paths;
}
if (isOptionsArrayOfStringOrObject(options)) {
return options;
}
if (isObjectOfPaths(options[0])) {
return options[0].paths;
}
return [];
}

Expand Down Expand Up @@ -167,10 +164,10 @@ export default createRule<Options, MessageIds>({
}
},
ExportNamedDeclaration(node): void {
if (
node.exportKind === 'type' &&
node.source?.type === AST_NODE_TYPES.Literal
) {
if (node.source?.type !== AST_NODE_TYPES.Literal) {
return;
}
if (node.exportKind === 'type') {
const importSource = (node.source.value as string).trim();
if (
!isAllowedTypeImportPath(importSource) &&
Expand Down
18 changes: 18 additions & 0 deletions packages/eslint-plugin/tests/rules/no-restricted-imports.test.ts
Expand Up @@ -212,6 +212,14 @@ ruleTester.run('no-restricted-imports', rule, {
},
],
},
{
code: "export * from 'foo';",
options: ['import1'],
},
{
code: 'export { foo } from foo;',
options: ['import1', 'import2'],
},
],
invalid: [
{
Expand Down Expand Up @@ -520,5 +528,15 @@ ruleTester.run('no-restricted-imports', rule, {
},
],
},
{
code: "export * from 'import1';",
options: ['import1'],
errors: [
{
messageId: 'path',
type: AST_NODE_TYPES.ExportAllDeclaration,
},
],
},
],
});

0 comments on commit 2ff917f

Please sign in to comment.