Skip to content

Commit 1ed014d

Browse files
committed
Guard against key-less nodes. Fixes #71
1 parent f8e9588 commit 1ed014d

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/rules/no-2.0.0-hooks.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*/
44
'use strict';
55

6+
const { get } = require('../utils/get');
7+
68
// TODO
79
// Write docs for this once we feel it should be recommended.
810
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 = {
2123
return {
2224
ObjectExpression(node) {
2325
node.properties.forEach((property) => {
24-
let name = property.key.name;
25-
if (MISTAKE_HOOKS.indexOf(name) > -1) {
26+
let name = get(property, 'key.name');
27+
if (name && MISTAKE_HOOKS.indexOf(name) > -1) {
2628
context.report(property, MESSAGE);
2729
}
2830
});

lib/utils/imports.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ function collectImportBindings(node, imports) {
77

88
if (sourceName) {
99
return node.specifiers.filter((specifier) => {
10-
return 'ImportSpecifier' === specifier.type && importedBindings.includes(specifier.imported.name);
10+
let name = get(specifier, 'imported.name');
11+
return 'ImportSpecifier' === specifier.type && name && importedBindings.includes(name);
1112
}).map((specifier) => specifier.local.name);
1213
}
1314

0 commit comments

Comments
 (0)