【问题标题】:how to configure my eslintrc in cloud function typescript project?如何在云函数 typescript 项目中配置我的 eslintrc?
【发布时间】:2021-04-28 05:10:43
【问题描述】:

我正在尝试使用打字稿云功能并在其中使用 ESlint,但我只想将未使用的变量作为警告,而不是标记为错误。我很困惑如何在我的云功能项目中配置它,在我的.eslintrc 中总是出现这样的错误,请帮助

这是我的 .eslintrc 配置

module.exports = {
  root: true,
  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"],
    no-unused-vars: ["warn"] <---- this one
  },
};

【问题讨论】:

  • ["warn"]后面需要加逗号。这更像是一个风格错误而不是一个实际问题。参考comma-dangle规则。
  • 将no-unused-vars 括在引号中:"no-unused-vars"

标签: typescript firebase google-cloud-functions eslint eslintrc


【解决方案1】:

您需要将no-unused-vars 括在引号中,因为它的属性名称中包含-。

破折号在 javascript 变量中是不合法的。变量名必须以字母、美元符号或下划线开头,后面可以跟相同的名称或数字。您可以在字符串中使用破折号。

"no-unused-vars": ["warn"],

【讨论】:

    猜你喜欢
    • 2019-12-21
    • 2020-11-16
    • 2021-01-15
    • 2019-10-13
    • 2021-01-10
    • 2020-12-08
    • 1970-01-01
    • 2023-01-04
    • 2019-12-13
    相关资源
    最近更新 更多