Skip to content

Commit

Permalink
fix: check for default export
Browse files Browse the repository at this point in the history
See: #2
  • Loading branch information
uhyo committed Nov 13, 2022
1 parent 19e1c37 commit bf624d4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/__tests__/default-export.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { getESLintTester } from "./fixtures/eslint";

const tester = getESLintTester();

describe("default export", () => {
it("Cannot import a package-default-export from sub directory", async () => {
const result = await tester.lintFile("src/default-export/foo.ts");
expect(result).toMatchInlineSnapshot(`
Array [
Object {
"column": 8,
"endColumn": 12,
"endLine": 1,
"line": 1,
"message": "Cannot import a package-private export 'default'",
"messageId": "package",
"nodeType": "ImportDefaultSpecifier",
"ruleId": "import-access/jsdoc",
"severity": 2,
},
Object {
"column": 10,
"endColumn": 25,
"endLine": 4,
"line": 4,
"message": "Cannot import a package-private export 'default'",
"messageId": "package",
"nodeType": "ImportSpecifier",
"ruleId": "import-access/jsdoc",
"severity": 2,
},
]
`);
});
});
6 changes: 6 additions & 0 deletions src/__tests__/fixtures/project/src/default-export/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import bar1 from "./sub/bar";
import baz from "./sub/baz";

import { default as bar2 } from "./sub/bar";

console.log(bar1, bar2, baz);
4 changes: 4 additions & 0 deletions src/__tests__/fixtures/project/src/default-export/sub/bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* @package
*/
export default "I am bar";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "This is baz";
4 changes: 3 additions & 1 deletion src/utils/findExportableDeclaration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
isClassDeclaration,
isExportAssignment,
isExportDeclaration,
isFunctionDeclaration,
isInterfaceDeclaration,
Expand All @@ -19,7 +20,7 @@ export function findExportedDeclaration(node: Node) {
return;
}

if (isExportDeclaration(decl)) {
if (isExportDeclaration(decl) || isExportAssignment(decl)) {
return decl;
}

Expand All @@ -36,6 +37,7 @@ function findExportableDeclaration(node: Node) {
isClassDeclaration(node) ||
isVariableStatement(node) ||
isExportDeclaration(node) ||
isExportAssignment(node) ||
isTypeAliasDeclaration(node) ||
isInterfaceDeclaration(node)
) {
Expand Down

0 comments on commit bf624d4

Please sign in to comment.