Firebase Cloud Functions ESLint 最近有变化吗?

Did Firebase Cloud Functions ESLint change recently?

我几个月前用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 文件中单独设置这些规则,但这很烦人,我不想那样做。默认情况下,为什么不禁用这些规则?我只想要确保我的代码在 运行 时不会失败的基本规则,而不是像 single/double 引号和最大行长度这样的随机样式首选项。

有什么方法可以只使用基本的 linting 功能和 firebase 函数吗?

我运行遇到了和你一样的问题。新的、更严格的 linting 规则似乎来自于 Firebase 函数现在默认使用“google”eslint 基础配置插件这一事实。阅读更多关于配置 ESLint 插件的信息 in the docs。我的旧 Firebase 函数使用 tslint 没有问题。

这是我的 .eslintrc.js 文件在我从 eslint 收到样式错误时的样子:

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'],
    },
};

我从扩展 属性 中删除了 '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'],
    },
};

您可以去掉 google extends 值,但我建议保留它并关闭最困扰您的规则,对我来说是缩进和最大长度(行数):

module.exports = {
  root: true,
  env: {
    es6: true,
    node: true,
  },
  extends: [
    "eslint:recommended",
    "google",
  ],
  rules: {
    "quotes": ["error", "double"],
    "indent": ["off"],
    "max-len": ["off"],
  },
};

对于任何对此感到困惑的人,您可以编辑 Cloud Functions 文件夹中的 lint 配置文件。截至此答案,该文件名为 .eslintrc.js.