Closed AllanOricil closed 2 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
}
@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
This is the only way that makes it work
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?
This is how my .eslintrc
is configured
{
"extends": ["@salesforce/eslint-config-lwc/recommended"]
}
@nolanlawson I found that this issue was resolved in 2019 https://github.com/salesforce/lwc/issues/1113
I will close this issue here
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
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.
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
@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.
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.
@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.
@seksenov Do you know who owns the lightning language server VSCode extension?
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.
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.