简体   繁体   English

TSLint 对非字母化的导入源不满意

[英]TSLint unhappy with non-alphabetized import sources

I have a couple of TypeScript import sources that TSLint is unhappy about, because they are apparently not alphabetized.我有几个 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';

The error message from TSLint:来自 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.

My package.json script command:我的 package.json 脚本命令:

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

Even though TSLint is unhappy about Global and remote , everything is ok with alphabetization.尽管 TSLint 对Globalremote不满意,但按字母顺序排列一切都很好。 I believe TSLint must be unhappy about the capitalization or something similar.我相信 TSLint 一定对大写或类似的事情不满意。 Is there anyway to check how TSLint is alphabetizing?无论如何要检查 TSLint 如何按字母顺序排列?

You could run tslint with --fix to sort the imports:您可以使用--fix运行 tslint 对--fix进行排序:

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

And if you use VS Code, there's a tslint extension that allows you to apply individual fixes.如果您使用 VS Code,还有一个 tslint 扩展允许您应用单独的修复。

Assuming you use the default settings for the ordered-imports rule, your imports should be okay when sorted like this: (absolute before relative)假设您使用了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';

For more importation you can check the documentation of the rule at https://palantir.github.io/tslint/rules/ordered-imports/ :如需更多导入,您可以在https://palantir.github.io/tslint/rules/ordered-imports/查看规则文档:

If no "groups" options is set, a default grouping is used of third-party, parent directories and the current directory.如果未设置“组”选项,则使用第三方、父目录和当前目录的默认分组。 ("bar", "../baz", "./foo".) (“bar”、“../baz”、“./foo”。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM