getify / eslint-plugin-proper-arrows

ESLint rules to ensure proper arrow function definitions
MIT License
305 stars 14 forks source link

Elision of destructured function parameters causes crash #16

Closed palnes closed 5 years ago

palnes commented 5 years ago

While linting the following code, the plugin crashed:

export const clampData = data => flow(
    // Trim left side of the array
    dropWhile(([, y]) => y === null),
    // Trim right side of the array
    dropRightWhile(([, y]) => y === null),
)(data);

The error message:

TypeError: Cannot read property 'type' of null
    at getAllIdentifiers (./node_modules/@getify/eslint-plugin-proper-arrows/lib/index.js:628:12)
    at getAllIdentifiers (./node_modules/@getify/eslint-plugin-proper-arrows/lib/index.js:635:23)
    at exit (./node_modules/@getify/eslint-plugin-proper-arrows/lib/index.js:66:25)
    at listeners.(anonymous function).forEach.listener (./node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (./node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (./node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (./node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.leaveNode (./node_modules/eslint/lib/util/node-event-generator.js:303:14)
    at CodePathAnalyzer.leaveNode (./node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:654:23)

Expected: Skipping entries in an array is allowed (but perhaps not friendly) when destructuring. However, this entry will be returned as a null when iterating. A fix would probably entail checking for a null entry before checking the properties.

getify commented 5 years ago

Thanks, fixed!