Firebase部署导致几个错误

bvuwiixz  于 2022-11-17  发布在  其他
关注(0)|答案(1)|浏览(140)

我使用Typescript在VS代码中创建了Firebase云函数,VS代码中没有显示错误。但是当我部署我的Firebase代码时,我收到了几条错误消息。为什么我收到了所有这些错误消息,为什么VS代码没有显示一条?我如何修复它,使VS代码显示错误?
错误:

8:1   error    More than 2 blank lines not allowed                   no-multiple-empty-lines
   9:1   error    This line has a length of 108. Maximum allowed is 80  max-len
  10:1   error    This line has a length of 120. Maximum allowed is 80  max-len
  19:1   error    This line has a length of 98. Maximum allowed is 80   max-len
  26:1   error    Expected indentation of 4 spaces but found 2          indent
  26:13  error    Strings must use doublequote                          quotes
  27:1   error    Expected indentation of 4 spaces but found 2          indent
  27:20  warning  'context' is defined but never used                   @typescript-eslint/no-unused-vars
  28:1   error    Expected indentation of 6 spaces but found 4          indent
  28:17  error    Strings must use doublequote                          quotes
  28:70  error    Missing semicolon                                     semi
  30:1   error    Expected indentation of 6 spaces but found 4          indent
  30:28  error    Missing semicolon                                     semi
  31:1   error    Expected indentation of 6 spaces but found 4          indent
  31:21  error    Missing semicolon                                     semi
  33:1   error    Expected indentation of 6 spaces but found 4          indent
  33:34  error    Missing semicolon                                     semi
  34:1   error    Expected indentation of 6 spaces but found 4          indent
  34:38  error    Missing semicolon                                     semi
  35:1   error    Expected indentation of 6 spaces but found 4          indent
  35:39  error    Missing semicolon                                     semi
  37:1   error    Expected indentation of 6 spaces but found 4          indent
  38:1   error    Expected indentation of 6 spaces but found 4          indent
  39:1   error    Expected indentation of 10 spaces but found 6         indent
  40:1   error    Expected indentation of 10 spaces but found 6         indent
  40:19  error    Strings must use doublequote                          quotes
  41:1   error    Expected indentation of 10 spaces but found 6         indent
  41:14  error    Strings must use doublequote                          quotes
  41:20  error    Strings must use doublequote                          quotes
  42:1   error    Expected indentation of 10 spaces but found 6         indent
  43:1   error    Expected indentation of 10 spaces but found 6         indent
  43:13  error    Expected parentheses around arrow function argument   arrow-parens
  44:1   error    Expected indentation of 12 spaces but found 8         indent
  44:31  error    Expected parentheses around arrow function argument   arrow-parens
  45:1   error    Expected indentation of 14 spaces but found 10        indent
  45:63  error    Missing semicolon                                     semi
  46:1   error    Expected indentation of 14 spaces but found 10        indent
  47:1   error    Expected indentation of 16 spaces but found 12        indent
  48:1   error    Expected indentation of 16 spaces but found 12        indent
  49:1   error    Expected indentation of 20 spaces but found 14        indent
  50:1   error    Expected indentation of 20 spaces but found 14        indent
  50:27  error    Strings must use doublequote                          quotes
  51:1   error    Expected indentation of 20 spaces but found 14        indent
  51:22  error    Strings must use doublequote                          quotes
  51:28  error    Strings must use doublequote                          quotes
  52:1   error    Expected indentation of 20 spaces but found 14        indent
  53:1   error    Expected indentation of 20 spaces but found 14        indent
  53:21  error    Expected parentheses around arrow function argument   arrow-parens
  54:1   error    Expected indentation of 22 spaces but found 16        indent
  54:40  error    Expected parentheses around arrow function argument   arrow-parens
  55:1   error    Expected indentation of 24 spaces but found 18        indent
  55:74  error    Missing semicolon                                     semi
  56:1   error    Expected indentation of 24 spaces but found 18        indent
  57:1   error    Expected indentation of 26 spaces but found 20        indent
  58:1   error    This line has a length of 81. Maximum allowed is 80   max-len
  58:1   error    Expected indentation of 28 spaces but found 22        indent
  59:1   error    Expected indentation of 28 spaces but found 22        indent
  60:1   error    Expected indentation of 28 spaces but found 22        indent
  60:30  error    Strings must use doublequote                          quotes
  61:1   error    Expected indentation of 28 spaces but found 22        indent
  61:30  error    Strings must use doublequote                          quotes
  61:39  error    Missing trailing comma                                comma-dangle
  62:1   error    Expected indentation of 26 spaces but found 20        indent
  62:22  error    Missing trailing comma                                comma-dangle
  63:1   error    Expected indentation of 24 spaces but found 18        indent
  63:20  error    Missing semicolon                                     semi
  64:1   error    Expected indentation of 24 spaces but found 18        indent
  65:1   error    Expected indentation of 24 spaces but found 18        indent
  66:1   error    Expected indentation of 28 spaces but found 20        indent
  67:1   error    Expected indentation of 28 spaces but found 20        indent
  68:1   error    Expected indentation of 28 spaces but found 20        indent
  68:27  error    Expected parentheses around arrow function argument   arrow-parens
  69:1   error    Expected indentation of 30 spaces but found 22        indent
  69:35  error    Strings must use doublequote                          quotes
  69:74  error    Missing semicolon                                     semi
  70:1   error    Expected indentation of 28 spaces but found 20        indent
  71:1   error    Expected indentation of 28 spaces but found 20        indent
  71:28  error    Expected parentheses around arrow function argument   arrow-parens
  72:1   error    Expected indentation of 30 spaces but found 22        indent
  72:35  error    Strings must use doublequote                          quotes
  72:67  error    Missing semicolon                                     semi
  73:1   error    Expected indentation of 28 spaces but found 20        indent
  73:23  error    Missing semicolon                                     semi
  74:1   error    Expected indentation of 22 spaces but found 16        indent
  74:19  error    Missing semicolon                                     semi
  75:1   error    Expected indentation of 20 spaces but found 14        indent
  75:17  error    Missing semicolon                                     semi
  76:1   error    Expected indentation of 14 spaces but found 10        indent
  77:1   error    Expected indentation of 16 spaces but found 12        indent
  77:25  error    Strings must use doublequote                          quotes
  77:62  error    Missing semicolon                                     semi
  78:1   error    Expected indentation of 14 spaces but found 10        indent
  79:1   error    Expected indentation of 12 spaces but found 8         indent
  79:11  error    Missing semicolon                                     semi
  80:1   error    Expected indentation of 10 spaces but found 6         indent
  80:9   error    Missing semicolon                                     semi
  81:1   error    Expected indentation of 6 spaces but found 4          indent
  81:16  error    Missing semicolon                                     semi
  82:1   error    Expected indentation of 4 spaces but found 2          indent

