Skip to content

Commit

Permalink
Support type assertion on default export (fixes #48) [publish]
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Sep 14, 2024
1 parent f6dbb3a commit 78f987f
Show file tree
Hide file tree
Showing 6 changed files with 455 additions and 420 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog

## Unreleased
## 4.0.12

- Support type assertion on default export (fixes #48)
- Add default export to fix usage with jiti (fixes #50)

## 0.4.11
Expand Down
Binary file modified bun.lockb
Binary file not shown.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
"scripts": {
"build": "scripts/bundle.ts",
"test": "bun test",
"lint": "bun lint-ci --fix --cache",
"lint-ci": "eslint ./ --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint": "eslint ./ --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"prettier": "bun prettier-ci --write",
"prettier-ci": "prettier --ignore-path=.gitignore --check '**/*.{ts,json,md,yml}'",
"ci": "tsc && bun lint-ci && bun prettier-ci && bun test && bun run build"
"ci": "tsc && bun lint && bun prettier-ci && bun test && bun run build"
},
"prettier": {},
"peerDependencies": {
"eslint": ">=7"
},
"devDependencies": {
"@arnaud-barre/eslint-config": "^4.0.0",
"@arnaud-barre/eslint-config": "^4.1.1",
"@arnaud-barre/tnode": "^0.19.2",
"@types/eslint": "^8.44.8",
"@types/node": "^20.10.2",
"@typescript-eslint/parser": "^6.13.1",
"@typescript-eslint/utils": "^6.13.1",
"bun-types": "^1.0.15",
"eslint": "^8.55.0",
"@typescript-eslint/parser": "^7.18.0",
"@typescript-eslint/utils": "^7.18.0",
"bun-types": "^1.1.27",
"eslint": "^8.57.0",
"prettier": "3.0.3",
"typescript": "~5.3"
"typescript": "~5.4"
}
}
4 changes: 4 additions & 0 deletions src/only-export-components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ const valid = [
name: "export default React.memo function declaration",
code: "function Foo() {}; export default React.memo(Foo);",
},
{
name: "export default React.memo function declaration with type assertion",
code: "function Foo() {}; export default React.memo(Foo) as typeof Foo;",
},
{
name: "export type *",
code: "export type * from './module';",
Expand Down
19 changes: 12 additions & 7 deletions src/only-export-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,22 @@ export const onlyExportComponents: TSESLint.RuleModule<
context.report({ messageId: "exportAll", node });
} else if (node.type === "ExportDefaultDeclaration") {
hasExports = true;
const declaration =
node.declaration.type === "TSAsExpression" ||
node.declaration.type === "TSSatisfiesExpression"
? node.declaration.expression
: node.declaration;
if (
node.declaration.type === "VariableDeclaration" ||
node.declaration.type === "FunctionDeclaration" ||
node.declaration.type === "CallExpression"
declaration.type === "VariableDeclaration" ||
declaration.type === "FunctionDeclaration" ||
declaration.type === "CallExpression"
) {
handleExportDeclaration(node.declaration);
handleExportDeclaration(declaration);
}
if (node.declaration.type === "Identifier") {
handleExportIdentifier(node.declaration);
if (declaration.type === "Identifier") {
handleExportIdentifier(declaration);
}
if (node.declaration.type === "ArrowFunctionExpression") {
if (declaration.type === "ArrowFunctionExpression") {
context.report({ messageId: "anonymousExport", node });
}
} else if (node.type === "ExportNamedDeclaration") {
Expand Down
Loading

0 comments on commit 78f987f

Please sign in to comment.