Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] button-has-type: fix exception for <button type> #3255

Merged
merged 1 commit into from May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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