firebase 解析错误:意外标记=>eslint

eaf3rand  于 2023-03-03  发布在  其他
关注(0)|答案(1)|浏览(146)

我在Google上搜索并尝试了不同的方法,但似乎async函数导致了一个错误,称=>是意外的。我尝试将ecmaVersion添加到. eslintrc.js中,但没有结果。
我的代码:

exports.badgeUpdated = functions.firestore
    .document("badges/{docId}")
    .onUpdate(async (change, _) => {
      //get the document that has changed and the new fieldvalue
      const newObjectId = change.after.id;
      const newObject = change.after.data();
      const newBadgeName = newObject.badgeName;
      console.log(`New BadgeName ${newBadgeName}`);
      //Search badge doc with changed ID and set new name
      const badgedRef = admin
        .firestore()
        .collectionGroup("badgeCollection")
        .where("id", "==", newObjectId).get();
      console.log(`Queryresult ${(await badgedRef).docs}`);
      return null;
});

linter在抱怨第三行my. eslintrc. js:

module.exports = {
  root: true,
  env: {
    es6: true,
    node: true,
  },
  extends: [
    "eslint:recommended",
    "google",
  ],
  parserOptions: {
    "ecmaFeatures": {
      "ecmaVersion": 2022,
    },
    "sourceType": "module",
  },
  rules: {
    "quotes": ["error", "double"],
    "linebreak-style": ["error", "windows"],
  },

};
omqzjyyz

omqzjyyz1#

ecmaVersion不应在ecmaFeatures中。
https://eslint.org/docs/latest/use/configure/language-options

module.exports = {
  root: true,
  env: {
    es6: true,
    node: true,
  },
  extends: [
    "eslint:recommended",
    "google",
  ],
  parserOptions: {
    "ecmaVersion": 2022,
    "sourceType": "module",
  },
  rules: {
    "quotes": ["error", "double"],
    "linebreak-style": ["error", "windows"],
  },
};

此外,请确保您使用的是最新版本的ESLint。

相关问题