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

prefer-query-selector: Cannot read property 'type' of undefined #903

Closed
AriPerkkio opened this issue Nov 22, 2020 · 0 comments · Fixed by #906
Closed

prefer-query-selector: Cannot read property 'type' of undefined #903

AriPerkkio opened this issue Nov 22, 2020 · 0 comments · Fixed by #906
Assignees
Labels

Comments

@AriPerkkio
Copy link
Contributor

Hello, I'm testing stability of well known community ESlint plugins with eslint-remote-tester. This eslint plugin seems to contain a rule which causes linter to crash. ESlint rules should not crash in any condition since this makes all valid linting problems disappear. If this is a false flag please let me know.

Crashing rule:

prefer-query-selector

Minimal repro:

document.getElementsByTagName()

This causes ESlint to dispaly an error:

TypeError: Cannot read property 'type' of undefined
Occurred while linting <text>:829
    at canBeFixed (/<root-path-removed>/eslint-plugin-unicorn/rules/prefer-query-selector.js:59:11)

Real-world examples:

eslint-remote-tester-results/mattermost_mattermost-webapp.md

Rule: prefer-query-selector

  • Message: Cannot read property 'type' of undefined Occurred while linting <text>:829
  • Path: mattermost/mattermost-webapp/actions/websocket_actions.test.jsx
  • Link
            handlePluginEnabled({data: {manifest}});

            expect(document.createElement).toHaveBeenCalledWith('script');
            expect(document.getElementsByTagName).toHaveBeenCalledTimes(1);
            expect(document.getElementsByTagName()[0].appendChild).toHaveBeenCalledTimes(1);
            expect(mockScript.onload).toBeInstanceOf(Function);

            // Pretend to be a browser, invoke onload
            mockScript.onload();
            expect(initialize).toHaveBeenCalledWith(expect.anything(), store);
TypeError: Cannot read property 'type' of undefined
Occurred while linting <text>:829
    at canBeFixed (/<root-path-removed>/eslint-remote-tester/configs/node_modules/eslint-plugin-unicorn/rules/prefer-query-selector.js:59:11)
    at CallExpression (/<root-path-removed>/eslint-remote-tester/configs/node_modules/eslint-plugin-unicorn/rules/prefer-query-selector.js:117:8)
    at /<root-path-removed>/eslint-remote-tester/node_modules/eslint/lib/linter/safe-emitter.js:49:25
    at Array.forEach (<anonymous>)
    at Object.emit (/<root-path-removed>/eslint-remote-tester/node_modules/eslint/lib/linter/safe-emitter.js:47:38)
    at NodeEventGenerator.applySelector (/<root-path-removed>/eslint-remote-tester/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/<root-path-removed>/eslint-remote-tester/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (/<root-path-removed>/eslint-remote-tester/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/<root-path-removed>/eslint-remote-tester/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)
    at /<root-path-removed>/eslint-remote-tester/node_modules/eslint/lib/linter/linter.js:966:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants