Skip to content

Commit fe44166

Browse files
committed
[chore]: outlier test cases
1 parent 42396c2 commit fe44166

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

__tests__/src/rules/no-static-element-interactions-test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,24 @@ const componentsSettings = {
3434
components: {
3535
Button: 'button',
3636
TestComponent: 'div',
37+
// Custom component with mapped attributes
3738
Link: {
3839
component: 'a',
3940
attributes: {
40-
href: ['to', 'href'],
41+
href: ['to', 'href', 'foo'],
4142
},
4243
},
44+
// Custom component with a redundant attribute
45+
TestComponent2: {
46+
attributes: {
47+
href: ['href'],
48+
},
49+
component: 'a',
50+
},
51+
// Custom component with empty attributes object
52+
TestComponent3: {
53+
component: 'a',
54+
},
4355
},
4456
},
4557
};
@@ -89,7 +101,9 @@ const alwaysValid = [
89101
{ code: '<a onClick={() => void 0} href="http://x.y.z" />' },
90102
{ code: '<a onClick={() => void 0} href="http://x.y.z" tabIndex="0" />' },
91103
{ code: '<Link onClick={() => void 0} to="path/to/page" />', settings: componentsSettings },
104+
{ code: '<Link onClick={() => void 0} foo="path/to/page" />', settings: componentsSettings },
92105
{ code: '<Link onClick={() => void 0} href="http://x.y.z" />', settings: componentsSettings },
106+
{ code: '<TestComponent2 onClick={() => void 0} href="http://x.y.z" />;', settings: componentsSettings },
93107
{ code: '<audio onClick={() => {}} />;' },
94108
{ code: '<form onClick={() => {}} />;' },
95109
{ code: '<form onSubmit={() => {}} />;' },
@@ -365,6 +379,10 @@ const neverValid = [
365379
// Custom components
366380
{ code: '<Link onClick={() => void 0} to="path/to/page" />', settings: { 'jsx-a11y': { components: { Link: 'a' } } }, errors: [expectedError] },
367381
{ code: '<TestComponent onClick={() => void 0} to="path/to/page" />', settings: componentsSettings, errors: [expectedError] },
382+
// Custom component with a redundant attribute
383+
{ code: '<TestComponent2 onClick={() => void 0} to="path/to/page" />;', settings: componentsSettings, errors: [expectedError] },
384+
// Custom component with empty attributes object
385+
{ code: '<TestComponent3 onClick={() => void 0} to="path/to/page" />;', settings: componentsSettings, errors: [expectedError] },
368386
// `a` with a `to` is not valid, only custom components listed in `components`
369387
{ code: '<a onClick={() => void 0} to="path/to/page" />', settings: componentsSettings, errors: [expectedError] },
370388
];

src/util/getElementType.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,19 @@ const getElementType = (context: ESLintContext): ((node: JSXOpeningElement) => s
3333

3434
const componentType = componentMap[rawType];
3535

36+
if (typeof componentType === 'string') {
37+
return hasOwn(componentMap, rawType) ? componentType : rawType;
38+
}
39+
3640
if (typeof componentType === 'object') {
41+
if (componentType.component) return componentType.component;
42+
3743
const customComponent = Object.entries(componentType).find(([key]) => key === rawType);
3844

3945
if (customComponent) {
4046
[rawType] = customComponent;
4147
return hasOwn(componentMap, rawType) ? rawType : rawType;
4248
}
43-
} else if (typeof componentType === 'string') {
44-
return hasOwn(componentMap, rawType) ? componentType : rawType;
4549
}
4650

4751
return rawType;

0 commit comments

Comments
 (0)