angular - 如何抑制来自 npm 链接包的 tslint 警告?

标签 angular typescript npm tslint

我正在处理一个 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/

相关文章:

node.js - Docker 构建 npm 错误日志

git - 我应该提交在 npm 包中发布的自动生成的文件吗

npm - 可以使用 pnpm 仅使用一个软件包版本吗?

angular - 如何解决循环依赖

html - 动态更改 Angular 5 中 Bootstrap 进度条的属性

node.js - 当存在index.d.ts时,TypeScript不会导入index.js

javascript - typescript 无法推断自定义 Hook 中的解构数组类型

javascript - 从 JavaScript 模型中的现有属性返回未定义

angular - 是否可以在 Angular 中同时将输入绑定(bind)到两个变量?

javascript - 我如何在 if 条件下使用 Angular focusout