diff --git a/lib/rules/no-2.0.0-hooks.js b/lib/rules/no-2.0.0-hooks.js index 6142903..c890aa2 100644 --- a/lib/rules/no-2.0.0-hooks.js +++ b/lib/rules/no-2.0.0-hooks.js @@ -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.'; @@ -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); } }); diff --git a/lib/utils/imports.js b/lib/utils/imports.js index 31fe365..b4b021a 100644 --- a/lib/utils/imports.js +++ b/lib/utils/imports.js @@ -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); }