Skip to content

Commit

Permalink
Allow numbers in component names (Fixes #1) [publish]
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Nov 15, 2022
1 parent 2ccc3fd commit 1fa35f4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.3.1

Allow numbers in component names (Fixes #1)

## 0.3.0

Report an error when a file that contains components that can't be fast-refreshed because:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-react-refresh",
"version": "0.3.0",
"version": "0.3.1",
"license": "MIT",
"scripts": {
"build": "scripts/bundle.ts",
Expand Down
6 changes: 3 additions & 3 deletions src/only-export-components.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { TSESLint } from "@typescript-eslint/utils";
import { TSESTree } from "@typescript-eslint/types";

const possibleReactExportRE = /^[A-Z][a-zA-Z]*$/;
// Only letters, starts with uppercase and at least one lowercase
const possibleReactExportRE = /^[A-Z][a-zA-Z0-9]*$/;
// Starts with uppercase and at least one lowercase
// This can lead to some false positive (ex: `const CMS = () => <></>`)
// But allow to catch `export const CONSTANT = 3`
const strictReactExportRE = /^[A-Z][a-zA-Z]*[a-z]+[a-zA-Z]*$/;
const strictReactExportRE = /^[A-Z][a-zA-Z0-9]*[a-z]+[a-zA-Z0-9]*$/;

export const onlyExportComponents: TSESLint.RuleModule<
| "exportAll"
Expand Down
4 changes: 4 additions & 0 deletions src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const valid = [
name: "Direct export AF component",
code: "export const Foo = () => {};",
},
{
name: "Direct export AF component with number",
code: "export const Foo2 = () => {};",
},
{
name: "Export AF component",
code: "const Foo = () => {}; export { Foo };",
Expand Down

0 comments on commit 1fa35f4

Please sign in to comment.