云函数:

exports.sendNotification = functions.firestore
  .document('/rooms/{roomId}/messages/{messageId}')
  .onCreate((snap, context) => {
    console.log('----------------start function--------------------')
    const doc = snap.data()
    console.log(doc)

    const senderId = doc.senderId
    const receiverId = doc.receiverId
    const contentMessage = doc.message

    // Get push token user to (receive)
    admin
      .firestore()
      .collection('users')
      .where('id', '==', receiverId)
      .get()
      .then(querySnapshot => {
        querySnapshot.forEach(userTo => {
          console.log(`Found receiver: ${userTo.data().name}`)
          if (userTo.data().token) {
            // Get info user from (sent)
            admin
              .firestore()
              .collection('users')
              .where('id', '==', senderId)
              .get()
              .then(querySnapshot2 => {
                querySnapshot2.forEach(userFrom => {
                  console.log(`Found user from: ${userFrom.data().name}`)
                  const payload = {
                    notification: {
                      title: `You have a message from "${userFrom.data().name}"`,
                      body: contentMessage,
                      badge: '1',
                      sound: 'default'
                    }
                  }
                  // Let push to the target device
                  admin
                    .messaging()
                    .sendToDevice(userTo.data().token, payload)
                    .then(response => {
                      console.log('Successfully sent message:', response)
                    })
                    .catch(error => {
                      console.log('Error sending message:', error)
                    })
                })
              })
          } else {
            console.log('Can not find pushToken target user')
          }
        })
      })
    return null
  });
sxpgvts3

sxpgvts31#

当您在Firebase初始化时启用ESLint时,会发生这种情况。

您可以直接运行ESLint,方法是进入主项目文件夹,然后在终端上执行以下命令:

cd functions && npx eslint . --fix

cd functions && node_modules/eslint/bin/eslint.js . --fix

以上命令将修复ESLint可以自动修复的问题。如果运行命令后未捕获到警告,则现在可以部署函数而不会出现问题。如果仍有警告,则必须在部署函数之前手动修复它。

注意:如果您不想使用ESLint,您可以重新创建项目,在系统提示时选择不使用ESLint。或者您可以通过编辑firebase.json文件并删除运行lint命令的**predeploy脚本,在当前项目中禁用ESLint。请参阅下面的firebase.json**示例:

{
  "functions": [
    {
      "source": "functions",
      "codebase": "default",
      "ignore": [
        "node_modules",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ],
      "predeploy": [
        "npm --prefix \"$RESOURCE_DIR\" run lint",
        "npm --prefix \"$RESOURCE_DIR\" run build"
      ]
    }
  ]
}

删除这些代码块:

"predeploy": [
    "npm --prefix \"$RESOURCE_DIR\" run lint",
    "npm --prefix \"$RESOURCE_DIR\" run build"
]

相关问题