Оператор распространения облачных функций Firebase не проходит проверку eslint и загрузка не удалась

Может ли кто-нибудь выяснить, как мне решить ошибку linter. Этот код протестирован и отлично работает. Единственное, я не могу развернуть его в инфраструктуре облачных функций.

Я уверен, что что-то не так с файлом .eslintrc. Может ли кто-нибудь помочь мне в том, как я могу использовать оператора спреда.

Вот тут линтер выдает ошибку:

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

Это мой файл .eslintrc:

{
"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
}}

person Gaurav Harchwani    schedule 23.08.2018    source источник
comment
Было бы полезно, если бы вы добавили фактическое сообщение об ошибке в свой вопрос.   -  person Doug Stevenson    schedule 23.08.2018


Ответы (3)


Для потомков, так как у этого есть 500 просмотров и нет решения: это сработало для меня -

В .eslintrc.json изменить

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

to

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

затем попробуйте перераспределить

#worksonmymachine

person Caleb O'Leary    schedule 11.08.2019
comment
"ecmaVersion": 2019 у меня тоже сработало, спасибо - person Ivan Chernykh; 25.08.2019
comment
Мне достаточно только "ecmaVersion": 2019 :D - person Hoang Trinh; 07.09.2019
comment
Работает как шарм! - person Minoru; 26.10.2020

ESLint поддерживает паузу/расширение объектов, но вы должны включить это через конфигурацию. Вы можете установить для ecmaVersion значение 2018 (в parserOptions) или установить для ecmaFeatures.experimentalObjectRestSpread значение true (также в parserOptions обратите внимание на необходимость создания объекта ecmaFeatures).

Вам нужно было добавить env.eslint вот так:

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

Для получения дополнительной информации прочитайте эту статью: https://codeburst.io/es6-in-cloud-functions-for-firebase-959b35e31cb0 Надеюсь, это поможет.

person ParthS007    schedule 23.08.2018
comment
Я уже добавил ecmaVersion в 2018 и ExperimentObjectRestSpread в true. Пожалуйста, проверьте файл. Все еще не работает. Я работаю с проектом облачных функций Firebase. Когда я добавляю это, ошибка исчезает, но во время развертывания она показывает ошибку. - person Gaurav Harchwani; 23.08.2018
comment
@GauravHarchwani, я добавил ссылку на блог, пожалуйста, проверьте ее :) - person ParthS007; 23.08.2018

Я была такая же проблема. Обновление узла до версии 8+ должно исправить это.

person Community    schedule 01.04.2019