Skip to content

TypeError: Cannot read property 'name' of undefined at require-default-props.js:291:23 #1029

Closed
singapore/lint-condo
#240
@jwarykowski

Description

@jwarykowski

Overview

Seen another instance of the Cannot read property 'name' issue which has already been raised in issue #1021. Again using the following package versions:

Error returned is:

Cannot read property 'name' of undefined
TypeError: Cannot read property 'name' of undefined
    at isPropTypeAnnotation (/Users/user/path/org/project/node_modules/eslint-plugin-react/lib/rules/require-default-props.js:291:23)
    at Object.ClassProperty (/Users/user/path/org/project/node_modules/eslint-plugin-react/lib/rules/require-default-props.js:461:13)

After checking require-default-props.js its failing at this point:

function isPropTypeAnnotation(node) {
  return (node.key.name === 'props' && !!node.typeAnnotation);
}

After inspecting the node I have the following returned:

Node {
  type: 'ClassProperty',
  start: 301,
  end: 414,
  loc: 
   SourceLocation {
     start: Position { line: 11, column: 2 },
     end: Position { line: 15, column: 3 } },
  computed: false,
  variance: null,
  static: true,
  value: 
   Node {
     type: 'ObjectExpression',
     start: 320,
     end: 414,
     loc: SourceLocation { start: [Object], end: [Object] },
     properties: [ [Object], [Object], [Object] ],
     range: [ 320, 414 ],
     _babelType: 'ObjectExpression' },
  range: [ 301, 414 ],
  _babelType: 'ClassProperty',
  parent: 
   Node {
     type: 'ClassBody',
     start: 296,
     end: 1235,
     loc: SourceLocation { start: [Object], end: [Object] },
     body: [ [Circular], [Object], [Object], [Object] ],
     range: [ 296, 1235 ],
     _babelType: 'ClassBody',
     parent: 
      Node {
        type: 'ClassDeclaration',
        start: 265,
        end: 1235,
        loc: [Object],
        id: [Object],
        superClass: [Object],
        body: [Circular],
        decorators: [Object],
        range: [Object],
        _babelType: 'ClassDeclaration',
        parent: [Object] } } }

After inspecting then source in question returned from context.getFilename() and checking the line number, I have the following code:

export default class Anchor extends Component {
  static propTypes = {
    active: PropTypes.bool,
    underline: PropTypes.bool,
    tooltip: PropTypes.array,
 }
 ...
}

After checking the source comments here this all appears to be valid.

As you can see in the above node output there is no key property? Has there been a breaking change here? Any insight would be greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions