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

@stencil/async-methods is not working properly #15

Open
adrianiskandar opened this issue Sep 11, 2020 · 15 comments
Open

@stencil/async-methods is not working properly #15

adrianiskandar opened this issue Sep 11, 2020 · 15 comments

Comments

@adrianiskandar
Copy link

adrianiskandar commented Sep 11, 2020

Working with the latest version of this plugin:
"@stencil/eslint-plugin": "^0.3.1",
We discover is not behaving as expected, when we run eslint is throwing the following error:

error External @method() expandPopover() must return a Promise. Consider prefixing the method with async, such as @method() async expandPopover() @stencil/async-methods

But we have the async decorator in the method:

    /**
     * some comment
     */
    @Method()
    async expandPopover(): Promise<void> {
        if(this.trigger === PopoverTooltipTrigger.Conditional){
            this.openPopover();
        }
    }

What is worse is that if you run the eslint --fix command, it will generate this code:

    /**
     * some comment
     */


    /**
     * some comment
     */
    

    /**
     * some comment
     */
    

    /**
     * some comment
     */
    @Method()
    asyncasync    async expandPopover(): Promise<void> {
        if(this.trigger === PopoverTooltipTrigger.Conditional){
            this.openPopover();
        }
    }

Is multiplying the comment by 4 and is adding multiple async words before the method declaration.

We couldn't figure it out how to fix this, can you help?
Thanks.

@shanswami
Copy link

I also have this exact issue

@gtranter
Copy link

I also have the same issue - any update? It's been over a year. Using version 0.3.1.

@gtranter
Copy link

gtranter commented Oct 1, 2021

After quite a bit of experimentation, I was able to get rid of the error in my project by adding to the .eslintrc.json as recommended in the readme:

  "parserOptions": {
    "project": "./tsconfig.json"
  },

HOWEVER, if you legitimately have this error, such as code like:

@Method()
sayHello() {
    return "Hello";
}

the fixer still generates duplicate jsDoc blocks - in my case 1,023 blocks or 5,115 lines, AND doesn't fix the problem - the async keyword is still missing and the error persists.

So even though the error can be avoided, the rule is still useless because using --fix will wreak havoc on code.

@rwaskiewicz
Copy link
Contributor

Hey @adrianiskandar @gtranter,

I took a stab at reproducing this this afternoon, and wasn't able to successfully. Would it be possible for either of you to create a minimal reproduction & push it to github so that I can pull it down?

Apologies this took so long to get to - the new Stencil team and I are starting to put some effort towards fixing up this library.

@rwaskiewicz rwaskiewicz added the Awaiting Reply Further information is requested label Oct 8, 2021
@gtranter
Copy link

gtranter commented Oct 8, 2021

@rwaskiewicz Here's a demo repo: https://github.com/gtranter/stencil-eslint-async-methods-bug. Just run npm run lint -- --fix after installing.

@rwaskiewicz rwaskiewicz added Reply Received and removed Awaiting Reply Further information is requested labels Oct 8, 2021
@rwaskiewicz
Copy link
Contributor

Thanks!

@mikkelrom
Copy link

I'm seeing this issue as well 🙂

@Stormix
Copy link

Stormix commented Jan 20, 2022

+1

3 similar comments
@danielleroux
Copy link

+1

@boakenfull
Copy link

+1

@ffaubry
Copy link

ffaubry commented Apr 6, 2023

+1

@rwaskiewicz rwaskiewicz removed their assignment Apr 6, 2023
@tfrijsewijk
Copy link

@adrianiskandar and @rwaskiewicz, please see this comment by @gtranter which mentions the parserOptions. For me this was also the solution. The autofix --fix is still broken though.

@thatdom
Copy link

thatdom commented Feb 1, 2024

+1

@IPospelova
Copy link

i have the same issue, get 800+ line of repeating comments.

@krbaio3
Copy link

krbaio3 commented Aug 30, 2024

The problem is here:

create(context) {
        const stencil = stencilComponentContext();
        const parserServices = context.parserServices;  // <--- HERE
        const typeChecker = parserServices.program.getTypeChecker();
        return Object.assign(Object.assign({}, stencil.rules), { 'MethodDefinition > Decorator[expression.callee.name=Method]': (decoratorNode) => {

When read context, the property is undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests