stencil-eslint icon indicating copy to clipboard operation
stencil-eslint copied to clipboard

Throws error when a property does not have a type annotation.

Open elwynelwyn opened this issue 5 years ago • 4 comments

When adding the plugin to my eslint extends:

    "extends": [
        "plugin:@stencil/recommended",

I started getting the following error:

Oops! Something went wrong! :(

ESLint: 7.11.0

TypeError: Cannot read property 'typeAnnotation' of undefined
Occurred while linting C:\MyOrg\MyProj\src\components\org-component\org-component.tsx:14
    at getType (C:\MyOrg\MyProj\node_modules\@stencil\eslint-plugin\dist\index.js:65:32)
    at ClassProperty > Decorator[expression.callee.name=Element] (C:\MyOrg\MyProj\node_modules\@stencil\eslint-plug
in\dist\index.js:439:37)
    at C:\MyOrg\MyProj\node_modules\eslint\lib\linter\safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (C:\MyOrg\MyProj\node_modules\eslint\lib\linter\safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (C:\MyOrg\MyProj\node_modules\eslint\lib\linter\node-event-generator.js:254
:26)
    at NodeEventGenerator.applySelectors (C:\MyOrg\MyProj\node_modules\eslint\lib\linter\node-event-generator.js:28
3:22)
    at NodeEventGenerator.enterNode (C:\MyOrg\MyProj\node_modules\eslint\lib\linter\node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (C:\MyOrg\MyProj\node_modules\eslint\lib\linter\code-path-analysis\code-path-anal
yzer.js:711:23)
    at C:\MyOrg\MyProj\node_modules\eslint\lib\linter\linter.js:952:32
error Command failed with exit code 2.

The stacktrace pointed to my component, where I had a property with no type annotation:

@Component({
    tag: 'org-component',
    shadow: true,
})
export class OrgComponent implements ComponentWillLoad {
    @Element() host;

Enabling TypeScript's noImplicitAny and then adding a type annotation fixes this issue and lets the linter continue:

@Component({
    tag: 'org-component',
    shadow: true,
})
export class OrgComponent implements ComponentWillLoad {
    @Element() host: HTMLOrgComponentElement;

elwynelwyn avatar Oct 23 '20 03:10 elwynelwyn

Yup, I just faced this issue too.

An alternative workaround is that you can disable @stencil/element-type in your ESLint config.

casr avatar Nov 04 '20 12:11 casr

Thanks for this! Currently, this project doesn't support ESLint 7, although we're working on upgrading it to do so. I'll circle back and investigate once that's done

rwaskiewicz avatar Oct 08 '21 17:10 rwaskiewicz

Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Stencil, please create a new issue and ensure the template is fully filled out.

Thank you for using Stencil!

ionitron-bot[bot] avatar Apr 27 '22 15:04 ionitron-bot[bot]

Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Stencil, please create a new issue and ensure the template is fully filled out.

Thank you for using Stencil!

ionitron-bot[bot] avatar Oct 24 '22 16:10 ionitron-bot[bot]

This bug also exists when running the rule on ESLint V8, FWIW. I'm throwing up a PR that should fix this case and another similar case that I ran into, where an explicit any type annotation also throws a runtime error instead of reporting it/fixing it. (@Element() elm: any;)

brandongregoryscott avatar Oct 22 '24 18:10 brandongregoryscott