FirebaseCloudFunctionsESLint最近有变化吗?
几个月前我用 firebase 创建了一个云函数项目,并使用了 linting。
我最近使用 linting 创建了一个新的云函数项目,现在 linter 抱怨我从未设置过的随机规则。我不记得它在几个月前执行了几乎大量的样式规则。
像:
This line has a length of 95. Maximum allowed is 80
Missing JSDoc comment
Missing Trailing comma
expected indentation of 2 spaces but found 4
Strings must use singlequote
它也不让我使用 async/await。
我发现我可以在我的 .eslintrc.js 文件中单独设置这些规则,但这很烦人,我不想这样做。默认情况下,为什么不禁用这些规则?我只想要确保我的代码在运行时不会失败的基本规则,而不是像单/双引号和最大行长度这样的随机样式首选项。
有什么方法可以将基本的 linting 功能与 firebase 功能一起使用吗?
回答
我遇到了和你一样的问题。新的、更严格的 linting 规则似乎来自 Firebase 函数现在默认使用“google”eslint 基础配置插件的事实。在文档中阅读有关配置 ESLint 插件的更多信息。我的旧 Firebase 函数使用 tslint 没有问题。
这是我从 eslint 收到样式错误时我的 .eslintrc.js 文件的样子:
module.exports = {
env: {
es6: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'google',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['tsconfig.json', 'tsconfig.dev.json'],
sourceType: 'module',
},
ignorePatterns: [
'/lib/**/*', // Ignore built files.
],
plugins: ['@typescript-eslint', 'import'],
rules: {
quotes: ['error', 'double'],
},
};
我从 extends 属性中删除了 'google',这似乎解决了几乎所有的样式 linting 问题。
现在它看起来像这样:
module.exports = {
env: {
es6: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['tsconfig.json', 'tsconfig.dev.json'],
sourceType: 'module',
},
ignorePatterns: [
'/lib/**/*', // Ignore built files.
],
plugins: ['@typescript-eslint', 'import'],
rules: {
quotes: ['error', 'double'],
},
};
- I also had to get rid of the rules object. I'm very confused as to why (as in why Google is doing it) on one hand you can turn on tslint enforcement which will give linting errors if using double quotes, but then this new default gives errors if using single quotes....