![](/img/trans.png)
[英]Enable TSlint ordered-imports rule with module-source-path
[英]Tslint always enforcing no-submodule-imports rule even if disabled
我正在嘗試將tslint配置為允許Parse
庫( https://www.npmjs.com/package/parse-js )中的子模塊,以便可以使用parse/react-native
,但是它不起作用。
我嘗試添加"no-submodule-imports": [true, "parse", "parse/react-native"]
和"no-submodule-imports": false
在我的tslint中為"no-submodule-imports": false
,但仍然出現以下錯誤:
ERROR: src/App.tsx:2:19 - Submodule import paths from this package are disallowed; import from the root instead
在node_modules中此子模塊的@types/parse
中的聲明為:
declare module "parse/node" {
export = Parse;
}
declare module "parse" {
import * as parse from "parse/node";
export = parse
}
declare module "parse/react-native" {
import * as parse from "parse/node";
export = parse
}
該代碼可以正常工作,但是如果我運行tslint,則會收到該錯誤。 我嘗試了它的不同組合,仍然有問題。
這是我的tslint.json的樣子:
{
"extends": [
"tslint:latest",
"tslint-react",
"tslint-react-a11y",
"tslint-config-prettier"
],
"no-submodule-imports": [true, "parse", "parse/react-native"],
"import-blacklist": false,
"defaultSeverity": "error",
"rules": {
"ban": {
"options": [
["_", "extend", "use object spread: { ...a, ...b }"],
["_", "isNull", "use plain JS: == null"],
["_", "isDefined", "use plain JS: != null"],
["Object", "assign", "use object spread: { ...a, ...b }"],
["Object", "getOwnPropertyNames", "use Object.keys()"],
["describe", "only", "should not be committed to repo"],
["it", "only", "should not be committed to repo"],
["test", "only", "should not be committed to repo"]
]
},
"no-object-literal-type-assertion": false,
"ordered-imports": [
true,
{
"import-sources-order": "any",
"named-imports-order": "any"
}
],
"no-any": true,
"interface-over-type-literal": false,
"linebreak-style": {
"options": ["LF"]
},
"quotemark": [true, "single"],
"jsx-boolean-value": ["never"],
"member-access": [true],
"no-console": false,
"no-implicit-dependencies": false,
"no-invalid-this": {
"options": ["check-function-in-method"]
},
"interface-name": false,
"max-classes-per-file": false,
"jsx-no-lambda": false,
"no-trailing-whitespace": true,
"no-this-assignment": [
true,
{
"allow-destructuring": true
}
],
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-initializer": true,
"object-literal-sort-keys": false,
"prefer-conditional-expression": false,
"variable-name": {
"options": [
"allow-leading-underscore",
"allow-pascal-case",
"ban-keywords",
"check-format"
]
},
"member-ordering": [
true,
"private-before-public",
"static-before-instance",
"variables-before-functions"
],
"trailing-comma": [
true,
{
"multiline": "always",
"singleline": "never",
"esSpecCompliant": true
}
]
},
"jsRules": {
"object-literal-sort-keys": false
},
"linterOptions": {
"exclude": [
"/**/packages/newrelic-webpack-plugin/embedded.js",
"/**/coverage/**/*",
"/**/*.json",
"/**/build/**/*"
]
}
}
先謝謝您的幫助。
我也遇到了這個。 看起來對於有角度的項目,規則必須位於src文件夾內的tslint文件中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.