stencil-community / stencil-eslint

ESLint rules specific to Stencil JS projects
MIT License
61 stars 34 forks source link

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

Open elwynelwyn opened 4 years ago

elwynelwyn commented 4 years ago

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;
casr commented 4 years ago

Yup, I just faced this issue too.

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

rwaskiewicz commented 3 years ago

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

ionitron-bot[bot] commented 2 years ago

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] commented 2 years ago

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!

brandongregoryscott commented 3 weeks ago

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;)