Skip to content
This repository was archived by the owner on Sep 18, 2023. It is now read-only.

file-name-matches-element: TypeError: Cannot read properties of null (reading 'name') #57

Closed
silverwind opened this issue Apr 7, 2023 · 3 comments · Fixed by #58
Closed

Comments

@silverwind
Copy link
Contributor

Linted Line:

window.customElements.define('foo-bar', class extends HTMLElement {

Error:

TypeError: Cannot read properties of null (reading 'name')
Rule: "custom-elements/file-name-matches-element"
    at :matches(ClassDeclaration, ClassExpression)[superClass.name=/HTML.*Element/] (node_modules/eslint-plugin-custom-elements/lib/rules/file-name-matches-element.js:51:30)
    at ruleErrorHandler (node_modules/eslint/lib/linter/linter.js:1093:28)
    at node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (node_modules/eslint/lib/linter/node-event-generator.js:340:14)
    at CodePathAnalyzer.enterNode (node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:795:23)
    at node_modules/eslint/lib/linter/linter.js:1128:32
@keithamus
Copy link
Contributor

Thanks for the issue! I can get this fixed up next week unless you would like to contribute a fix?

It looks like we check the identifier node but a class expression in argument position doesn’t have one so it would need to be guarded with a ?.

@silverwind
Copy link
Contributor Author

I guess I can. So in this case, no name can be derived, so we skip rule basically for this file?

@silverwind
Copy link
Contributor Author

silverwind commented Apr 8, 2023

Figured it out: #58

silverwind added a commit to silverwind/eslint-plugin-custom-elements that referenced this issue Apr 8, 2023
keithamus added a commit that referenced this issue Apr 9, 2023
Fixes: #57

Co-authored-by: Keith Cirkel <keithamus@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants