Skip to content

Commit 268df3b

Browse files
committed
Support for Arbitrary Module Identifiers syntax (fixes #52) [publish]
1 parent cb7cecd commit 268df3b

8 files changed

+332
-376
lines changed

.eslintrc.cjs

-4
This file was deleted.

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Changelog
22

3-
## Unreleased
3+
## 0.4.13
44

55
- Support for `react-redux` connect (`export default connect(mapStateToProps, mapDispatchToProps)(MyComponent)`) (fixes #51)
6+
- Support for [Arbitrary Module Identifiers](https://devblogs.microsoft.com/typescript/announcing-typescript-5-6/#support-for-arbitrary-module-identifiers) syntax (fixes #52)
67

78
## 0.4.12
89

bun.lockb

-1.93 KB
Binary file not shown.

eslint.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import baseConfig from "@arnaud-barre/eslint-config";
2+
3+
export default baseConfig;

package.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
{
22
"name": "eslint-plugin-react-refresh",
3-
"version": "0.4.12",
3+
"version": "0.4.13",
44
"type": "module",
55
"license": "MIT",
66
"scripts": {
77
"build": "scripts/bundle.ts",
88
"test": "bun test",
9-
"lint": "eslint ./ --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
9+
"lint": "bun --bun eslint . --max-warnings 0",
1010
"prettier": "bun prettier-ci --write",
11-
"prettier-ci": "prettier --ignore-path=.gitignore --check '**/*.{ts,json,md,yml}'",
11+
"prettier-ci": "prettier --ignore-path=.gitignore --check '**/*.{js,ts,json,md,yml}'",
1212
"ci": "tsc && bun lint && bun prettier-ci && bun test && bun run build"
1313
},
1414
"prettier": {},
1515
"peerDependencies": {
1616
"eslint": ">=7"
1717
},
1818
"devDependencies": {
19-
"@arnaud-barre/eslint-config": "^4.1.1",
19+
"@arnaud-barre/eslint-config": "^5.0.1",
2020
"@arnaud-barre/tnode": "^0.19.2",
21-
"@types/eslint": "^8.44.8",
22-
"@types/node": "^20.10.2",
23-
"@typescript-eslint/parser": "^7.18.0",
24-
"@typescript-eslint/utils": "^7.18.0",
25-
"bun-types": "^1.1.27",
26-
"eslint": "^8.57.0",
21+
"@types/eslint": "^9.6.1",
22+
"@types/node": "^20.16.13",
23+
"@typescript-eslint/parser": "^8.10.0",
24+
"@typescript-eslint/utils": "^8.10.0",
25+
"bun-types": "^1.1.31",
26+
"eslint": "^9.13.0",
2727
"prettier": "3.0.3",
28-
"typescript": "~5.4"
28+
"typescript": "~5.6"
2929
}
3030
}

src/only-export-components.test.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
#!/usr/bin/env tnode
22
import { test } from "bun:test";
3+
import parser from "@typescript-eslint/parser";
34
import { RuleTester } from "eslint";
45
import { onlyExportComponents } from "./only-export-components.ts";
56

6-
const ruleTester = new RuleTester({
7-
parser: require.resolve("@typescript-eslint/parser"),
8-
parserOptions: {
9-
sourceType: "module",
10-
ecmaVersion: 2022,
11-
ecmaFeatures: { jsx: true },
12-
},
13-
});
7+
const ruleTester = new RuleTester({ languageOptions: { parser } });
148

159
const valid = [
1610
{
@@ -274,6 +268,11 @@ const invalid = [
274268
options: [{ allowExportNames: ["loader", "meta"] }],
275269
errorId: "namedExport",
276270
},
271+
{
272+
name: "Export with arbitrary module identifier",
273+
code: 'const Foo = () => {}; export { Foo as "🍌"}',
274+
errorId: "localComponents",
275+
},
277276
];
278277

279278
const it = (name: string, cases: Parameters<typeof ruleTester.run>[2]) => {

src/only-export-components.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ export const onlyExportComponents: TSESLint.RuleModule<
8282
let mayHaveReactExport = false;
8383
let reactIsInScope = false;
8484
const localComponents: TSESTree.Identifier[] = [];
85-
const nonComponentExports: TSESTree.BindingName[] = [];
85+
const nonComponentExports: (
86+
| TSESTree.BindingName
87+
| TSESTree.StringLiteral
88+
)[] = [];
8689

8790
const handleLocalIdentifier = (
8891
identifierNode: TSESTree.BindingName,
@@ -94,7 +97,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
9497
};
9598

9699
const handleExportIdentifier = (
97-
identifierNode: TSESTree.BindingName,
100+
identifierNode: TSESTree.BindingName | TSESTree.StringLiteral,
98101
isFunction?: boolean,
99102
init?: TSESTree.Expression | null,
100103
) => {
@@ -232,7 +235,8 @@ export const onlyExportComponents: TSESLint.RuleModule<
232235
if (node.declaration) handleExportDeclaration(node.declaration);
233236
for (const specifier of node.specifiers) {
234237
handleExportIdentifier(
235-
specifier.exported.name === "default"
238+
specifier.exported.type === "Identifier" &&
239+
specifier.exported.name === "default"
236240
? specifier.local
237241
: specifier.exported,
238242
);

0 commit comments

Comments
 (0)