Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase cloud functions spread operator fails eslint check and upload fails

Can anyone please figure out how do i solve the linter error. This code is tested and works perfectly. Only thing is i am unable to deploy it on cloud functions infrastructure.

I am sure somethings wrong with .eslintrc file. Can anyone please help me out on how i can use the spread operator.

This is where linter throws the error:

const rightChoices = _.map(snapshot.val(), (val, questionId) => {
  return { ...val, questionId};
})

This is my .eslintrc file:

{
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
  "jsx": true,
  "experimentalObjectRestSpread": true
}
}
"plugins":[
"promise"
],
"extends": "eslint:recommended",
"rules": {
// Removed rule "disallow the use of console" from recommended eslint rules
"no-console": "off",

// Removed rule "disallow multiple spaces in regular expressions" from recommended eslint rules
"no-regex-spaces": "off",

// Removed rule "disallow the use of debugger" from recommended eslint rules
"no-debugger": "off",

// Removed rule "disallow unused variables" from recommended eslint rules
"no-unused-vars": "off",

// Removed rule "disallow mixed spaces and tabs for indentation" from recommended eslint rules
"no-mixed-spaces-and-tabs": "off",

// Removed rule "disallow the use of undeclared variables unless mentioned in /*global */ comments" from recommended eslint rules
"no-undef": "off",

// Warn against template literal placeholder syntax in regular strings
"no-template-curly-in-string": 1,

// Warn if return statements do not either always or never specify values
"consistent-return": 1,

// Warn if no return statements in callbacks of array methods
"array-callback-return": 1,

// Require the use of === and !==
"eqeqeq": 2,

// Disallow the use of alert, confirm, and prompt
"no-alert": 2,

// Disallow the use of arguments.caller or arguments.callee
"no-caller": 2,

// Disallow null comparisons without type-checking operators
"no-eq-null": 2,

// Disallow the use of eval()
"no-eval": 2,

// Warn against extending native types
"no-extend-native": 1,

// Warn against unnecessary calls to .bind()
"no-extra-bind": 1,

// Warn against unnecessary labels
"no-extra-label": 1,

// Disallow leading or trailing decimal points in numeric literals
"no-floating-decimal": 2,

// Warn against shorthand type conversions
"no-implicit-coercion": 1,

// Warn against function declarations and expressions inside loop statements
"no-loop-func": 1,

// Disallow new operators with the Function object
"no-new-func": 2,

// Warn against new operators with the String, Number, and Boolean objects
"no-new-wrappers": 1,

// Disallow throwing literals as exceptions
"no-throw-literal": 2,

// Require using Error objects as Promise rejection reasons
"prefer-promise-reject-errors": 2,

// Enforce “for” loop update clause moving the counter in the right direction
"for-direction": 2,

// Enforce return statements in getters
"getter-return": 2,

// Disallow await inside of loops
"no-await-in-loop": 2,

// Disallow comparing against -0
"no-compare-neg-zero": 2,

// Warn against catch clause parameters from shadowing variables in the outer scope
"no-catch-shadow": 1,

// Disallow identifiers from shadowing restricted names
"no-shadow-restricted-names": 2,

// Enforce return statements in callbacks of array methods
"callback-return": 2,

// Require error handling in callbacks
"handle-callback-err": 2,

// Warn against string concatenation with __dirname and __filename
"no-path-concat": 1,

// Prefer using arrow functions for callbacks
"prefer-arrow-callback": 1,

// Return inside each then() to create readable and reusable Promise chains.
// Forces developers to return console logs and http calls in promises.
"promise/always-return": 2,

//Enforces the use of catch() on un-returned promises
"promise/catch-or-return": 2,

// Warn against nested then() or catch() statements
"promise/no-nesting": 1
}}
like image 352
Gaurav Harchwani Avatar asked Aug 23 '18 06:08

Gaurav Harchwani


People also ask

Are deploys to runtimes now disabled in the firebase CLI?

Deploys to runtimes below Node.js 10 are now disabled in the Firebase CLI. Existing Node.js 8 functions will stop executing on 2021-03-15.

Why are my App Engine files public on Firebase?

Since Firebase and your project's default App Engine app share this bucket, configuring public access may make newly uploaded App Engine files publicly accessible, as well. Be sure to restrict access to your Cloud Storage bucket again when you set up Authentication.

How can Firebase help you accelerate app development?

Tune in to learn how Firebase can help you accelerate app development, release with confidence, and scale with ease. Register Cloud Storage for Firebase allows you to quickly and easily upload files to a Cloud Storage bucket provided and managed by Firebase.

What are the different versions of Firebase-tools?

firebase-functions: 3.6.1 (Issue is present irrespective of version) firebase-tools: 8.12.1 (Issue is present irrespective of version) firebase-admin: 9.2.0 (Issue is present irrespective of version) I've been trying to deploy my existing project with just a few EJS changes.


Video Answer


2 Answers

For posterity, since this has 500 views and no solution: This worked for me -

In .eslintrc.json change

"parserOptions": {
   // Required for certain syntax usages
   "ecmaVersion": 2017,
   "sourceType": "module"
 },

to

"parserOptions": {
   // Required for certain syntax usages
   "ecmaVersion": 2019,
   "sourceType": "module"
 },

then try to redeploy

#worksonmymachine

like image 154
Caleb O'Leary Avatar answered Nov 11 '22 14:11

Caleb O'Leary


ESLint does support object rest/spread, but you have to opt-in via configuration. You can either set your ecmaVersion to 2018 (in parserOptions), or set ecmaFeatures.experimentalObjectRestSpread to true (also in parserOptions, note the need to create an ecmaFeatures object).

You had to add env.eslint like so:

{
  "env": {
    "es6": true
  },
  "extends": [
    "eslint:recommended",
    "google"
  ],
  "parserOptions": {
    "ecmaVersion": 9,
    "sourceType": "module"
  }
}

For more info, read this article: https://codeburst.io/es6-in-cloud-functions-for-firebase-959b35e31cb0 I hope this helps.

like image 37
ParthS007 Avatar answered Nov 11 '22 14:11

ParthS007