Skip to content

Commit

Permalink
[Fix] button-has-type: fix exception for <button type>
Browse files Browse the repository at this point in the history
  • Loading branch information
meowtec authored and ljharb committed May 16, 2022
1 parent 46ce117 commit 9356230
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -19,6 +19,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* [`no-unused-state`]: avoid a crash ([#3258][] @WillyLiaoWH @ljharb)
* [`jsx-no-useless-fragment`]: use proper apostrophe in error message ([#3266][] @develohpanda)
* `propTypes`: handle imported types/interface in forwardRef generic ([#3280][] @vedadeepta)
* [`button-has-type`]: fix exception for `<button type>` ([#3255][] @meowtec)

### Changed
* [readme] remove global usage and eslint version from readme ([#3254][] @aladdin-add)
Expand Down Expand Up @@ -48,6 +49,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
[#3260]: https://github.jsx-eslintckcr/eslint-plugin-react/pull/3260
[#3259]: https://githubjsx-eslintickcr/eslint-plugin-react/pull/3259
[#3258]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3258
[#3255]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3255
[#3254]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3254
[#3251]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3251
[#3249]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3249
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/button-has-type.js
Expand Up @@ -126,7 +126,7 @@ module.exports = {
return;
}

if (typeProp.value.type === 'JSXExpressionContainer') {
if (typeProp.value && typeProp.value.type === 'JSXExpressionContainer') {
checkExpression(node, typeProp.value.expression);
return;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/rules/button-has-type.js
Expand Up @@ -179,6 +179,15 @@ ruleTester.run('button-has-type', rule, {
},
],
},
{
code: '<button type/>',
errors: [
{
messageId: 'invalidValue',
data: { value: true },
},
],
},
{
code: '<button type={condition ? "reset" : "button"}/>',
options: [{ reset: false }],
Expand Down

0 comments on commit 9356230

Please sign in to comment.