【问题标题】:Usage of linters/linting tools within Deno在 Deno 中使用 linter/linting 工具
【发布时间】:2020-09-13 22:40:54
【问题描述】:

我目前正在探索 Deno 作为概念验证,并且我正在尝试找到合适的方法来在项目中设置 linting。

这是我正在考虑设置的 eslint 配置的一部分,但我知道由于 Node.JS 和 Deno 之间的差异,这可能会导致更多问题:

parser: '@typescript-eslint/parser',
extends: [
  'eslint:recommended',
  'plugin:@typescript-eslint/eslint-recommended',
  'plugin:@typescript-eslint/recommended',
],

话虽如此,在 Deno/TypeScript 项目中设置 linting 和格式化有哪些实践/方法?

我知道deno lint 仍在进行中,缺乏文档阻碍了我目前采用它。

【问题讨论】:

    标签: javascript typescript deno deno-lint


    【解决方案1】:

    这是eslint 配置Deno uses,非常适合使用Denostd/

    {
      "root": true,
      "parser": "@typescript-eslint/parser",
      "parserOptions": {
        "createDefaultProgram": true
      },
      "plugins": ["@typescript-eslint"],
      "extends": [
        "plugin:@typescript-eslint/recommended",
        "prettier",
        "prettier/@typescript-eslint"
      ],
      "rules": {
        "@typescript-eslint/array-type": ["error", { "default": "array-simple" }],
        "@typescript-eslint/ban-ts-comment": ["off"],
        "@typescript-eslint/explicit-member-accessibility": ["off"],
        "@typescript-eslint/explicit-module-boundary-types": ["off"],
        "@typescript-eslint/no-non-null-assertion": ["off"],
        "@typescript-eslint/no-use-before-define": ["off"],
        "@typescript-eslint/no-parameter-properties": ["off"],
        "@typescript-eslint/no-unused-vars": [
          "error",
          { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }
        ],
        "@typescript-eslint/ban-ts-ignore": ["off"],
        "@typescript-eslint/no-empty-function": ["off"],
        "no-return-await": "error",
        "require-await": "error",
        "no-async-promise-executor": "error"
      },
      "overrides": [
        {
          "files": ["*.js"],
          "rules": {
            "@typescript-eslint/explicit-function-return-type": ["off"]
          }
        },
        {
          "files": ["tools/node_*.js"],
          "rules": {
            "@typescript-eslint/no-var-requires": ["off"]
          }
        }
      ]
    }
    

    【讨论】:

    • 嘿!感谢您的回答。是的,我一直在尝试类似你一直在做的事情,看来我们将不得不这样做,直到他们发布了 linter 的 v1!
    • 但它似乎不起作用。我已经在我的 Deno 项目的根目录中放置了一个 .eslintrc 文件,其中包含此答案的确切内容,并添加了更多规则进行测试,例如 "indent": ["error", 4]"@typescript-eslint/quotes": ["error", "single"] 以及当我完全运行 deno lint 时似乎忽略了那个 .eslintrc 文件。另外,我不知道如何告诉deno fmt 使用 eslint 规则。在我的常规前端项目中,我有 "eslint --format **/*.ts 使用 eslint 格式化 ts 文件,但不确定如何在没有 Node/npm 和 npm 脚本的 Deno 项目中执行此操作
    【解决方案2】:

    您现在可以使用deno lint 来检测代码:https://deno.land/manual/tools/linter

    【讨论】:

      【解决方案3】:

      您可以通过运行以下命令来格式化您的 Deno 项目文件:

      检查源文件是否格式化

      deno fmt --check
      

      自动格式化 JavaScript/TypeScript 源代码

      deno fmt
      

      我认为这是我们目前最好的选择,因为deno_lint 还没有准备好。

      【讨论】:

      • 您好,谢谢您的回答!是的我同意。我想我们将不得不使用现有的 eslint 规则,使用 deno fmt 命令来格式化代码。希望他们能尽快释放 linter..
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-08
      • 1970-01-01
      • 1970-01-01
      • 2020-07-16
      • 1970-01-01
      相关资源
      最近更新 更多