Skip to content

Latest commit

 

History

History
66 lines (48 loc) · 1.96 KB

File metadata and controls

66 lines (48 loc) · 1.96 KB

ember/template-require-input-type

🔧 This rule is automatically fixable by the --fix CLI option.

This rule rejects <input type="..."> values that are not one of the input types defined by the HTML spec, and (optionally) requires every <input> to declare a type attribute.

An invalid value like <input type="foo"> silently falls back to the Text state — the browser reports no error, but the author's intent (validation, inputmode hint, platform keyboard) is lost. That's a genuine silent-failure class, which this rule always flags and auto-fixes to type="text".

A missing type attribute (<input />) is spec-compliant — the missing-value default is the Text state — so flagging it is a style / consistency choice, not a correctness one. Opt in with requireExplicit: true if your team wants parity with template-require-button-type.

Examples

This rule forbids the following (always):

<input type='' />
<input type='foo' />
<input type='TEXTY' />

With requireExplicit: true the rule also forbids:

<input />
<input name='email' />

This rule allows the following:

<input type='text' />
<input type='email' />
<input type='checkbox' />
<input type={{this.inputType}} />

Dynamic values such as type={{this.inputType}} are not flagged at lint time.

Configuration

  • requireExplicit (boolean, default false): when true, also flag <input> elements that have no type attribute. Auto-fix inserts type="text".
module.exports = {
  rules: {
    'ember/template-require-input-type': ['error', { requireExplicit: true }],
  },
};

References