Skip to content

Commit f41bdb8

Browse files
committed
fix(template-require-input-type): flag valueless type attribute per HTML missing-value default (Copilot review)
1 parent 3790db6 commit f41bdb8

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

lib/rules/template-require-input-type.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,25 @@ module.exports = {
9696
}
9797

9898
const value = typeAttr.value;
99-
if (value && value.type === 'GlimmerTextNode') {
99+
100+
// Valueless attribute form (`<input type />`) — per HTML spec, a
101+
// present-but-empty type attribute resolves to the missing-value
102+
// default ("Text state"). That's the same runtime result as
103+
// `type=""`, which we already flag. Treat them consistently:
104+
// flag as invalid('') and autofix to `type="text"`.
105+
if (!value) {
106+
context.report({
107+
node: typeAttr,
108+
messageId: 'invalid',
109+
data: { value: '' },
110+
fix(fixer) {
111+
return fixer.replaceText(typeAttr, 'type="text"');
112+
},
113+
});
114+
return;
115+
}
116+
117+
if (value.type === 'GlimmerTextNode') {
100118
const typeValue = value.chars.toLowerCase();
101119
if (typeValue === '') {
102120
context.report({

tests/lib/rules/template-require-input-type.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ const invalidHbs = [
3636
output: '<input type="text" />',
3737
errors: [{ message: errInvalid('TEXTY') }],
3838
},
39+
// Valueless type attribute — per HTML spec resolves to the missing-value
40+
// default (Text state), same runtime result as `type=""`. Flag and autofix
41+
// to `type="text"`. (Output loses the pre-slash space because the
42+
// valueless attr range ends at `type`; prettier will re-insert if needed.)
43+
{
44+
code: '<input type />',
45+
output: '<input type="text"/>',
46+
errors: [{ message: errInvalid('') }],
47+
},
3948
];
4049

4150
const requireExplicitInvalid = [

0 commit comments

Comments
 (0)