Skip to content

Commit

Permalink
Merge pull request #324 from lukekarrys/master
Browse files Browse the repository at this point in the history
Fix crash with ESLint 1.10.0 (fixes #323)
  • Loading branch information
yannickcr committed Nov 20, 2015
2 parents 25e05b8 + 886a09a commit 1b5d007
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var Components = require('../util/Components');
// Rule Definition
// ------------------------------------------------------------------------------

module.exports = Components.detect(function(context, components) {
module.exports = Components.detect(function(context, components, utils) {

var config = context.options[0] || {};
var acceptTranspilerName = config.acceptTranspilerName || false;
Expand Down Expand Up @@ -131,7 +131,7 @@ module.exports = Components.detect(function(context, components) {
if (!isDisplayNameDeclaration(node.property)) {
return;
}
var component = context.react.getRelatedComponent(node);
var component = utils.getRelatedComponent(node);
if (!component) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-direct-mutation-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var Components = require('../util/Components');
// Rule Definition
// ------------------------------------------------------------------------------

module.exports = Components.detect(function(context, components) {
module.exports = Components.detect(function(context, components, utils) {

/**
* Checks if the component is valid
Expand Down Expand Up @@ -51,7 +51,7 @@ module.exports = Components.detect(function(context, components) {
item.object.type === 'ThisExpression' &&
item.property.name === 'state'
) {
var component = components.get(context.react.getParentComponent());
var component = components.get(utils.getParentComponent());
var mutations = component && component.mutations || [];
mutations.push(node.left.object);
components.set(node, {
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/prefer-es6-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ var Components = require('../util/Components');
// Rule Definition
// ------------------------------------------------------------------------------

module.exports = Components.detect(function(context) {
module.exports = Components.detect(function(context, components, utils) {

return {
ObjectExpression: function(node) {
if (context.react.isES5Component(node)) {
if (utils.isES5Component(node)) {
context.report(node, 'Component should use es6 class instead of createClass');
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var Components = require('../util/Components');
// Rule Definition
// ------------------------------------------------------------------------------

module.exports = Components.detect(function(context, components) {
module.exports = Components.detect(function(context, components, utils) {

var configuration = context.options[0] || {};
var ignored = configuration.ignore || [];
Expand All @@ -28,7 +28,7 @@ module.exports = Components.detect(function(context, components) {
*/
function isPropTypesUsage(node) {
var isClassUsage = (
(context.react.getParentES6Component() || context.react.getParentES5Component()) &&
(utils.getParentES6Component() || utils.getParentES5Component()) &&
node.object.type === 'ThisExpression' && node.property.name === 'props'
);
var isStatelessFunctionUsage = node.object.name === 'props';
Expand Down Expand Up @@ -328,7 +328,7 @@ module.exports = Components.detect(function(context, components) {
*/
function getPropertyName(node) {
var isDirectProp = /^props(\.|\[)/.test(context.getSource(node));
var isInClassComponent = context.react.getParentES6Component() || context.react.getParentES5Component();
var isInClassComponent = utils.getParentES6Component() || utils.getParentES5Component();
var isNotInConstructor = !inConstructor(node);
if (isDirectProp && isInClassComponent && isNotInConstructor) {
return void 0;
Expand Down Expand Up @@ -408,7 +408,7 @@ module.exports = Components.detect(function(context, components) {
throw new Error(node.type + ' ASTNodes are not handled by markPropTypesAsUsed');
}

var component = components.get(context.react.getParentComponent());
var component = components.get(utils.getParentComponent());
var usedPropTypes = component && component.usedPropTypes || [];

switch (type) {
Expand Down Expand Up @@ -569,7 +569,7 @@ module.exports = Components.detect(function(context, components) {
markPropTypesAsUsed(node);
break;
case 'declaration':
var component = context.react.getRelatedComponent(node);
var component = utils.getRelatedComponent(node);
if (!component) {
return;
}
Expand Down
34 changes: 17 additions & 17 deletions lib/util/Components.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function componentRule(rule, context) {
var components = new Components();

// Utilities for component detection
context.react = {
var utils = {

/**
* Check if the node is a React ES5 component
Expand Down Expand Up @@ -176,9 +176,9 @@ function componentRule(rule, context) {
*/
getParentComponent: function() {
return (
context.react.getParentES6Component() ||
context.react.getParentES5Component() ||
context.react.getParentStatelessComponent()
utils.getParentES6Component() ||
utils.getParentES5Component() ||
utils.getParentStatelessComponent()
);
},

Expand All @@ -191,7 +191,7 @@ function componentRule(rule, context) {
var scope = context.getScope();
while (scope) {
var node = scope.block && scope.block.parent && scope.block.parent.parent;
if (node && context.react.isES5Component(node)) {
if (node && utils.isES5Component(node)) {
return node;
}
scope = scope.upper;
Expand All @@ -210,7 +210,7 @@ function componentRule(rule, context) {
scope = scope.upper;
}
var node = scope && scope.block;
if (!node || !context.react.isES6Component(node)) {
if (!node || !utils.isES6Component(node)) {
return null;
}
return node;
Expand Down Expand Up @@ -316,57 +316,57 @@ function componentRule(rule, context) {
// Component detection instructions
var detectionInstructions = {
ClassDeclaration: function(node) {
if (!context.react.isES6Component(node)) {
if (!utils.isES6Component(node)) {
return;
}
components.add(node, 2);
},

ClassProperty: function(node) {
node = context.react.getParentComponent();
node = utils.getParentComponent();
if (!node) {
return;
}
components.add(node, 2);
},

ObjectExpression: function(node) {
if (!context.react.isES5Component(node)) {
if (!utils.isES5Component(node)) {
return;
}
components.add(node, 2);
},

FunctionExpression: function(node) {
node = context.react.getParentComponent();
node = utils.getParentComponent();
if (!node) {
return;
}
components.add(node, 1);
},

FunctionDeclaration: function(node) {
node = context.react.getParentComponent();
node = utils.getParentComponent();
if (!node) {
return;
}
components.add(node, 1);
},

ArrowFunctionExpression: function(node) {
node = context.react.getParentComponent();
node = utils.getParentComponent();
if (!node) {
return;
}
if (node.expression && context.react.isReturningJSX(node)) {
if (node.expression && utils.isReturningJSX(node)) {
components.add(node, 2);
} else {
components.add(node, 1);
}
},

ThisExpression: function(node) {
node = context.react.getParentComponent();
node = utils.getParentComponent();
if (!node || !/Function/.test(node.type)) {
return;
}
Expand All @@ -375,10 +375,10 @@ function componentRule(rule, context) {
},

ReturnStatement: function(node) {
if (!context.react.isReturningJSX(node)) {
if (!utils.isReturningJSX(node)) {
return;
}
node = context.react.getParentComponent();
node = utils.getParentComponent();
if (!node) {
return;
}
Expand All @@ -387,7 +387,7 @@ function componentRule(rule, context) {
};

// Update the provided rule instructions to add the component detection
var ruleInstructions = rule(context, components);
var ruleInstructions = rule(context, components, utils);
var updatedRuleInstructions = util._extend({}, ruleInstructions);
Object.keys(detectionInstructions).forEach(function(instruction) {
updatedRuleInstructions[instruction] = function(node) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"devDependencies": {
"babel-eslint": "4.1.5",
"coveralls": "2.11.4",
"eslint": "1.9.0",
"eslint": "1.10.0",
"istanbul": "0.4.0",
"mocha": "2.3.4"
},
Expand Down

0 comments on commit 1b5d007

Please sign in to comment.