Skip to content

Commit 26b3c15

Browse files
committed
Support false positives with TypeScript function overloading (fixes #105)
1 parent daa2efb commit 26b3c15

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Support false positives with TypeScript function overloading (fixes [#105](https://github.com/ArnaudBarre/eslint-plugin-react-refresh/issues/105))
6+
37
## 0.5.0
48

59
### Breaking changes

src/only-export-components.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ const valid: {
275275
name: "Export default class component",
276276
code: "export default class MyComponent extends Component { render() { return <div>Hello</div>; } }",
277277
},
278+
{
279+
name: "Direct export uppercase function",
280+
code: `export function Button(props: PropsWithChildren<{ onClick: () => void }>): ReactNode;
281+
export function Button(props: PropsWithChildren): ReactNode {
282+
return <button {...props}>{props.children}</button>;
283+
}`,
284+
},
278285
];
279286

280287
const invalid: {

src/only-export-components.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,13 @@ export const onlyExportComponents: TSESLint.RuleModule<
297297
}
298298
} else if (node.type === "ExportNamedDeclaration") {
299299
if (node.exportKind === "type") continue;
300+
const declaration = node.declaration
301+
? skipTSWrapper(node.declaration)
302+
: null;
303+
if (declaration?.type === "TSDeclareFunction") continue;
300304
hasExports = true;
301-
if (node.declaration) {
302-
handleExportDeclaration(skipTSWrapper(node.declaration));
305+
if (declaration) {
306+
handleExportDeclaration(declaration);
303307
}
304308
for (const specifier of node.specifiers) {
305309
handleExportIdentifier(

0 commit comments

Comments
 (0)