Skip to content

Commit 682ae68

Browse files
authored
Merge pull request jsx-eslint#1000 from ljharb/fix_node_0_10
[Fix] Don’t rely on `Array#find` existing pre node 4
2 parents 466ab7f + 3c035c9 commit 682ae68

6 files changed

+28
-11
lines changed

.travis.yml

+11
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,16 @@ node_js:
33
- '6'
44
- '5'
55
- '4'
6+
- 'iojs'
7+
- '0.12'
8+
- '0.10'
9+
before_script:
10+
- 'if [ "${TRAVIS_NODE_VERSION}" = "iojs" ] || [ "${TRAVIS_NODE_VERSION}" = "0.12" ] || [ "${TRAVIS_NODE_VERSION}" = "0.10" ]; then npm install eslint@2; fi'
611
after_success:
712
- npm run coveralls
13+
matrix:
14+
fast_finish: true
15+
allow_failures:
16+
- node_js: "iojs"
17+
- node_js: "0.12"
18+
- node_js: "0.10"

lib/rules/no-children-prop.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
'use strict';
66

7+
var find = require('array.prototype.find');
8+
79
// ------------------------------------------------------------------------------
810
// Helpers
911
// ------------------------------------------------------------------------------
@@ -53,7 +55,7 @@ module.exports = {
5355
}
5456

5557
var props = node.arguments[1].properties;
56-
var childrenProp = props.find(function(prop) {
58+
var childrenProp = find(props, function(prop) {
5759
return prop.key && prop.key.name === 'children';
5860
});
5961

lib/rules/no-danger-with-children.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
'use strict';
66

7+
var find = require('array.prototype.find');
78
var variableUtil = require('../util/variable');
89

910
// ------------------------------------------------------------------------------
@@ -20,7 +21,7 @@ module.exports = {
2021
},
2122
create: function(context) {
2223
function findSpreadVariable(name) {
23-
return variableUtil.variablesInScope(context).find(function (item) {
24+
return find(variableUtil.variablesInScope(context), function (item) {
2425
return item.name === name;
2526
});
2627
}
@@ -33,7 +34,7 @@ module.exports = {
3334
if (!node.properties) {
3435
return false;
3536
}
36-
return node.properties.find(function(prop) {
37+
return find(node.properties, function(prop) {
3738
if (prop.type === 'Property') {
3839
return prop.key.name === propName;
3940
} else if (prop.type === 'ExperimentalSpreadProperty') {
@@ -53,7 +54,7 @@ module.exports = {
5354
*/
5455
function findJsxProp(node, propName) {
5556
var attributes = node.openingElement.attributes;
56-
return attributes.find(function (attribute) {
57+
return find(attributes, function (attribute) {
5758
if (attribute.type === 'JSXSpreadAttribute') {
5859
var variable = findSpreadVariable(attribute.argument.name);
5960
if (variable && variable.defs.length && variable.defs[0].node.init) {
@@ -94,7 +95,7 @@ module.exports = {
9495
var props = node.arguments[1];
9596

9697
if (props.type === 'Identifier') {
97-
var variable = variableUtil.variablesInScope(context).find(function (item) {
98+
var variable = find(variableUtil.variablesInScope(context), function (item) {
9899
return item.name === props.name;
99100
});
100101
if (variable && variable.defs[0].node.init) {

lib/rules/require-default-props.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
'use strict';
66

7+
var find = require('array.prototype.find');
78
var Components = require('../util/Components');
89
var variableUtil = require('../util/variable');
910
var annotations = require('../util/annotations');
@@ -57,7 +58,7 @@ module.exports = {
5758
* @returns {ASTNode|null} Return null if the variable could not be found, ASTNode otherwise.
5859
*/
5960
function findVariableByName(name) {
60-
var variable = variableUtil.variablesInScope(context).find(function(item) {
61+
var variable = find(variableUtil.variablesInScope(context), function(item) {
6162
return item.name === name;
6263
});
6364

@@ -188,7 +189,7 @@ module.exports = {
188189
* from this ObjectExpression can't be resolved.
189190
*/
190191
function getDefaultPropsFromObjectExpression(objectExpression) {
191-
var hasSpread = objectExpression.properties.find(function(property) {
192+
var hasSpread = find(objectExpression.properties, function(property) {
192193
return property.type === 'ExperimentalSpreadProperty';
193194
});
194195

lib/rules/style-prop-object.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
'use strict';
66

7+
var find = require('array.prototype.find');
78
var variableUtil = require('../util/variable');
89

910
// ------------------------------------------------------------------------------
@@ -25,7 +26,7 @@ module.exports = {
2526
* @param {object} node A Identifier node
2627
*/
2728
function checkIdentifiers(node) {
28-
var variable = variableUtil.variablesInScope(context).find(function (item) {
29+
var variable = find(variableUtil.variablesInScope(context), function (item) {
2930
return item.name === node.name;
3031
});
3132

@@ -47,7 +48,7 @@ module.exports = {
4748
&& node.arguments.length > 1
4849
) {
4950
if (node.arguments[1].type === 'ObjectExpression') {
50-
var style = node.arguments[1].properties.find(function(property) {
51+
var style = find(node.arguments[1].properties, function(property) {
5152
return property.key && property.key.name === 'style' && !property.computed;
5253
});
5354
if (style) {

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
"bugs": "https://github.com/yannickcr/eslint-plugin-react/issues",
2525
"dependencies": {
2626
"doctrine": "^1.2.2",
27-
"jsx-ast-utils": "^1.3.4"
27+
"jsx-ast-utils": "^1.3.4",
28+
"array.prototype.find": "^2.0.1"
2829
},
2930
"devDependencies": {
3031
"babel-eslint": "7.1.1",
3132
"coveralls": "2.11.15",
32-
"eslint": "3.11.1",
33+
"eslint": "^2.0.0 || ^3.0.0",
3334
"istanbul": "0.4.5",
3435
"mocha": "3.2.0"
3536
},

0 commit comments

Comments
 (0)