簡體   English   中英

TSLint 對非字母化的導入源不滿意

[英]TSLint unhappy with non-alphabetized import sources

我有幾個 TSLint 不滿意的 TypeScript 導入源,因為它們顯然不是按字母順序排列的。

import { DialogNoConfigurationFile } from './view/dialogs/dialog-no-configuration-file';
import { DisplayMain } from './view/display/display-main';
import { Global } from './business/global';
import { remote } from 'electron';
import { RequestResponse } from './data/model/request-response';
import { UserRequestResponse } from './data/model/user-request-response';

來自 TSLint 的錯誤消息:

ERROR: /home/myuser/Documents/myproject/administration2/src/app.tsx:11:1 - Import sources within a group must be alphabetized.
ERROR: /home/myuser/Documents/myproject/administration2/src/app.tsx:12:1 - Import sources within a group must be alphabetized.

我的 package.json 腳本命令:

"lint": "tslint --project tsconfig.json --force"

盡管 TSLint 對Globalremote不滿意,但按字母順序排列一切都很好。 我相信 TSLint 一定對大寫或類似的事情不滿意。 無論如何要檢查 TSLint 如何按字母順序排列?

您可以使用--fix運行 tslint 對--fix進行排序:

npx tslint --fix --project tsconfig.json src/app.tsx

如果您使用 VS Code,還有一個 tslint 擴展允許您應用單獨的修復。

假設您使用了ordered-imports規則的默認設置,那么按如下方式排序時您的導入應該沒問題:(絕對在相對之前)

import { remote } from 'electron';
import { Global } from './business/global';
import { RequestResponse } from './data/model/request-response';
import { UserRequestResponse } from './data/model/user-request-response';
import { DialogNoConfigurationFile } from './view/dialogs/dialog-no-configuration-file';
import { DisplayMain } from './view/display/display-main';

如需更多導入,您可以在https://palantir.github.io/tslint/rules/ordered-imports/查看規則文檔:

如果未設置“組”選項,則使用第三方、父目錄和當前目錄的默認分組。 (“bar”、“../baz”、“./foo”。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM