Skip to content

Commit

Permalink
Guard against key-less nodes. Fixes #71
Browse files Browse the repository at this point in the history
  • Loading branch information
mwpastore committed Sep 21, 2017
1 parent 388bdfe commit 11b7a3d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/rules/no-2.0.0-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/
'use strict';

const { get } = require('../utils/get');

// TODO
// Write docs for this once we feel it should be recommended.
const MESSAGE = 'Do not use the 2.0.0 hooks as they are not conducive to the programming model.';
Expand All @@ -21,8 +23,8 @@ module.exports = {
return {
ObjectExpression(node) {
node.properties.forEach((property) => {
let name = property.key.name;
if (MISTAKE_HOOKS.indexOf(name) > -1) {
let name = get(property, 'key.name');
if (name && MISTAKE_HOOKS.indexOf(name) > -1) {
context.report(property, MESSAGE);
}
});
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ function collectImportBindings(node, imports) {

if (sourceName) {
return node.specifiers.filter((specifier) => {
return 'ImportSpecifier' === specifier.type && importedBindings.includes(specifier.imported.name);
let name = get(specifier, 'imported.name');
return 'ImportSpecifier' === specifier.type && name && importedBindings.includes(name);
}).map((specifier) => specifier.local.name);
}

Expand Down

0 comments on commit 11b7a3d

Please sign in to comment.