Skip to content

Commit a7a814e

Browse files
committed
[patch] no-invalid-html-attribute: report more granularly
This also makes error ordering more consistent since certain eslint/node combinations reverse the ordering
1 parent 3636689 commit a7a814e

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1010
* [`no-unsafe`]: report on the method instead of the entire component (@ljharb)
1111
* [`no-deprecated`]: report on the destructured property instead of the entire variable declarator (@ljharb)
1212
* [`no-deprecated`]: report on the imported specifier instead of the entire import statement (@ljharb)
13+
* [`no-invalid-html-attribute`]: report more granularly (@ljharb)
1314

1415
[#3614]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3614
1516

lib/rules/no-invalid-html-attribute.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ function checkAttribute(context, node) {
389389
(tagName) => `"<${tagName}>"`
390390
).join(', ');
391391
report(context, messages.onlyMeaningfulFor, 'onlyMeaningfulFor', {
392-
node,
392+
node: node.name,
393393
data: {
394394
attributeName: attribute,
395395
tagNames,
@@ -408,7 +408,7 @@ function checkAttribute(context, node) {
408408

409409
if (!node.value) {
410410
report(context, messages.emptyIsMeaningless, 'emptyIsMeaningless', {
411-
node,
411+
node: node.name,
412412
data: { attributeName: attribute },
413413
suggest: [
414414
Object.assign(
@@ -434,7 +434,7 @@ function checkAttribute(context, node) {
434434

435435
if (node.value.expression.type === 'ObjectExpression') {
436436
report(context, messages.onlyStrings, 'onlyStrings', {
437-
node,
437+
node: node.value,
438438
data: { attributeName: attribute },
439439
suggest: [
440440
Object.assign(
@@ -445,7 +445,7 @@ function checkAttribute(context, node) {
445445
});
446446
} else if (node.value.expression.type === 'Identifier' && node.value.expression.name === 'undefined') {
447447
report(context, messages.onlyStrings, 'onlyStrings', {
448-
node,
448+
node: node.value,
449449
data: { attributeName: attribute },
450450
suggest: [
451451
Object.assign(
@@ -531,7 +531,7 @@ function checkCreateProps(context, node, attribute) {
531531
).join(', ');
532532

533533
report(context, messages.onlyMeaningfulFor, 'onlyMeaningfulFor', {
534-
node,
534+
node: prop.key,
535535
data: {
536536
attributeName: attribute,
537537
tagNames,

tests/lib/rules/no-invalid-html-attribute.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ ruleTester.run('no-invalid-html-attribute', rule, {
421421
output: '<html ></html>',
422422
},
423423
],
424-
type: 'JSXAttribute',
424+
type: 'JSXIdentifier',
425425
},
426426
],
427427
},
@@ -440,7 +440,8 @@ ruleTester.run('no-invalid-html-attribute', rule, {
440440
// output: 'React.createElement("html", { })',
441441
// },
442442
// ],
443-
type: 'CallExpression',
443+
column: 31,
444+
type: 'Identifier',
444445
},
445446
],
446447
},
@@ -456,7 +457,7 @@ ruleTester.run('no-invalid-html-attribute', rule, {
456457
output: '<a ></a>',
457458
},
458459
],
459-
type: 'JSXAttribute',
460+
type: 'JSXIdentifier',
460461
},
461462
],
462463
},
@@ -504,7 +505,7 @@ ruleTester.run('no-invalid-html-attribute', rule, {
504505
output: '<span ></span>',
505506
},
506507
],
507-
type: 'JSXAttribute',
508+
type: 'JSXIdentifier',
508509
},
509510
],
510511
},
@@ -568,7 +569,7 @@ ruleTester.run('no-invalid-html-attribute', rule, {
568569
output: '<a ></a>',
569570
},
570571
],
571-
type: 'JSXAttribute',
572+
type: 'JSXExpressionContainer',
572573
},
573574
],
574575
},
@@ -584,7 +585,7 @@ ruleTester.run('no-invalid-html-attribute', rule, {
584585
output: '<a ></a>',
585586
},
586587
],
587-
type: 'JSXAttribute',
588+
type: 'JSXExpressionContainer',
588589
},
589590
],
590591
},

0 commit comments

Comments
 (0)