diff --git a/docs/rules/button-has-type.md b/docs/rules/button-has-type.md
index 7708f9eb1d..63a6038e29 100644
--- a/docs/rules/button-has-type.md
+++ b/docs/rules/button-has-type.md
@@ -10,6 +10,7 @@ The following patterns are considered errors:
```jsx
var Hello =
var Hello =
+var Hello =
var Hello = React.createElement('button', {}, 'Hello')
var Hello = React.createElement('button', {type: 'foo'}, 'Hello')
diff --git a/lib/rules/button-has-type.js b/lib/rules/button-has-type.js
index a7d4694b77..b6b86bbb2a 100644
--- a/lib/rules/button-has-type.js
+++ b/lib/rules/button-has-type.js
@@ -72,8 +72,8 @@ module.exports = {
});
}
- function checkValue(node, value, quoteFn) {
- const q = quoteFn || (x => `"${x}"`);
+ function checkValue(node, value) {
+ const q = x => `"${x}"`;
if (!(value in configuration)) {
context.report({
node,
@@ -100,12 +100,16 @@ module.exports = {
return;
}
- const propValue = getLiteralPropValue(typeProp);
- if (!propValue && typeProp.value && typeProp.value.expression) {
- checkValue(node, typeProp.value.expression.name, x => `\`${x}\``);
- } else {
- checkValue(node, propValue);
+ if (typeProp.value.type === 'JSXExpressionContainer') {
+ context.report({
+ node: typeProp,
+ message: 'The button type attribute must be specified by a static string'
+ });
+ return;
}
+
+ const propValue = getLiteralPropValue(typeProp);
+ checkValue(node, propValue);
},
CallExpression(node) {
if (!isCreateElement(node, context)) {
diff --git a/tests/lib/rules/button-has-type.js b/tests/lib/rules/button-has-type.js
index 948626ec42..15e5257c24 100644
--- a/tests/lib/rules/button-has-type.js
+++ b/tests/lib/rules/button-has-type.js
@@ -73,7 +73,13 @@ ruleTester.run('button-has-type', rule, {
{
code: '