[英]ESLint - Only Allow Relative Import Paths Not Absolute
在與問題ESLint - Only Allow Absolute Import Paths Not Relative類似的注釋上
eslint 如何在絕對導入上出錯? 對 TypeScript 的上下文特別感興趣。
您可以嘗試使用規則@typescript-eslint/no-restricted-imports
來禁止絕對導入(任何不以./
或../
開頭的東西)。
{
rules: {
"no-restricted-imports": "off",
"@typescript-eslint/no-restricted-imports": [
"error",
{
"patterns": ["!./*", "!../*"]
}
]
}
}
@typescript-eslint/no-restricted-imports
擴展eslint/no-restricted-imports
。
我們之所以禁用eslint/no-restricted-imports
是因為它可以報告不正確的錯誤。
更多信息在這里。
在 IDE 中設置“僅相對路徑”並從tsconfig.json
中刪除baseUrl
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.