首页 > 解决方案 > Firebase Cloud Functions ESLint 最近是否发生了变化?

问题描述

几个月前我用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

它也不让我使用异步/等待。

我发现我可以在我的 .eslintrc.js 文件中单独设置这些规则,但这很烦人,我不想这样做。默认情况下,为什么不禁用这些规则?我只想要确保我的代码在运行时不会失败的基本规则,而不是像单引号/双引号和最大行长这样的随机样式偏好。

有什么方法可以将基本的 linting 功能与 firebase 功能一起使用?

标签: firebasegoogle-cloud-functionseslint

解决方案


我遇到了和你一样的问题。新的、更严格的 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'],
    },
};

推荐阅读