Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Overloaded method signatures failing on certain eslint rules #389

Closed
ismail-syed opened this issue Sep 26, 2017 · 7 comments
Closed

Overloaded method signatures failing on certain eslint rules #389

ismail-syed opened this issue Sep 26, 2017 · 7 comments

Comments

@ismail-syed
Copy link

What version of TypeScript are you using?
2.5.2

What version of typescript-eslint-parser are you using?
8.0.0

What code were you trying to parse?

export class Test {
  constructor() {
  }
  public test(param1: Number): Test;
  public test(param1: Test): Test;
  public test(param1: any): Test {
      return new Test();
    }
}

What did you expect to happen?
With the following rules enabled, I would expect the code above to be parsed. The issue seems to be that parsing overloaded method signatures, with the following eslint rules enabled fails.

    "rules": {
      "array-callback-return": "error",
      "getter-return": "error",
      "strict": "error",
      "lines-around-directive": "error",
      "no-empty-function": "error"
    }

Turning off all those rules, and enabling them individually fails as well.

What happened?

$ eslint . --ext .ts --max-warnings 0
Cannot read property 'type' of null
TypeError: Cannot read property 'type' of null
    at EventEmitter.onCodePathStart (/Users/ismailsyed/src/github.com/ismail-syed/typescript-eslint-parser-example/node_modules/eslint/lib/rules/array-callback-return.js:193:34)
n.js:193:34)
    at emitTwo (events.js:130:20)
    at EventEmitter.emit (events.js:213:7)                                                                                                                           lyzer.js:360:30)
    at processCodePathToEnter (/Users/ismailsyed/src/github.com/ismail-syed/typescript-eslint-parser-example/node_modules/eslint/lib/code-path-analysis/code-path-ana-analyzer.js:603:9)
lyzer.js:360:30)
    at CodePathAnalyzer.enterNode (/Users/ismailsyed/src/github.com/ismail-syed/typescript-eslint-parser-example/node_modules/eslint/lib/code-path-analysis/code-path
-analyzer.js:603:9)
    at Traverser.enter (/Users/ismailsyed/src/github.com/ismail-syed/typescript-eslint-parser-example/node_modules/eslint/lib/linter.js:962:32)    at Traverser.__execute (/Users/ismailsyed/src/github.com/ismail-syed/typescript-eslint-parser-example/node_modules/estraverse/estraverse.js:397:31)
    at Traverser.traverse (/Users/ismailsyed/src/github.com/ismail-syed/typescript-eslint-parser-example/node_modules/estraverse/estraverse.js:501:28)
    at Traverser.traverse (/Users/ismailsyed/src/github.com/ismail-syed/typescript-eslint-parser-example/node_modules/eslint/lib/util/traverser.js:31:22)
    at Linter._verifyWithoutProcessors (/Users/ismailsyed/src/github.com/ismail-syed/typescript-eslint-parser-example/node_modules/eslint/lib/linter.js:959:19)

Example repo:
https://github.com/ismail-syed/typescript-eslint-parser-example

@j-f1
Copy link
Contributor

j-f1 commented Sep 26, 2017

I think they’re checking the body of the function expressions, but that’s undefined, so they throw.

@ismail-syed
Copy link
Author

Thanks for the suggestion @j-f1. Taking a stab at fixing these failures in eslint/eslint

@JamesHenry
Copy link
Member

Thanks a lot for working on this @ismail-syed!

Unfortunately, it seems that modifying the core rules is not going to be a sustainable way forward.

This is arguably not technically an issue with the parser, but rather how it integrates with the wider ESLint ecosystem. However, I am definitely happy to keep this open here to track.

I am going to think about the best way forward with this and also chat with the TypeScript team about it.

@j-f1
Copy link
Contributor

j-f1 commented Oct 22, 2017

How about FunctionOverloadDeclaration and MethodOverloadDeclaration?

@ismail-syed
Copy link
Author

Thanks for the update, @JamesHenry! Interested to hear what's decided for moving forward.

@ismail-syed
Copy link
Author

ismail-syed commented Nov 12, 2017

Doing a check here for node.body and breaking if it's undefined fixes the small issue I have logged above. Would this be an appropriate temporary fix for this?

@JamesHenry
Copy link
Member

This was finally fixed by #412. I added the source above as an integration test.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants