eslint-plugin-ember-best-practices icon indicating copy to clipboard operation
eslint-plugin-ember-best-practices copied to clipboard

ExperimentalSpreadProperty nodes break rules

Open mwpastore opened this issue 8 years ago • 1 comments

Having ExperimentalSpreadProperty node properties in the tree seems to break at least no-2.0.0-hooks and no-side-effect-cp. The problem seems to be rooted in the assumption that each node property has a key property, but ExperimentalSpreadProperty node properties have neither key nor value properties. Is the fix as simple as modifying these rules to ignore node properties without key properties?

Node {
  type: 'ExperimentalSpreadProperty',
  start: 693,
  end: 718,
  loc: 
   SourceLocation {
     start: Position { line: 29, column: 6 },
     end: Position { line: 29, column: 31 } },
  range: [ 693, 718 ],
  argument: 
   Node {
     type: 'Identifier',
     start: 696,
     end: 718,
     loc: SourceLocation { start: [Object], end: [Object] },
     range: [ 696, 718 ],
     name: 'resolvedProjectPayload' } }
The Broccoli Plugin: [SimpleConcatConcat] failed with:
TypeError: Cannot read property 'name' of undefined
    at ObjectExpression.node.properties.forEach (/Users/mwp/Code/pow/juliet/node_modules/eslint-plugin-ember-best-practices/lib/rules/no-2.0.0-hooks.js:25:34)
    at Array.forEach (native)
    at Linter.ObjectExpression (/Users/mwp/Code/pow/juliet/node_modules/eslint-plugin-ember-best-practices/lib/rules/no-2.0.0-hooks.js:23:25)
// lib/rules/no-2.0.0-hooks.js
23: node.properties.forEach((property) => {
24:   console.log(property); // see above for output
25:   let name = property.key.name; // boom!

mwpastore avatar Jul 07 '17 00:07 mwpastore

Is the fix as simple as modifying these rules to ignore node properties without key properties?

This seems reasonable to me, though thorough test cases would help better confirm.

trentmwillis avatar Jul 07 '17 03:07 trentmwillis