eslint / typescript-eslint-parser

An ESLint custom parser which leverages TypeScript ESTree to allow for ESLint to lint TypeScript source code.
Other
915 stars 92 forks source link

[body null]eslint scan .ts #496

Closed cyw3 closed 5 years ago

cyw3 commented 6 years ago

What version of TypeScript are you using? typescript@2.9.2

What version of typescript-eslint-parser are you using? typescript-eslint-parser@16.0.1

What code were you trying to parse?

declare module chrome {
    class Driver extends webdriver.WebDriver {
        constructor(opt_config?: webdriver.Capabilities, opt_service?: any, opt_flow?: webdriver.promise.ControlFlow);
        constructor(opt_config?: Options, opt_service?: any, opt_flow?: webdriver.promise.ControlFlow);
    }
}

What did you expect to happen? eslint can work well.

What happened? but eslint crash:

$ eslint --ext .ts test.ts

Cannot read property 'body' of null
TypeError: Cannot read property 'body' of null
    at checkForConstructor (/Users/xxx/node-v8.9.1/lib/node_modules/eslint/lib/rules/no-useless-constructor.js:167:42)
    at listeners.(anonymous function).forEach.listener (/Users/xxx/node-v8.9.1/lib/node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/xxx/node-v8.9.1/lib/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/xxx/node-v8.9.1/lib/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (/Users/xxx/node-v8.9.1/lib/node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (/Users/xxx/node-v8.9.1/lib/node_modules/eslint/lib/util/node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (/Users/xxx/node-v8.9.1/lib/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:632:23)
    at nodeQueue.forEach.traversalInfo (/Users/xxx/node-v8.9.1/lib/node_modules/eslint/lib/linter.js:861:28)
    at Array.forEach (<anonymous>)
jorgegonzalez commented 5 years ago

Were you able to solve this @cyw3?

infctr commented 5 years ago

Ran into same issue with code

declare class Foo {
  constructor(params: IFooParams);

  public setUserID(userId: string): void;

  public reachGoal(goal: string, object);
}

and debug info

  eslint:linter An error occurred while traversing +20ms
  eslint:linter Filename: /Users/infctr/Projects/itv-smarttv/app/modules/analytics/service/ymTransmitter/defines.d.ts +0ms
  eslint:linter Parser Options: { ecmaFeatures:
   { globalReturn: false,
     generators: false,
     objectLiteralDuplicateProperties: false,
     jsx: true },
  ecmaVersion: 9,
  sourceType: 'module' } +0ms
  eslint:linter Parser Path: typescript-eslint-parser +0ms
  eslint:linter Settings: { 'import/resolver': { node: { extensions: [Array], moduleDirectory: [Array] } },
  'import/ignore': [ 'node_modules', '\\.(coffee|scss|css|less|hbs|svg|json)$' ],
  react: { pragma: 'React', version: '16.0' },
  propWrapperFunctions: [ 'forbidExtraProps', 'exact', 'Object.freeze' ] } +0ms
Cannot read property 'body' of null
mysticatea commented 5 years ago

Closing as a duplicate of #485. Thank you.