在 Deno 中使用 linters/linting 工具

wen*_*jun 5 javascript typescript deno deno-lint

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

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

parser: '@typescript-eslint/parser',
extends: [
  'eslint:recommended',
  'plugin:@typescript-eslint/eslint-recommended',
  'plugin:@typescript-eslint/recommended',
],
Run Code Online (Sandbox Code Playgroud)

话虽如此,在 Deno/TypeScript 项目中设置 linting 和格式化的一些实践/方法是什么?

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

Mar*_*nde 5

这是Deno 使用eslint配置,并且非常适合使用.std/Deno

{
  "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"]
      }
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)


cvn*_*vng 3

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

检查源文件是否格式化

deno fmt --check
Run Code Online (Sandbox Code Playgroud)

自动格式化 JavaScript/TypeScript 源代码

deno fmt
Run Code Online (Sandbox Code Playgroud)

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