react/button-has-type
eslint-plugin-react
No autofix
eslint.config.js
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/button-has-type": "error",
},
},
];Disallow usage of button elements without an explicit type attribute
var Hello = <button>Hello</button>
var Hello = <button type="foo">Hello</button>
var Hello = <button type={foo}>Hello</button>
var Hello = React.createElement('button', {}, 'Hello')
var Hello = React.createElement('button', {type: 'foo'}, 'Hello')var Hello = <span>Hello</span>
var Hello = <span type="foo">Hello</span>
var Hello = <button type="button">Hello</button>
var Hello = <button type="submit">Hello</button>
var Hello = <button type="reset">Hello</button>
var Hello = <button type={condition ? "button" : "submit"}>Hello</button>
var Hello = React.createElement('span', {}, 'Hello')
var Hello = React.createElement('span', {type: 'foo'}, 'Hello')
var Hello = React.createElement('button', {type: 'button'}, 'Hello')
var Hello = React.createElement('button', {type: 'submit'}, 'Hello')
var Hello = React.createElement('button', {type: 'reset'}, 'Hello')
var Hello = React.createElement('button', {type: condition ? 'button' : 'submit'}, 'Hello')Examples from the ESLint documentation.
react/button-has-type
eslint-plugin-react
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/button-has-type": "error",
},
},
];react/button-has-type
react plugin · restriction
{
"plugins": [
"react"
],
"rules": {
"react/button-has-type": "error"
}
}a11y/useButtonType
a11y · since 1.0.0
{
"linter": {
"rules": {
"a11y": {
"useButtonType": "error"
}
}
}
}Disallow void DOM elements (e.g. <img />, <br />) from receiving children
Disallow usage of Array index in keys
Disallow unnecessary fragments
Disallow usage of dangerous JSX properties
Disallow usage of referential-type variables as default param in functional component
Disallow missing props validation in a React component definition