dimanche 12 juin 2016

Distinguish methods and properties

The Problem:

I'm currently improving the valid-expect rule for the eslint-plugin-jasmine package trying to handle one more invalid Jasmine expect() usage when a matcher is not called:

expect(true).toBeDefined;

Valid usage:

expect(true).toBeDefined();

I'm getting pretty close - I can determine that there is a member expression on the expect():

// matcher was not called
MemberExpression: function (node) {
  if (node.object && node.object.callee.name === 'expect') {
    console.log(node.property)
  }
}

But the node.property in both valid and invalid cases is of an Identifier type:

Node {
  type: 'Identifier',
  start: 13,
  end: 24,
  loc: 
   SourceLocation {
     start: Position { line: 1, column: 13 },
     end: Position { line: 1, column: 24 } },
  range: [ 13, 24 ],
  name: 'toBeDefined' }

And there is nothing obvious indicating that this is a property or a method.

The Question:

How can I determine if a property is callable or not in ESLint?

Aucun commentaire:

Enregistrer un commentaire