salesforce / eslint-config-lwc

Opinionated ESLint configurations for LWC projects
MIT License
114 stars 35 forks source link

LWC1112: @api get connection and @api set connection detected in class declaration. Only one of the two needs to be decorated with @api. #66

Closed AllanOricil closed 2 years ago

AllanOricil commented 3 years ago

When a Set is before a Get and it is annotaded with @api eslint indicates the following error:

LWC1112: @api get connection and @api set connection detected in class declaration. Only one of the two needs to be decorated with @api.

image

When the Set is below the Get the issue is fixed, but eslint does not recommend this. The order of Get and Set should not be considered on this rule.

image

nolanlawson commented 3 years ago

Thanks for reporting. Just to be clear, which eslint preset/rule recommends putting set after get?

Also, does it work for you if you move the @api before the set? This should work:

  _foo

  get foo () {
    return this._foo
  }

  @api
  set foo (val) {
    this._foo = val
  }
AllanOricil commented 3 years ago

@nolanlawson this is the text that appears when I hover over the lint error

c:\Users\allan_000\workspace\vodafone\sf-metadata\agentAllFlowsNewIssueEnglish.js: LWC1112: @api get connection and @api set connection detected in class declaration. Only one of the two needs to be decorated with @api.lwc
(property) agentAllFlowsNewIssueEnglish.connection: any

These scenarios also do not work

image image image

This is the only way that makes it work

image

AllanOricil commented 3 years ago

I just noticed that this is not an ESLint error. It is a lwc api error. Should I move this error to the lwc repository or leave it here?

AllanOricil commented 3 years ago

This is how my .eslintrc is configured

{
  "extends": ["@salesforce/eslint-config-lwc/recommended"]
}
AllanOricil commented 3 years ago

@nolanlawson I found that this issue was resolved in 2019 https://github.com/salesforce/lwc/issues/1113

I will close this issue here

ytiq commented 2 years ago

found an example that fails it @AllanOricil .

import { LightningElement, api } from 'lwc';

export default class Testsdfsdf extends LightningElement {
    @api get b() {}
    @api set a(value) { }
    get a() {}
}

If anywhere in your code you have @api getter, then it fails other parts where you have @api setter

AllanOricil commented 2 years ago

found an example that fails it @AllanOricil .

import { LightningElement, api } from 'lwc';

export default class Testsdfsdf extends LightningElement {
    @api get b() {}
    @api set a(value) { }
    get a() {}
}

If anywhere in your code you have @api getter, then it fails other parts where you have @api setter @ytiq The example I showed above was fixed after I reopened vscode. I think the language server that has the rules was not loaded somehow.

ytiq commented 2 years ago

I was getting error on existing code base, tried re-opening. Also tried making new components and testing with them. Once you have mix of @api getter and @api setters in one file, lwc-server stops working

AllanOricil commented 2 years ago

@pmdartus @nolanlawson I confirm @ytiq isolated the problem correctly. It is not an issue related to vscode not loading the language server.

steps:

1 - create a lwc with the following code

import { LightningElement, api } from 'lwc';

export default class Test extends LightningElement {

    @api set test1(value){}
    get test2(){}
}

2 - verify it does work and no language server error is present 3 - change the lwc code to this one

import { LightningElement, api } from 'lwc';

export default class Test extends LightningElement {

    @api set test1(value){}
    @api get test2(){}
}

4 - verify that now you have the error from this issue 5 - conclude that in a class you can't decorate a getter and a setter with @api. You must choose one of them in the whole js file to decorate with @api. In other words, either all getters are decorated with @api, or all setters.

pmdartus commented 2 years ago

As far as I understand the issue, it is reported by the language server running an outdated version of the LWC compiler and is unrelated to the eslint plugin. I will close this issue in favor of https://github.com/forcedotcom/lightning-language-server/issues/464.

ytiq commented 2 years ago

@pmdartus lightning-language-server is not being updated, do you know, by any chance who maintains the VS code plugin, so I can write the issue in the correct place? Because this issue makes the plugin unusable.

pmdartus commented 2 years ago

@seksenov Do you know who owns the lightning language server VSCode extension?