我正在处理一个 Angular/TypeScript 组件包,同时使用该包在应用程序中进行开发。我使用 npm link 来设置共享组件。在构建时,tslint 似乎会为链接包发出一系列警告。
例如在我们的 tslint.json 中,我们有一个前缀“ta
”。在包中它是“fn
”。因为我们在 tsconfig 中排除了 node_modules,所以我们从来没有遇到过问题。但是一旦我们 npm 链接了包,它现在也会对我们包中的文件进行 linting。然后在构建时在控制台中触发一堆警告。
WARNING in ../fn-library/src/popover/popover.component.ts
[10, 15]: The selector of the component "PopoverComponent" should have prefix "ta"
关于抑制来自 npm 链接包的 tslint 警告有什么建议吗?
这是我当前在父项目中的 tsconfig.json 文件:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"noEmit": true,
"noEmitHelpers": true,
"strictNullChecks": false,
"importHelpers": true,
"baseUrl": "./src",
"paths": [],
"lib": [
"dom",
"es6"
],
"typeRoots": [
"node_modules/@types"
],
"types": [
"jasmine",
"node"
]
},
"exclude": [
"node_modules/**/*",
"dist/**/*"
],
"angularCompilerOptions": {
"skipMetadataEmit": true
},
"compileOnSave": false,
"buildOnSave": false
}
这是我的 tslint 文件:
{
"rulesDirectory": [
"node_modules/codelyzer"
],
"rules": {
"directive-selector": [
true,
"attribute",
"ta",
"camelCase"
],
"component-selector": [
true,
"element",
"ta",
"kebab-case"
],
"use-input-property-decorator": true,
"use-output-property-decorator": true,
"use-host-property-decorator": true,
"no-attribute-parameter-decorator": true,
"no-input-rename": true,
"no-output-rename": true,
"no-forward-ref": true,
"use-life-cycle-interface": true,
"use-pipe-transform-interface": true,
"pipe-naming": [
true,
"camelCase",
"ta"
],
"component-class-suffix": true,
"directive-class-suffix": true,
"import-destructuring-spacing": true
}
}
最佳答案
您可以使用内联注释来禁用该行上的 tslint
selector: 'component',// tslint:disable-line
要从 lint 中排除一组文件,请将以下行添加到 tsconfig 文件
"tslint.exclude": "**/folder/**/*.ts"
你的情况
"tslint.exclude": "**/fn-library/**/*.ts"
关于angular - 如何抑制来自 npm 链接包的 tslint 警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44336653/