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

TypeError: Cannot read property 'length' of undefined #2439

Closed
3 tasks done
samualtnorman opened this issue Aug 29, 2020 · 3 comments
Closed
3 tasks done

TypeError: Cannot read property 'length' of undefined #2439

samualtnorman opened this issue Aug 29, 2020 · 3 comments
Labels
bug Something isn't working external This issue is with another package, not typescript-eslint itself package: parser Issues related to @typescript-eslint/parser

Comments

@samualtnorman
Copy link

samualtnorman commented Aug 29, 2020

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

I was writing a custom rule to work along side the typescript-eslint plugin but I ran into an issue caused by the parser.

eslint-plugin-test/index.js

exports.rules = {
    test: {
        create(context) {
            return {
                "anyNode ~ *": node => {
                    context.report({
                        message: "test",
                        node
                    })

                    // this code doesn't get a chance to get called :(
                }
            }
        }
    }
}

project/.eslintrc.json

{
	"parser": "@typescript-eslint/parser",
	"plugins": [ "eslint-plugin-test" ],
	"rules": { "test/test": "error" }
}

project/index.ts

const foo: string = "bar"

Expected Result

I expect it to lint the code, without errors.

Actual Result

Oops! Something went wrong! :(

ESLint: 7.7.0

TypeError: Cannot read property 'length' of undefined
Occurred while linting /home/samual/test/index.ts:1
    at u (/home/samual/test/node_modules/esquery/dist/esquery.min.js:1:31904)
    at Function.l [as matches] (/home/samual/test/node_modules/esquery/dist/esquery.min.js:1:30807)
    at NodeEventGenerator.applySelector (/home/samual/test/node_modules/eslint/lib/linter/node-event-generator.js:253:21)
    at NodeEventGenerator.applySelectors (/home/samual/test/node_modules/eslint/lib/linter/node-event-generator.js:281:22)
    at NodeEventGenerator.enterNode (/home/samual/test/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/home/samual/test/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:673:23)
    at /home/samual/test/node_modules/eslint/lib/linter/linter.js:949:32
    at Array.forEach (<anonymous>)
    at runRules (/home/samual/test/node_modules/eslint/lib/linter/linter.js:944:15)
    at Linter._verifyWithoutProcessors (/home/samual/test/node_modules/eslint/lib/linter/linter.js:1170:31)

Additional Info

Here's the debug output.
I have no idea how any of typescript-eslint works, but I definitely know esquery tries to access an array that doesn't exist, and it only does this when the code to be linted is using typescript specific features. This also only happens with the adjacent sibling operator followed by a wildcard.

[samual@Samual-PC test]$ npx eslint index.ts --debug
  eslint:cli CLI args: [ 'index.ts', '--debug' ] +0ms
  eslint:cli Running on files +3ms
  eslint:config-array-factory Loading JSON config file: /home/samual/test/package.json +0ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], basePath: '/home/samual/test', loose: false } ] +0ms
  eslint:ignore-pattern   processed: { basePath: '/home/samual/test', patterns: [ '/**/node_modules/*' ] } +1ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], basePath: '/home/samual/test', loose: false } ] +0ms
  eslint:ignore-pattern   processed: { basePath: '/home/samual/test', patterns: [ '/**/node_modules/*' ] } +1ms
  eslint:file-enumerator Start to iterate files: [ 'index.ts' ] +0ms
  eslint:file-enumerator File: /home/samual/test/index.ts +0ms
  eslint:cascading-config-array-factory Load config files for /home/samual/test. +0ms
  eslint:cascading-config-array-factory No cache found: /home/samual/test. +0ms
  eslint:config-array-factory Loading JSON config file: /home/samual/test/.eslintrc.json +4ms
  eslint:config-array-factory Config file found: /home/samual/test/.eslintrc.json +0ms
  eslint:config-array-factory Loading parser "@typescript-eslint/parser" from /home/samual/test/.eslintrc.json +0ms
  eslint:config-array-factory Loaded: @typescript-eslint/parser@3.10.1 (/home/samual/test/node_modules/@typescript-eslint/parser/dist/index.js) +1ms
  eslint:config-array-factory Loading plugin "eslint-plugin-test" from /home/samual/test/.eslintrc.json +137ms
  eslint:config-array-factory Loaded: eslint-plugin-test@1.0.0 (/home/samual/eslint-plugin-test/index.js) +1ms
  eslint:config-array-factory Plugin /home/samual/eslint-plugin-test/index.js loaded in: 0ms +0ms
  eslint:cascading-config-array-factory No cache found: /home/samual. +140ms
  eslint:cascading-config-array-factory Stop traversing because of considered root. +0ms
  eslint:cascading-config-array-factory Configuration was determined: ConfigArray(2) [ { type: 'config', name: 'DefaultIgnorePattern', filePath: '', criteria: null, env: undefined, globals: undefined, ignorePattern: IgnorePattern { patterns: [Array], basePath: '/home/samual/test', loose: false }, noInlineConfig: undefined, parser: undefined, parserOptions: undefined, plugins: undefined, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: undefined, settings: undefined }, { type: 'config', name: '.eslintrc.json', filePath: '/home/samual/test/.eslintrc.json', criteria: null, env: undefined, globals: undefined, ignorePattern: undefined, noInlineConfig: undefined, parser: { error: null, filePath: '/home/samual/test/node_modules/@typescript-eslint/parser/dist/index.js', id: '@typescript-eslint/parser', importerName: '.eslintrc.json', importerPath: '/home/samual/test/.eslintrc.json' }, parserOptions: undefined, plugins: { test: [Object] }, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: { 'test/test': 'error' }, settings: undefined } ] on /home/samual/test +1ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], basePath: '/home/samual/test', loose: false } ] +142ms
  eslint:ignore-pattern   processed: { basePath: '/home/samual/test', patterns: [ '/**/node_modules/*' ] } +0ms
  eslint:ignore-pattern Check {
  filePath: '/home/samual/test/index.ts',
  dot: false,
  relativePath: 'index.ts',
  result: false
} +1ms
  eslint:cli-engine Lint /home/samual/test/index.ts +0ms
  eslint:linter Linting code for /home/samual/test/index.ts (pass 1) +0ms
  eslint:linter Verify +0ms
  eslint:linter With ConfigArray: /home/samual/test/index.ts +0ms
  eslint:linter An error occurred while traversing +19ms
  eslint:linter Filename: /home/samual/test/index.ts +0ms
  eslint:linter Line: 1 +0ms
  eslint:linter Parser Options: { ecmaVersion: undefined } +0ms
  eslint:linter Parser Path: /home/samual/test/node_modules/@typescript-eslint/parser/dist/index.js +0ms
  eslint:linter Settings: {} +0ms

