Skip to content

Commit 4a1b63a

Browse files
committed
PR Feedback
1 parent d284e26 commit 4a1b63a

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

lib/rules/template-no-bare-strings.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,24 +175,30 @@ module.exports = {
175175
},
176176

177177
create(context) {
178+
const filename = context.filename ?? context.getFilename();
179+
const isStrictMode = filename.endsWith('.gjs') || filename.endsWith('.gts');
180+
178181
const rawConfig = context.options[0];
179182
let config;
180183

184+
// In strict mode (gjs/gts), Input/Textarea could be custom components —
185+
// prefer false negatives over false positives, matching ember-template-lint.
186+
const defaultElementAttributes = isStrictMode
187+
? DEFAULT_ELEMENT_ATTRIBUTES
188+
: mergeObjects(DEFAULT_ELEMENT_ATTRIBUTES, BUILTIN_COMPONENT_ATTRIBUTES);
189+
181190
if (Array.isArray(rawConfig)) {
182191
config = {
183192
allowlist: sanitizeConfigArray([...rawConfig, ...DEFAULT_ALLOWLIST]),
184193
globalAttributes: [...DEFAULT_GLOBAL_ATTRIBUTES],
185-
elementAttributes: mergeObjects(DEFAULT_ELEMENT_ATTRIBUTES, BUILTIN_COMPONENT_ATTRIBUTES),
194+
elementAttributes: defaultElementAttributes,
186195
ignoredElements: [...IGNORED_ELEMENTS],
187196
};
188197
} else if (rawConfig && typeof rawConfig === 'object') {
189198
config = {
190199
allowlist: sanitizeConfigArray([...(rawConfig.allowlist || []), ...DEFAULT_ALLOWLIST]),
191200
globalAttributes: [...(rawConfig.globalAttributes || []), ...DEFAULT_GLOBAL_ATTRIBUTES],
192-
elementAttributes: mergeObjects(
193-
rawConfig.elementAttributes,
194-
mergeObjects(DEFAULT_ELEMENT_ATTRIBUTES, BUILTIN_COMPONENT_ATTRIBUTES)
195-
),
201+
elementAttributes: mergeObjects(rawConfig.elementAttributes, defaultElementAttributes),
196202
ignoredElements: [
197203
...sanitizeConfigArray(rawConfig.ignoredElements || []),
198204
...IGNORED_ELEMENTS,
@@ -202,7 +208,7 @@ module.exports = {
202208
config = {
203209
allowlist: [...DEFAULT_ALLOWLIST],
204210
globalAttributes: [...DEFAULT_GLOBAL_ATTRIBUTES],
205-
elementAttributes: mergeObjects(DEFAULT_ELEMENT_ATTRIBUTES, BUILTIN_COMPONENT_ATTRIBUTES),
211+
elementAttributes: defaultElementAttributes,
206212
ignoredElements: [...IGNORED_ELEMENTS],
207213
};
208214
}

tests/lib/rules/template-no-bare-strings.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ ruleTester.run('template-no-bare-strings', rule, {
3737
'<template><pre> fdff sf sf <div> aaa </div> f </pre></template>',
3838
'<template><textarea> this is an input</textarea></template>',
3939
'<template><div placeholder="wat?"></div></template>',
40+
// In GJS/GTS (strict mode), Input/Textarea could be custom components —
41+
// not checked to avoid false positives, matching ember-template-lint behavior.
42+
{
43+
filename: 'template.gjs',
44+
code: '<template><Input placeholder="This is a placeholder" /></template>',
45+
},
46+
{
47+
filename: 'template.gjs',
48+
code: '<template><Textarea placeholder="This is a placeholder" /></template>',
49+
},
50+
{
51+
filename: 'template.gjs',
52+
code: '<template><Input @placeholder="This is a placeholder" /></template>',
53+
},
54+
{
55+
filename: 'template.gts',
56+
code: '<template><Textarea @placeholder="This is a placeholder" /></template>',
57+
},
4058
`<template><foo-bar>
4159
</foo-bar></template>`,
4260
'<template><div data-test-foo-bar></div></template>',

0 commit comments

Comments
 (0)