Skip to content

Commit fd542f6

Browse files
committed
[fix] - Fix some syntactical and stylistic issues for cleaner code.
1 parent 5da8833 commit fd542f6

13 files changed

+43
-37
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ module.exports = {
143143
"prefer-const": 2,
144144
"prefer-spread": 2,
145145
"prefer-template": 2,
146+
'quotes': [2, 'single', 'avoid-escape'],
146147
"radix": 2,
147148
"semi": 2,
148149
"sort-vars": [ 2, {

docs/rules/no-unsupported-elements-use-aria.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# no-unsupported-elements-use-aria
22

3-
Certain reserved DOM elements do not support ARIA roles, states and properties. This is often because they are not visible, for example `meta`, `html`, `script`, `style`. This rule enforces that these DOM elements do not contain the role and/or aria-* props.
3+
Certain reserved DOM elements do not support ARIA roles, states and properties. This is often because they are not visible, for example `meta`, `html`, `script`, `style`. This rule enforces that these DOM elements do not contain the `role` and/or `aria-*` props.
44

55
#### References
66
1. [AX_ARIA_12](https://github.com/GoogleChrome/accessibility-developer-tools/wiki/Audit-Rules#ax_aria_12)
@@ -12,12 +12,12 @@ This rule takes no arguments.
1212
### Succeed
1313
```jsx
1414
<!-- Good: the meta element should not be given any ARIA attributes -->
15-
<meta charset="UTF-8">
15+
<meta charset="UTF-8" />
1616
```
1717

1818
### Fail
1919
```jsx
2020
<!-- Bad: the meta element should not be given any ARIA attributes -->
21-
<meta charset="UTF-8" aria-hidden="false">
21+
<meta charset="UTF-8" aria-hidden="false" />
2222
```
2323

src/rules/img-uses-alt.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ module.exports = context => ({
6060

6161
module.exports.schema = [
6262
{
63-
"oneOf": [
64-
{ "type": "string" },
63+
'oneOf': [
64+
{ 'type': 'string' },
6565
{
66-
"type": "array",
67-
"items": {
68-
"type": "string"
66+
'type': 'array',
67+
'items': {
68+
'type': 'string'
6969
},
70-
"minItems": 1,
71-
"uniqueItems": true
70+
'minItems': 1,
71+
'uniqueItems': true
7272
}
7373
]
7474
}

src/rules/label-uses-for.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ module.exports = context => ({
4040

4141
module.exports.schema = [
4242
{
43-
"oneOf": [
44-
{ "type": "string" },
43+
'oneOf': [
44+
{ 'type': 'string' },
4545
{
46-
"type": "array",
47-
"items": {
48-
"type": "string"
46+
'type': 'array',
47+
'items': {
48+
'type': 'string'
4949
},
50-
"minItems": 1,
51-
"uniqueItems": true
50+
'minItems': 1,
51+
'uniqueItems': true
5252
}
5353
]
5454
}

src/rules/no-hash-href.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ module.exports = context => ({
3838

3939
module.exports.schema = [
4040
{
41-
"oneOf": [
42-
{ "type": "string" },
41+
'oneOf': [
42+
{ 'type': 'string' },
4343
{
44-
"type": "array",
45-
"items": {
46-
"type": "string"
44+
'type': 'array',
45+
'items': {
46+
'type': 'string'
4747
},
48-
"minItems": 1,
49-
"uniqueItems": true
48+
'minItems': 1,
49+
'uniqueItems': true
5050
}
5151
]
5252
}

src/rules/no-unsupported-elements-use-aria.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ module.exports = context => ({
2626
return;
2727
}
2828

29-
// Check if it has role attribute;
30-
const hasRole = hasAttribute(node.attributes, 'role');
31-
const hasAria = Object.keys(ARIA).some(prop => hasAttribute(node.attributes, prop.toLowerCase()));
29+
const invalidAttributes = Object.keys(ARIA).concat('ROLE');
30+
const hasAria = hasAttribute(node.attributes, ...invalidAttributes);
3231

33-
if (hasRole || hasAria) {
32+
if (hasAria) {
3433
context.report({
3534
node,
3635
message: errorMessage

src/rules/role-requires-aria.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import hasAttribute from '../util/hasAttribute';
1414

1515
const errorMessage = (role, requiredProps) =>
1616
`Elements with the ARIA role "${role}" must have the following ` +
17-
`attributes defined: ${requiredProps.toString().toLowerCase()}`;
17+
`attributes defined: ${String(requiredProps).toLowerCase()}`;
1818

1919
module.exports = context => ({
2020
JSXAttribute: attribute => {
@@ -31,7 +31,7 @@ module.exports = context => ({
3131
return;
3232
}
3333

34-
const normalizedValues = `${value}`.toUpperCase().split(" ");
34+
const normalizedValues = String(value).toUpperCase().split(' ');
3535
const validRoles = normalizedValues.filter(value => Object.keys(validRoleTypes).indexOf(value) > -1);
3636

3737
validRoles.forEach(role => {

src/rules/valid-aria-role.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = context => ({
2828
return;
2929
}
3030

31-
const normalizedValues = `${value}`.toUpperCase().split(" ");
31+
const normalizedValues = String(value).toUpperCase().split(' ');
3232
const isValid = normalizedValues.every(value => Object.keys(validRoleTypes).indexOf(value) > -1);
3333

3434
if (isValid === true) {

src/util/hasAttribute.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77
* as the purpose of this linter is to do hard checks of explicit JSX props.
88
*
99
*/
10-
const hasAttribute = (attributes, attribute) => {
10+
const hasAttribute = (attributesOnNode, ...attributesToCheck) => {
1111
let nodeAttribute = undefined;
1212

13-
const hasAttr = attributes.some(attr => {
13+
// Normalize.
14+
const comparators = attributesToCheck.map(attribute => attribute.toUpperCase());
15+
16+
const hasAttr = attributesOnNode.some(attr => {
1417
// If the attributes contain a spread attribute, then skip.
1518
if (attr.type === 'JSXSpreadAttribute') {
1619
return false;
1720
}
1821

1922
// Normalize.
20-
if (attr.name.name.toUpperCase() === attribute.toUpperCase()) {
23+
if (comparators.indexOf(attr.name.name.toUpperCase()) > -1) {
2124
nodeAttribute = attr;
2225
return true;
2326
}

src/util/values/Literal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const extract = value => {
22
const { value: extractedValue } = value;
33

4-
if (extractedValue === "true") {
4+
if (extractedValue === 'true') {
55
return true;
6-
} else if (extractedValue === "false") {
6+
} else if (extractedValue === 'false') {
77
return false;
88
}
99

0 commit comments

Comments
 (0)