Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[require-await] throws #1077

Closed
fabiospampinato opened this issue Oct 13, 2019 · 2 comments
Closed

[require-await] throws #1077

fabiospampinato opened this issue Oct 13, 2019 · 2 comments
Labels
bug Something isn't working external This issue is with another package, not typescript-eslint itself has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@fabiospampinato
Copy link

Repro

{
  "rules": {
	"@typescript-eslint/require-await": "error"
  }
}
declare const cancelIdleCallback = ( await import ( '@types/requestidlecallback' ) ).default.cancel;

Expected Result

It shouldn't throw.

Actual Result

It throws.

Additional Info

This is the error:

Cannot set property 'hasAwait' of null
Occurred while linting /Users/fabio/Projects/notable/src/types.d.ts:10

Debug Dump

// lots of other lines about other files before this
  eslint:ignored-paths contains: +36ms
  eslint:ignored-paths   target   = "/Users/fabio/Projects/notable/src/types.d.ts" +0ms
  eslint:ignored-paths   base     = "/Users/fabio/Projects/notable" +0ms
  eslint:ignored-paths   relative = "src/types.d.ts" +0ms
  eslint:ignored-paths   result   = false +0ms
  eslint:file-enumerator Yield: types.d.ts +0ms
  eslint:cli-engine Lint /Users/fabio/Projects/notable/src/types.d.ts +36ms
  eslint:linter Linting code for /Users/fabio/Projects/notable/src/types.d.ts (pass 1) +1ms
  eslint:linter Verify +0ms
  eslint:linter With ConfigArray: /Users/fabio/Projects/notable/src/types.d.ts +0ms
  eslint:linter An error occurred while traversing +33ms
  eslint:linter Filename: /Users/fabio/Projects/notable/src/types.d.ts +0ms
  eslint:linter Line: 10 +0ms
  eslint:linter Parser Options: { ecmaVersion: 11,
  ecmaFeatures: { globalReturn: false, jsx: true },
  project: 'tsconfig.json',
  sourceType: 'module',
  useJSXTextNode: true } +0ms
  eslint:linter Parser Path: /Users/fabio/Projects/notable/node_modules/@typescript-eslint/parser/dist/parser.js +1ms
  eslint:linter Settings: { react: { pragma: 'React', version: 'detect' } } +0ms
Cannot set property 'hasAwait' of null
Occurred while linting /Users/fabio/Projects/notable/src/types.d.ts:10

Versions

package version
@typescript-eslint/eslint-plugin 2.3.4-alpha.5
@typescript-eslint/parser 2.3.3
TypeScript 3.6.4
ESLint 6.5.1
node 10.15.0
npm 6.4.1
@fabiospampinato fabiospampinato added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Oct 13, 2019
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for maintainers to take a look labels Oct 13, 2019
@garyking
Copy link
Contributor

A file with simply await a is enough to crash this rule. As long as the await <something> is outside an async function, the rule will throw.

[Error - 8:40:16 p.m.] ESLint stack trace:
[Error - 8:40:16 p.m.] TypeError: Cannot set property 'hasAwait' of null
Occurred while linting /Users/gary/Downloads/Unsorted/Code/ts-test/src/a.ts:1
    at AwaitExpression (/Users/gary/.dotfiles/node_modules/eslint/lib/rules/require-await.js:92:36)
    at listeners.(anonymous function).forEach.listener (/Users/gary/.dotfiles/node_modules/eslint/lib/linter/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/gary/.dotfiles/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/gary/.dotfiles/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/Users/gary/.dotfiles/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (/Users/gary/.dotfiles/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/Users/gary/.dotfiles/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:634:23)
    at nodeQueue.forEach.traversalInfo (/Users/gary/.dotfiles/node_modules/eslint/lib/linter/linter.js:936:32)
    at Array.forEach (<anonymous>)

@bradzacher bradzacher added has pr there is a PR raised to close this external This issue is with another package, not typescript-eslint itself labels Nov 15, 2019
@bradzacher
Copy link
Member

This is a bug within the base rule. It assumes global await is not allowed because espree throws a parsing error for it.

I've opened eslint/eslint#12571
I'll close this issue. Feel free to follow on there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working external This issue is with another package, not typescript-eslint itself has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
3 participants