forcedotcom / lightning-language-server

LWC and Aura Language Servers - shipped as part of the Salesforce VSCode Extensions
https://forcedotcom.github.io/salesforcedx-vscode/
BSD 3-Clause "New" or "Revised" License
33 stars 48 forks source link

@api get recordId and @api set recordId detected in class declaration. Only one of the two needs to be decorated with @api. #464

Closed ytiq closed 2 years ago

ytiq commented 2 years ago

Summary

Short summary of what is going on or to provide context.

Steps To Reproduce:

  1. This is step 1.
  2. This is step 2. All steps should start with '1.'

Expected result

No Error from ESLint is shown

Actual result

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

Additional information

Here is an example of LWC component and error producing code snippet down below https://webcomponents.dev/edit/4TuiynUFc1ccniIlgo2L

import { LightningElement, api } from 'lwc';

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

If at any place in the project you have @api get in the component then adding @api set will give you an error

VS Code Version: 1.62

SFDX CLI Version: sfdx-cli/7.127.0 darwin-x64 node-v16.13.0

OS and version: macOs Catalina 10.15.7

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.

AllanOricil commented 2 years ago

https://github.com/salesforce/lwc/issues/2406 https://github.com/salesforce/eslint-config-lwc/issues/66

ytiq commented 2 years ago

@AllanOricil weirdly enough, I tried adding my code as a jest test in lwc-compiler and it passes, so it might not be directly related to the latest version of lightning-language-server. I tried looking into dependencies of VS Code plugins itself and it seems that the latest lwc-language-server is using "@lwc/compiler": "0.34.8" which is 3 years old, so might be related to it

randi274 commented 2 years ago

Thanks for logging this! Since we're tracking it over in the extensions repo with #3704, I'll close this issue in favor of that one for now.