deno.com

禁止外部导入

禁止使用外部导入。

  • 此 Lint 规则的动机是什么?
    • 如果外部模块通过 URL 导入,此规则会发出警告。"deps.ts" 和导入映射是例外。
  • 为什么被 Lint 的代码被认为是糟糕的?
    • 导入外部模块本身没有问题,但如果这些模块在项目中的多个位置被导入,那么当你想要升级它们时,将需要花费时间和精力。
  • 何时使用?
    • 为避免此问题,你可以使用 "deps.ts 约定" 或 导入映射,你可以在其中导入所有外部模块,然后重新导出它们或为其分配别名。
    • 如果你想遵循 "deps.ts 约定" 或使用导入映射。

无效示例

import { assertEquals } from "https://deno.land/std@0.126.0/testing/asserts.ts";

有效示例

import { assertEquals } from "./deps.ts";
// deps.ts

export {
  assert,
  assertEquals,
  assertStringIncludes,
} from "https://deno.land/std@0.126.0/testing/asserts.ts";

你可以在此处查阅此约定的解释:https://docs.deno.org.cn/runtime/manual/basics/modules/#it-seems-unwieldy-to-import-urls-everywhere

您找到所需内容了吗?

隐私政策