Skip to content

Commit 9356230

Browse files
meowtecljharb
authored andcommitted
[Fix] button-has-type: fix exception for <button type>
1 parent 46ce117 commit 9356230

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1919
* [`no-unused-state`]: avoid a crash ([#3258][] @WillyLiaoWH @ljharb)
2020
* [`jsx-no-useless-fragment`]: use proper apostrophe in error message ([#3266][] @develohpanda)
2121
* `propTypes`: handle imported types/interface in forwardRef generic ([#3280][] @vedadeepta)
22+
* [`button-has-type`]: fix exception for `<button type>` ([#3255][] @meowtec)
2223

2324
### Changed
2425
* [readme] remove global usage and eslint version from readme ([#3254][] @aladdin-add)
@@ -48,6 +49,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
4849
[#3260]: https://github.jsx-eslintckcr/eslint-plugin-react/pull/3260
4950
[#3259]: https://githubjsx-eslintickcr/eslint-plugin-react/pull/3259
5051
[#3258]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3258
52+
[#3255]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3255
5153
[#3254]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3254
5254
[#3251]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3251
5355
[#3249]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3249

lib/rules/button-has-type.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ module.exports = {
126126
return;
127127
}
128128

129-
if (typeProp.value.type === 'JSXExpressionContainer') {
129+
if (typeProp.value && typeProp.value.type === 'JSXExpressionContainer') {
130130
checkExpression(node, typeProp.value.expression);
131131
return;
132132
}

tests/lib/rules/button-has-type.js

+9
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ ruleTester.run('button-has-type', rule, {
179179
},
180180
],
181181
},
182+
{
183+
code: '<button type/>',
184+
errors: [
185+
{
186+
messageId: 'invalidValue',
187+
data: { value: true },
188+
},
189+
],
190+
},
182191
{
183192
code: '<button type={condition ? "reset" : "button"}/>',
184193
options: [{ reset: false }],

0 commit comments

Comments
 (0)