Skip to content

Commit b405786

Browse files
authored
[new] - Use airbnb eslint config (#58)
1 parent da4afe8 commit b405786

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+889
-722
lines changed

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
extends: "airbnb-base"
3+
}

.eslintrc.js

Lines changed: 0 additions & 163 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"build": "rimraf lib && babel src --out-dir lib && cp -R src/util/attributes lib/util/attributes",
2121
"prepublish": "npm run lint && npm run test && npm run build",
2222
"coveralls": "cat ./reports/coverage/lcov.info | coveralls",
23-
"lint": "eslint --config .eslintrc.js .",
23+
"lint": "eslint --config .eslintrc src tests",
2424
"pretest": "npm run lint",
2525
"test": "istanbul cover --dir reports/coverage node_modules/mocha/bin/_mocha tests/**/*.js -- --compilers js:babel-core/register --reporter dot"
2626
},
@@ -31,6 +31,8 @@
3131
"babel-preset-es2015": "^6.6.0",
3232
"coveralls": "^2.11.8",
3333
"eslint": "^2.2.0",
34+
"eslint-config-airbnb-base": "^3.0.1",
35+
"eslint-plugin-import": "^1.8.1",
3436
"istanbul": "^1.0.0-alpha.2",
3537
"mocha": "^2.4.5",
3638
"rimraf": "^2.5.2"

src/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict';
1+
/* eslint-disable global-require */
22

33
module.exports = {
44
rules: {
@@ -17,14 +17,14 @@ module.exports = {
1717
'onclick-has-role': require('./rules/onclick-has-role'),
1818
'role-has-required-aria-props': require('./rules/role-has-required-aria-props'),
1919
'role-supports-aria-props': require('./rules/role-supports-aria-props'),
20-
'tabindex-no-positive': require('./rules/tabindex-no-positive')
20+
'tabindex-no-positive': require('./rules/tabindex-no-positive'),
2121
},
2222
configs: {
2323
recommended: {
2424
parserOptions: {
2525
ecmaFeatures: {
26-
jsx: true
27-
}
26+
jsx: true,
27+
},
2828
},
2929
rules: {
3030
'jsx-a11y/aria-props': 2,
@@ -42,8 +42,8 @@ module.exports = {
4242
'jsx-a11y/onclick-has-role': 2,
4343
'jsx-a11y/role-has-required-aria-props': 2,
4444
'jsx-a11y/role-supports-aria-props': 2,
45-
'jsx-a11y/tabindex-no-positive': 2
46-
}
47-
}
48-
}
45+
'jsx-a11y/tabindex-no-positive': 2,
46+
},
47+
},
48+
},
4949
};

src/rules/aria-props.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @fileoverview Enforce all aria-* properties are valid.
33
* @author Ethan Cohen
44
*/
5-
'use strict';
65

76
// ----------------------------------------------------------------------------
87
// Rule Definition
@@ -38,12 +37,12 @@ module.exports = context => ({
3837
if (isValid === false) {
3938
context.report({
4039
node: attribute,
41-
message: errorMessage(name)
40+
message: errorMessage(name),
4241
});
4342
}
44-
}
43+
},
4544
});
4645

4746
module.exports.schema = [
48-
{ type: 'object' }
47+
{ type: 'object' },
4948
];

src/rules/aria-proptypes.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @fileoverview Enforce ARIA state and property values are valid.
33
* @author Ethan Cohen
44
*/
5-
'use strict';
65

