Skip to content

[Fix] Don’t rely on Array#find existing pre node 4 #1000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@ node_js:
- '6'
- '5'
- '4'
- 'iojs'
- '0.12'
- '0.10'
before_script:
- 'if [ "${TRAVIS_NODE_VERSION}" = "iojs" ] || [ "${TRAVIS_NODE_VERSION}" = "0.12" ] || [ "${TRAVIS_NODE_VERSION}" = "0.10" ]; then npm install eslint@2; fi'
after_success:
- npm run coveralls
matrix:
fast_finish: true
allow_failures:
- node_js: "iojs"
- node_js: "0.12"
- node_js: "0.10"
4 changes: 3 additions & 1 deletion lib/rules/no-children-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
'use strict';

var find = require('array.prototype.find');

// ------------------------------------------------------------------------------
// Helpers
// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -53,7 +55,7 @@ module.exports = {
}

var props = node.arguments[1].properties;
var childrenProp = props.find(function(prop) {
var childrenProp = find(props, function(prop) {
return prop.key && prop.key.name === 'children';
});

Expand Down
9 changes: 5 additions & 4 deletions lib/rules/no-danger-with-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
'use strict';

var find = require('array.prototype.find');
var variableUtil = require('../util/variable');

// ------------------------------------------------------------------------------
Expand All @@ -20,7 +21,7 @@ module.exports = {
},
create: function(context) {
function findSpreadVariable(name) {
return variableUtil.variablesInScope(context).find(function (item) {
return find(variableUtil.variablesInScope(context), function (item) {
return item.name === name;
});
}
Expand All @@ -33,7 +34,7 @@ module.exports = {
if (!node.properties) {
return false;
}
return node.properties.find(function(prop) {
return find(node.properties, function(prop) {
if (prop.type === 'Property') {
return prop.key.name === propName;
} else if (prop.type === 'ExperimentalSpreadProperty') {
Expand All @@ -53,7 +54,7 @@ module.exports = {
*/
function findJsxProp(node, propName) {
var attributes = node.openingElement.attributes;
return attributes.find(function (attribute) {
return find(attributes, function (attribute) {
if (attribute.type === 'JSXSpreadAttribute') {
var variable = findSpreadVariable(attribute.argument.name);
if (variable && variable.defs.length && variable.defs[0].node.init) {
Expand Down Expand Up @@ -94,7 +95,7 @@ module.exports = {
var props = node.arguments[1];

if (props.type === 'Identifier') {
var variable = variableUtil.variablesInScope(context).find(function (item) {
var variable = find(variableUtil.variablesInScope(context), function (item) {
return item.name === props.name;
});
if (variable && variable.defs[0].node.init) {
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/require-default-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
'use strict';

var find = require('array.prototype.find');
var Components = require('../util/Components');
var variableUtil = require('../util/variable');
var annotations = require('../util/annotations');
Expand Down Expand Up @@ -57,7 +58,7 @@ module.exports = {
* @returns {ASTNode|null} Return null if the variable could not be found, ASTNode otherwise.
*/
function findVariableByName(name) {
var variable = variableUtil.variablesInScope(context).find(function(item) {
var variable = find(variableUtil.variablesInScope(context), function(item) {
return item.name === name;
});

Expand Down Expand Up @@ -188,7 +189,7 @@ module.exports = {
* from this ObjectExpression can't be resolved.
*/
function getDefaultPropsFromObjectExpression(objectExpression) {
var hasSpread = objectExpression.properties.find(function(property) {
var hasSpread = find(objectExpression.properties, function(property) {
return property.type === 'ExperimentalSpreadProperty';
});

Expand Down
5 changes: 3 additions & 2 deletions lib/rules/style-prop-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
'use strict';

var find = require('array.prototype.find');
var variableUtil = require('../util/variable');

// ------------------------------------------------------------------------------
Expand All @@ -25,7 +26,7 @@ module.exports = {
* @param {object} node A Identifier node
*/
function checkIdentifiers(node) {
var variable = variableUtil.variablesInScope(context).find(function (item) {
var variable = find(variableUtil.variablesInScope(context), function (item) {
return item.name === node.name;
});

Expand All @@ -47,7 +48,7 @@ module.exports = {
&& node.arguments.length > 1
) {
if (node.arguments[1].type === 'ObjectExpression') {
var style = node.arguments[1].properties.find(function(property) {
var style = find(node.arguments[1].properties, function(property) {
return property.key && property.key.name === 'style' && !property.computed;
});
if (style) {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
"bugs": "https://github.com/yannickcr/eslint-plugin-react/issues",
"dependencies": {
"doctrine": "^1.2.2",
"jsx-ast-utils": "^1.3.4"
"jsx-ast-utils": "^1.3.4",
"array.prototype.find": "^2.0.1"
},
"devDependencies": {
"babel-eslint": "7.1.1",
"coveralls": "2.11.15",
"eslint": "3.11.1",
"eslint": "^2.0.0 || ^3.0.0",
"istanbul": "0.4.5",
"mocha": "3.2.0"
},
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy