button-has-type
Configuration
rslint.config.ts
Rule Details
Forbid <button> elements (and React.createElement('button', ...) calls) without an explicit type attribute. The default DOM type for a button is "submit", which — when used inside a <form> — unexpectedly submits the form. Always specify one of "button", "submit", or "reset".
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
The rule takes one optional argument — an object that lets you forbid specific button types. Defaults:
Setting one of these flags to false makes that type value forbidden. For example, with { "reset": false }:
Examples of incorrect code with this configuration:
Examples of correct code with this configuration:
Limitations
- Detects
<pragma>.createElement(...)where<pragma>defaults toReactand can be overridden viasettings.react.pragma(e.g."Foo"→Foo.createElement(...)). DestructuredcreateElement(e.g.import { createElement } from 'react') and@jsxcomment pragmas are not supported.