Skip to content

Commit

Permalink
Support for Arbitrary Module Identifiers syntax (fixes #52) [publish]
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Oct 19, 2024
1 parent cb7cecd commit 268df3b
Show file tree
Hide file tree
Showing 8 changed files with 332 additions and 376 deletions.
4 changes: 0 additions & 4 deletions .eslintrc.cjs

This file was deleted.

3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changelog

## Unreleased
## 0.4.13

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

## 0.4.12

Expand Down
Binary file modified bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import baseConfig from "@arnaud-barre/eslint-config";

export default baseConfig;
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"name": "eslint-plugin-react-refresh",
"version": "0.4.12",
"version": "0.4.13",
"type": "module",
"license": "MIT",
"scripts": {
"build": "scripts/bundle.ts",
"test": "bun test",
"lint": "eslint ./ --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint": "bun --bun eslint . --max-warnings 0",
"prettier": "bun prettier-ci --write",
"prettier-ci": "prettier --ignore-path=.gitignore --check '**/*.{ts,json,md,yml}'",
"prettier-ci": "prettier --ignore-path=.gitignore --check '**/*.{js,ts,json,md,yml}'",
"ci": "tsc && bun lint && bun prettier-ci && bun test && bun run build"
},
"prettier": {},
"peerDependencies": {
"eslint": ">=7"
},
"devDependencies": {
"@arnaud-barre/eslint-config": "^4.1.1",
"@arnaud-barre/eslint-config": "^5.0.1",
"@arnaud-barre/tnode": "^0.19.2",
"@types/eslint": "^8.44.8",
"@types/node": "^20.10.2",
"@typescript-eslint/parser": "^7.18.0",
"@typescript-eslint/utils": "^7.18.0",
"bun-types": "^1.1.27",
"eslint": "^8.57.0",
"@types/eslint": "^9.6.1",
"@types/node": "^20.16.13",
"@typescript-eslint/parser": "^8.10.0",
"@typescript-eslint/utils": "^8.10.0",
"bun-types": "^1.1.31",
"eslint": "^9.13.0",
"prettier": "3.0.3",
"typescript": "~5.4"
"typescript": "~5.6"
}
}
15 changes: 7 additions & 8 deletions src/only-export-components.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
#!/usr/bin/env tnode
import { test } from "bun:test";
import parser from "@typescript-eslint/parser";
import { RuleTester } from "eslint";
import { onlyExportComponents } from "./only-export-components.ts";

const ruleTester = new RuleTester({
parser: require.resolve("@typescript-eslint/parser"),
parserOptions: {
sourceType: "module",
ecmaVersion: 2022,
ecmaFeatures: { jsx: true },
},
});
const ruleTester = new RuleTester({ languageOptions: { parser } });

const valid = [
{
Expand Down Expand Up @@ -274,6 +268,11 @@ const invalid = [
options: [{ allowExportNames: ["loader", "meta"] }],
errorId: "namedExport",
},
{
name: "Export with arbitrary module identifier",
code: 'const Foo = () => {}; export { Foo as "🍌"}',
errorId: "localComponents",
},
];

const it = (name: string, cases: Parameters<typeof ruleTester.run>[2]) => {
Expand Down
10 changes: 7 additions & 3 deletions src/only-export-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export const onlyExportComponents: TSESLint.RuleModule<
let mayHaveReactExport = false;
let reactIsInScope = false;
const localComponents: TSESTree.Identifier[] = [];
const nonComponentExports: TSESTree.BindingName[] = [];
const nonComponentExports: (
| TSESTree.BindingName
| TSESTree.StringLiteral
)[] = [];

const handleLocalIdentifier = (
identifierNode: TSESTree.BindingName,
Expand All @@ -94,7 +97,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
};

const handleExportIdentifier = (
identifierNode: TSESTree.BindingName,
identifierNode: TSESTree.BindingName | TSESTree.StringLiteral,
isFunction?: boolean,
init?: TSESTree.Expression | null,
) => {
Expand Down Expand Up @@ -232,7 +235,8 @@ export const onlyExportComponents: TSESLint.RuleModule<
if (node.declaration) handleExportDeclaration(node.declaration);
for (const specifier of node.specifiers) {
handleExportIdentifier(
specifier.exported.name === "default"
specifier.exported.type === "Identifier" &&
specifier.exported.name === "default"
? specifier.local
: specifier.exported,
);
Expand Down
Loading

0 comments on commit 268df3b

Please sign in to comment.