Skip to content

Commit a10b96b

Browse files
committed
Support export const foo = -1 with allowConstantExport (fixes #43) [publish]
1 parent 70dcd5a commit a10b96b

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

CHANGELOG.md

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

3+
## 0.4.8
4+
5+
- Support `export const foo = -1` with `allowConstantExport` (fixes #43)
6+
37
## 0.4.7
48

59
- Support `export { Component as default }` (fixes #41)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-react-refresh",
3-
"version": "0.4.7",
3+
"version": "0.4.8",
44
"type": "module",
55
"license": "MIT",
66
"scripts": {

src/only-export-components.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ const valid = [
110110
code: "export const foo = 4; export const Bar = () => {};",
111111
options: [{ allowConstantExport: true }],
112112
},
113+
{
114+
name: "Component and negative number constant with allowConstantExport",
115+
code: "export const foo = -4; export const Bar = () => {};",
116+
options: [{ allowConstantExport: true }],
117+
},
113118
{
114119
name: "Component and string constant with allowConstantExport",
115120
code: "export const CONSTANT = 'Hello world'; export const Foo = () => {};",

src/only-export-components.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ export const onlyExportComponents: TSESLint.RuleModule<
102102
if (
103103
allowConstantExport &&
104104
init &&
105-
(init.type === "Literal" ||
106-
init.type === "TemplateLiteral" ||
107-
init.type === "BinaryExpression")
105+
(init.type === "Literal" || // 1, "foo"
106+
init.type === "UnaryExpression" || // -1
107+
init.type === "TemplateLiteral" || // `Some ${template}`
108+
init.type === "BinaryExpression") // 24 * 60
108109
) {
109110
return;
110111
}

0 commit comments

Comments
 (0)