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

你找到你需要的内容了吗?

隐私政策