Skip to content

Commit 6343fbd

Browse files
committed
Sync with ember-template-lint
1 parent 84b85e3 commit 6343fbd

1 file changed

Lines changed: 47 additions & 41 deletions

File tree

lib/rules/template-no-unknown-arguments-for-builtin-components.js

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,58 @@ function getErrorMessage(tagName, argumentName) {
337337
return `"${argumentName}" is unknown argument for <${tagName} /> component.`;
338338
}
339339

340+
function checkConflicts(nodeMeta, node, seen, context) {
341+
if (!nodeMeta.conflicts) {
342+
return;
343+
}
344+
for (const conflictList of nodeMeta.conflicts) {
345+
if (conflictList.every((item) => seen.includes(item))) {
346+
for (const argName of conflictList) {
347+
const attr = node.attributes.find(({ name }) => `@${argName}` === name);
348+
if (attr) {
349+
const conflictsWith = conflictList
350+
.filter((el) => `@${el}` !== attr.name)
351+
.map((el) => `"@${el}"`)
352+
.join(', ');
353+
context.report({
354+
node: attr,
355+
messageId: 'conflictArgument',
356+
data: {
357+
message: `"${attr.name}" conflicts with ${conflictsWith}, only one should exist.`,
358+
},
359+
});
360+
}
361+
}
362+
}
363+
}
364+
}
365+
366+
function checkRequired(nodeMeta, node, seen, context) {
367+
if (!nodeMeta.required) {
368+
return;
369+
}
370+
for (const requiredItems of nodeMeta.required) {
371+
const variants = Array.isArray(requiredItems) ? requiredItems : [requiredItems];
372+
if (!variants.some((el) => seen.includes(el))) {
373+
const argNames = variants.map((el) => `"@${el}"`).join(' or ');
374+
context.report({
375+
node,
376+
messageId: 'requiredArgument',
377+
data: {
378+
message: `Argument${variants.length > 1 ? 's' : ''} ${argNames} is required for <${node.tag} /> component.`,
379+
},
380+
});
381+
}
382+
}
383+
}
384+
340385
/** @type {import('eslint').Rule.RuleModule} */
341386
module.exports = {
342387
meta: {
343388
type: 'problem',
344389
docs: {
345390
description: 'disallow unknown arguments for built-in components',
346391
category: 'Possible Errors',
347-
recommended: false,
348392
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-unknown-arguments-for-builtin-components.md',
349393
templateMode: 'both',
350394
},
@@ -416,46 +460,8 @@ module.exports = {
416460
});
417461
}
418462

419-
// Check conflicts
420-
if (nodeMeta.conflicts) {
421-
for (const conflictList of nodeMeta.conflicts) {
422-
if (conflictList.every((item) => seen.includes(item))) {
423-
for (const argName of conflictList) {
424-
const attr = node.attributes.find(({ name }) => `@${argName}` === name);
425-
if (attr) {
426-
const conflictsWith = conflictList
427-
.filter((el) => `@${el}` !== attr.name)
428-
.map((el) => `"@${el}"`)
429-
.join(', ');
430-
context.report({
431-
node: attr,
432-
messageId: 'conflictArgument',
433-
data: {
434-
message: `"${attr.name}" conflicts with ${conflictsWith}, only one should exist.`,
435-
},
436-
});
437-
}
438-
}
439-
}
440-
}
441-
}
442-
443-
// Check required arguments
444-
if (nodeMeta.required) {
445-
for (const requiredItems of nodeMeta.required) {
446-
const variants = Array.isArray(requiredItems) ? requiredItems : [requiredItems];
447-
if (!variants.some((el) => seen.includes(el))) {
448-
const argNames = variants.map((el) => `"@${el}"`).join(' or ');
449-
context.report({
450-
node,
451-
messageId: 'requiredArgument',
452-
data: {
453-
message: `Argument${variants.length > 1 ? 's' : ''} ${argNames} is required for <${node.tag} /> component.`,
454-
},
455-
});
456-
}
457-
}
458-
}
463+
checkConflicts(nodeMeta, node, seen, context);
464+
checkRequired(nodeMeta, node, seen, context);
459465
},
460466
};
461467
},

0 commit comments

Comments
 (0)