Skip to content

Commit

Permalink
Support export const foo = -1 with allowConstantExport (fixes #43)…
Browse files Browse the repository at this point in the history
… [publish]
  • Loading branch information
ArnaudBarre committed Jul 9, 2024
1 parent 70dcd5a commit a10b96b
Show file tree
Hide file tree
Showing 4 changed files with 14 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.4.8

- Support `export const foo = -1` with `allowConstantExport` (fixes #43)

## 0.4.7

- Support `export { Component as default }` (fixes #41)
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.4.7",
"version": "0.4.8",
"type": "module",
"license": "MIT",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions src/only-export-components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ const valid = [
code: "export const foo = 4; export const Bar = () => {};",
options: [{ allowConstantExport: true }],
},
{
name: "Component and negative number constant with allowConstantExport",
code: "export const foo = -4; export const Bar = () => {};",
options: [{ allowConstantExport: true }],
},
{
name: "Component and string constant with allowConstantExport",
code: "export const CONSTANT = 'Hello world'; export const Foo = () => {};",
Expand Down
7 changes: 4 additions & 3 deletions src/only-export-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ export const onlyExportComponents: TSESLint.RuleModule<
if (
allowConstantExport &&
init &&
(init.type === "Literal" ||
init.type === "TemplateLiteral" ||
init.type === "BinaryExpression")
(init.type === "Literal" || // 1, "foo"
init.type === "UnaryExpression" || // -1
init.type === "TemplateLiteral" || // `Some ${template}`
init.type === "BinaryExpression") // 24 * 60
) {
return;
}
Expand Down

0 comments on commit a10b96b

Please sign in to comment.