Skip to content
Advertisement

how to fix unexpected token parsing error?

The arrow works for me all time but i get an error now Parsing error: Unexpected token => I tried checking the syntax and bracket and yeah, I dint miss any brackets.

Code :

const functions = require("firebase-functions");

const Filter = require("bad-words");

const admin = require("firebase-admin");
admin.initializeApp();

const db = admin.firestore();

exports.detectEvilUsers = functions.firestore
  .document("messages/{msgId}")
  .onCreate(async (doc, ctx) => {
    const filter = new Filter();
    const { text, uid } = doc.data();

    if (filter.isProfane(text)) {
      const cleaned = filter.clean(text);
      await doc.ref.update({
        text: "I got banned for lifetime for using voilated words",
      });

      await db.collection("banned").doc(uid).set({});
    }
  });

Error :

Parsing error: Unexpected token =>

And If try to change it to normal function(){} call, like this

exports.detectEvilUsers = functions.firestore
  .document("messages/{msgId}")
  .onCreate(async function(doc, ctx)  {
        const filter = new Filter();
        const { text, uid } = doc.data();
    ....
    ....
    ....
    }

It gives me Parsing error:unexpected token function

Advertisement

Answer

Eslin.json file: { "parser": "babel-eslint", "plugins": [ "babel" ], "extends": [ "plugin:prettier/recommended", "plugin:react/recommended" ], "env": { "browser": true, "es6": true, "jest": true }, "parserOptions": { "ecmaVersion": 2018, "sourceType": "module", "ecmaFeatures": { "jsx": true } }, "rules": { "curly": "error", "eqeqeq": "error", "guard-for-in": "error", "no-extend-native": "error", "complexity": [ "error", 200 ], "max-depth": [ "error", 5 ], "max-params": [ "error", 12 ], "max-statements": [ "error", 200 ], "no-caller": "error", "no-irregular-whitespace": "error", "no-new": "error", "no-undef": "error", "no-unused-vars": "error", "no-global-assign": "error", "react/prop-types": "off", "babel/semi": 1 } }

Advertisement