Sathish
Sathish

Reputation: 68

EsLint /prettier giving unnecessary errors and providing auto adding paranthesis to the end of the expression

I am using redux saga for asynchronous calls, I made an API call and store the data in local storage but eslint/prettier is auto adding parenthesis to assignment operator at the end of line. I don't find any relevant solution.

function fetchData(services: requiredServices) {
  return function*() {
    try {
      let datafromlocalStorage = JSON.parse(localStorage.getItem("studentInfo") || '{}');
      if (datafromlocalStorage && Object.keys(datafromlocalStorage).length < 1) {
        const { data } = yield call(services.dataManagement.getData);
        datafromlocalStorage = data;
        localStorage.setItem("studentInfo", JSON.stringify(data));
      }
      yield put(actions.saveContnet(datafromlocalStorage))
    } catch(e) {
    }
  }
}

It's giving error at the last line of try block, saying expression expected.

Upvotes: -1

Views: 56

Answers (1)

Drew Reese
Drew Reese

Reputation: 203348

The catch block is expecting at least one statement. If you just need to catch any thrown errors or rejected promises and don't care to handle them, then add a comment line, e.g // ignored.

function fetchData(services: requiredServices) {
  return function*() {
    try {
      let datafromlocalStorage = JSON.parse(
        localStorage.getItem("studentInfo") || '{}'
      );
      if (datafromlocalStorage && 
        Object.keys(datafromlocalStorage).length < 1
      ) {
        const { data } = yield call(services.dataManagement.getData);
        datafromlocalStorage = data;
        localStorage.setItem("studentInfo", JSON.stringify(data));
      }
      yield put(actions.saveContnet(datafromlocalStorage));
    } catch {
      // ignored
    }
  }
}

Upvotes: 0

Related Questions