76
// ----------------------------------------------------------------------------
87
// Rule Definition
@@ -18,7 +17,8 @@ const errorMessage = (name, type, permittedValues) => {
1817
case 'token':
1918
return `The value for ${name} must be a single token from the following: ${permittedValues}.`;
2019
case 'tokenlist':
21-
return `The value for ${name} must be a list of one or more tokens from the following: ${permittedValues}.`;
20+
return `The value for ${name} must be a list of one or more \
21+
tokens from the following: ${permittedValues}.`;
2222
case 'boolean':
2323
case 'string':
2424
case 'integer':
@@ -35,15 +35,16 @@ const validityCheck = (value, expectedType, permittedValues) => {
3535
case 'string':
3636
return typeof value === 'string';
3737
case 'tristate':
38-
return typeof value === 'boolean' || value == 'mixed';
38+
return typeof value === 'boolean' || value === 'mixed';
3939
case 'integer':
4040
case 'number':
4141
// Booleans resolve to 0/1 values so hard check that it's not first.
4242
return typeof value !== 'boolean' && isNaN(Number(value)) === false;
4343
case 'token':
4444
return typeof value === 'string' && permittedValues.indexOf(value.toLowerCase()) > -1;
4545
case 'tokenlist':
46-
return typeof value === 'string' && value.split(' ').every(token => permittedValues.indexOf(token.toLowerCase()) > -1);
46+
return typeof value === 'string' &&
47+
value.split(' ').every(token => permittedValues.indexOf(token.toLowerCase()) > -1);
4748
default:
4849
return false;
4950
}
@@ -72,19 +73,20 @@ module.exports = context => ({
7273
const allowUndefined = attributes.allowUndefined || false;
7374
const permittedValues = attributes.values || [];
7475

75-
const isValid = validityCheck(value, permittedType, permittedValues) || (allowUndefined && value === undefined);
76+
const isValid = validityCheck(value, permittedType, permittedValues) ||
77+
(allowUndefined && value === undefined);
7678

7779
if (isValid) {
7880
return;
7981
}
8082

8183
context.report({
8284
node: attribute,
83-
message: errorMessage(name, permittedType, permittedValues)
85+
message: errorMessage(name, permittedType, permittedValues),
8486
});
85-
}
87+
},
8688
});
8789

8890
module.exports.schema = [
89-
{ type: 'object' }
91+
{ type: 'object' },
9092
];

src/rules/aria-role.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @fileoverview Enforce aria role attribute is valid.
33
* @author Ethan Cohen
44
*/
5-
'use strict';
65

76
// ----------------------------------------------------------------------------
87
// Rule Definition
@@ -23,26 +22,27 @@ module.exports = context => ({
2322
const value = getLiteralPropValue(attribute);
2423

2524
// If value is undefined, then the role attribute will be dropped in the DOM.
26-
// If value is null, then getLiteralAttributeValue is telling us that the value isn't in the form of a literal.
25+
// If value is null, then getLiteralAttributeValue is telling us that the
26+
// value isn't in the form of a literal.
2727
if (value === undefined || value === null) {
2828
return;
2929
}
3030

3131
const normalizedValues = String(value).toUpperCase().split(' ');
3232
const validRoles = Object.keys(roles).filter(role => roles[role].abstract === false);
33-
const isValid = normalizedValues.every(value => validRoles.indexOf(value) > -1);
33+
const isValid = normalizedValues.every(val => validRoles.indexOf(val) > -1);
3434

3535
if (isValid === true) {
3636
return;
3737
}
3838

3939
context.report({
4040
node: attribute,
41-
message: errorMessage
41+
message: errorMessage,
4242
});
43-
}
43+
},
4444
});
4545

4646
module.exports.schema = [
47-
{ type: 'object' }
47+
{ type: 'object' },
4848
];

src/rules/aria-unsupported-elements.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* @fileoverview Enforce that elements that do not support ARIA roles, states and properties do not have those attributes.
2+
* @fileoverview Enforce that elements that do not support ARIA roles,
3+
* states and properties do not have those attributes.
34
* @author Ethan Cohen
45
*/
5-
'use strict';
66

77
// ----------------------------------------------------------------------------
88
// Rule Definition
@@ -13,7 +13,8 @@ import ARIA from '../util/attributes/ARIA';
1313
import { elementType } from 'jsx-ast-utils';
1414

1515
const errorMessage = invalidProp =>
16-
`This element does not support ARIA roles, states and properties. Try removing the prop '${invalidProp}'.`;
16+
`This element does not support ARIA roles, states and properties. \
17+
Try removing the prop '${invalidProp}'.`;
1718

1819
module.exports = context => ({
1920
JSXOpeningElement: node => {
@@ -32,13 +33,13 @@ module.exports = context => ({
3233
if (invalidAttributes.indexOf(prop.name.name.toUpperCase()) > -1) {
3334
context.report({
3435
node,
35-
message: errorMessage(prop.name.name)
36+
message: errorMessage(prop.name.name),
3637
});
3738
}
3839
});
39-
}
40+
},
4041
});
4142

4243
module.exports.schema = [
43-
{ type: 'object' }
44+
{ type: 'object' },
4445
];

0 commit comments

Comments
 (0)