salesforce / eslint-plugin-lwc

Official ESLint rules for LWC
MIT License
98 stars 32 forks source link

Imperative Apex expects passed objects to include spaces #151

Closed mvogelgesang closed 6 months ago

mvogelgesang commented 6 months ago

When calling Apex imperatively within an LWC, an object is used to pass params. However, if a space between the key and value is missing, Apex will report a null pointer exception. For example:

import { LightningElement, api } from "lwc";
import getInfo from "@salesforce/apex/AdoptionVolunteerEvent.getInfo";

export default class MyClass extends LightningElement {
@api recordId;

eventList = [];
  connectedCallback() {
-    getRelatedRecords({recordId:this.recordId})
+    getRelatedRecords({recordId: this.recordId})
      .then((response) => {
        eventList = response.data;
      }).catch((error) => {
        console.error(error);
     });
}

This can be overcome by setting format on save in the IDE but if that is not enabled, there is not a clear indication to the developer that there is an issue.

nolanlawson commented 6 months ago

Thanks for reporting. Are you reporting that Apex has this issue, or that the ESLint plugin should accommodate the issue and tell you to remove a space in this case?

jmsjtu commented 6 months ago

Spoke with @mvogelgesang and the issue is not reproducible, please let us know if you run into this again in the future!