Oops! Something went wrong! :(

ESLint: 7.7.0

TypeError: Cannot read property 'length' of undefined
Occurred while linting /home/samual/test/index.ts:1
    at u (/home/samual/test/node_modules/esquery/dist/esquery.min.js:1:31904)
    at Function.l [as matches] (/home/samual/test/node_modules/esquery/dist/esquery.min.js:1:30807)
    at NodeEventGenerator.applySelector (/home/samual/test/node_modules/eslint/lib/linter/node-event-generator.js:253:21)
    at NodeEventGenerator.applySelectors (/home/samual/test/node_modules/eslint/lib/linter/node-event-generator.js:281:22)
    at NodeEventGenerator.enterNode (/home/samual/test/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/home/samual/test/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:673:23)
    at /home/samual/test/node_modules/eslint/lib/linter/linter.js:949:32
    at Array.forEach (<anonymous>)
    at runRules (/home/samual/test/node_modules/eslint/lib/linter/linter.js:944:15)
    at Linter._verifyWithoutProcessors (/home/samual/test/node_modules/eslint/lib/linter/linter.js:1170:31)

Versions

package version
@typescript-eslint/parser 3.10.1
TypeScript 4.0.2
ESLint 7.7.0
node 14.9.0

Thanks.

@samualtnorman samualtnorman added package: parser Issues related to @typescript-eslint/parser triage Waiting for maintainers to take a look labels Aug 29, 2020
@bradzacher
Copy link
Member

bradzacher commented Aug 31, 2020

Hmm.. This looks like a bug in (or a feature of?) esquery.

It uses its own visitor keys for 3 selectors:

Our parser returns our extended list of visitor-keys

return { ast, services, scopeManager, visitorKeys };

But because esquery is hard-coded to use estraverse.VisitorKeys, it'll never use our visitor keys.

I've filed an issue with eslint. We'll see what we can do: eslint/eslint#13639

@bradzacher bradzacher added bug Something isn't working dependencies Issue about dependencies of the package and removed triage Waiting for maintainers to take a look labels Aug 31, 2020
@bradzacher bradzacher added external This issue is with another package, not typescript-eslint itself and removed dependencies Issue about dependencies of the package labels Aug 31, 2020
@bradzacher
Copy link
Member

This is a confirmed bug in ESLint/esquery/estraverse.
See the conversation in the aforementioned ESLint issue.
As there's nothing for us to action in this project, I'm going to close this issue.

@samualtnorman
Copy link
Author

thank you for looking into this

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 1, 2020
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 package: parser Issues related to @typescript-eslint/parser
Projects
None yet
Development

No branches or pull requests

2 participants