Skip to content

Commit 280dda3

Browse files
committed
Handle JSXMemberExpression as node type names.
1 parent 030c6ee commit 280dda3

File tree

10 files changed

+16
-6
lines changed

10 files changed

+16
-6
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/**
22
reports/**
33
index.js
4+
lib/

src/rules/img-uses-alt.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
// ----------------------------------------------------------------------------
1010

1111
import hasAttribute from '../util/hasAttribute';
12+
import getNodeType from '../util/getNodeType';
1213

1314
const errorMessage = type => `${type} elements must have an alt tag.`;
1415

1516
module.exports = context => ({
1617
JSXOpeningElement: node => {
1718
const typeCheck = [ 'img' ].concat(context.options[0]);
18-
const nodeType = node.name.name;
19+
const nodeType = getNodeType(node);
1920

2021
// Only check 'img' elements and custom types.
2122
if (typeCheck.indexOf(nodeType) === -1) {

src/rules/label-uses-for.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
// ----------------------------------------------------------------------------
1010

1111
import hasAttribute from '../util/hasAttribute';
12+
import getNodeType from '../util/getNodeType';
1213

1314
const errorMessage = 'Form controls using a label to identify them must be ' +
1415
'programmatically associated with the control using htmlFor';
1516

1617
module.exports = context => ({
1718
JSXOpeningElement: node => {
1819
const typeCheck = [ 'label' ].concat(context.options[0]);
19-
const nodeType = node.name.name;
20+
const nodeType = getNodeType(node);
2021

2122
// Only check 'label' elements and custom types.
2223
if (typeCheck.indexOf(nodeType) === -1) {

src/rules/no-hash-href.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
// ----------------------------------------------------------------------------
1010

1111
import hasAttribute from '../util/hasAttribute';
12+
import getNodeType from '../util/getNodeType';
1213

1314
const errorMessage = 'Links must not point to "#". Use a more descriptive href or use a button instead.';
1415

1516
module.exports = context => ({
1617
JSXOpeningElement: node => {
1718
const typeCheck = [ 'a' ].concat(context.options[0]);
18-
const nodeType = node.name.name;
19+
const nodeType = getNodeType(node);
1920

2021
// Only check 'a' elements and custom types.
2122
if (typeCheck.indexOf(nodeType) === -1) {

src/rules/onclick-uses-role.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader';
99
import isInteractiveElement from '../util/isInteractiveElement';
1010
import hasAttribute from '../util/hasAttribute';
11+
import getNodeType from '../util/getNodeType';
1112

1213
// ----------------------------------------------------------------------------
1314
// Rule Definition
@@ -24,7 +25,7 @@ module.exports = context => ({
2425
}
2526

2627
const isVisible = isHiddenFromScreenReader(attributes) === false;
27-
const isNonInteractive = isInteractiveElement(node.name.name, attributes) === false;
28+
const isNonInteractive = isInteractiveElement(getNodeType(node), attributes) === false;
2829
const noRoleAttribute = hasAttribute(attributes, 'role') === false;
2930

3031
// Visible, non-interactive elements require role attribute.

src/rules/redundant-alt.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import hasAttribute from '../util/hasAttribute';
1212
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader';
13+
import getNodeType from '../util/getNodeType';
1314

1415
const REDUNDANT_WORDS = [
1516
'image',
@@ -22,7 +23,7 @@ const errorMessage = 'Redundant alt attribute. Screen-readers already announce `
2223

2324
module.exports = context => ({
2425
JSXOpeningElement: node => {
25-
const type = node.name.name;
26+
const type = getNodeType(node);
2627
if (type !== 'img') {
2728
return;
2829
}

tests/src/rules/img-uses-alt.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ ruleTester.run('img-uses-alt', rule, {
5454
{ code: '<div alt={function(e) {} } />', parserOptions },
5555
{ code: '<img alt={() => void 0} />', parserOptions },
5656
{ code: '<IMG />', parserOptions },
57+
{ code: '<UX.Layout>test</UX.Layout>', parserOptions },
5758

5859
// CUSTOM ELEMENT TESTS FOR STRING OPTION
5960
{ code: '<Avatar alt="foo" />;', options: string, parserOptions },

tests/src/rules/label-uses-for.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ ruleTester.run('label-uses-for', rule, {
4545
{ code: '<label htmlFor="foo">Test!</label>', parserOptions },
4646
{ code: '<Label />', parserOptions }, // lower-case convention refers to real HTML elements.
4747
{ code: '<Label htmlFor="foo" />', parserOptions },
48+
{ code: '<UX.Layout>test</UX.Layout>', parserOptions },
4849

4950
// CUSTOM ELEMENT STRING OPTION TESTS
5051
{ code: '<Label htmlFor="foo" />', options: string, parserOptions },

tests/src/rules/no-hash-href.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ ruleTester.run('no-hash-href', rule, {
4848
{ code: '<a href={`#foo`}/>', parserOptions },
4949
{ code: '<a href={"foo"}/>', parserOptions },
5050
{ code: '<a href="#foo" />', parserOptions },
51+
{ code: '<UX.Layout>test</UX.Layout>', parserOptions },
5152

5253
// CUSTOM ELEMENT TEST FOR STRING OPTION
5354
{ code: '<Link />;', options: string, parserOptions },

tests/src/rules/redundant-alt.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ ruleTester.run('redundant-alt', rule, {
5454
{ code: '<img alt={"undefined"} />', parserOptions },
5555
{ code: '<img alt={() => {}} />', parserOptions },
5656
{ code: '<img alt={function(e){}} />', parserOptions },
57-
{ code: '<img aria-hidden={false} alt="Doing cool things." />', parserOptions }
57+
{ code: '<img aria-hidden={false} alt="Doing cool things." />', parserOptions },
58+
{ code: '<UX.Layout>test</UX.Layout>', parserOptions }
5859
],
5960
invalid: [
6061
{ code: '<img alt="Photo of friend." />;', errors: [ expectedError ], parserOptions },

0 commit comments

Comments
 (0)