Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you suppress tslint warnings from npm linked packages?

I'm working on a package of Angular/TypeScript components while developing in the app using that package. I've used npm link to set up the shared components. On build, it would seem that tslint kicks off a bunch of warnings for the linked package.

For example in our tslint.json, we have a prefix of "ta". In the package it's "fn". Because we're excluding node_modules in our tsconfig, we never had a problem. But once we npm linked the package, it's now linting the files in our package as well. Which then triggers a bunch of warnings in the console on build.

WARNING in ../fn-library/src/popover/popover.component.ts
[10, 15]: The selector of the component "PopoverComponent" should have prefix "ta"

Any suggestions on suppressing tslint warnings from npm linked packages?

Here is my current tsconfig.json file in the parent project:

{
    "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
}

Here is my tslint file:

{
    "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
    }
}
like image 837
Steve Schrab Avatar asked Jun 02 '17 20:06

Steve Schrab


People also ask

How do I turn off TSLint errors?

Place the cursor at an error or a warning reported by TSLint and press Alt+Enter . Select the quick-fix for the rule that you want to disable and press Right .

How do I disable TSLint to a file?

In addition to global configuration, you may also enable/disable linting for a subset of lint rules within a file with the following comment rule flags: /* tslint:disable */ - Disable all rules for the rest of the file. /* tslint:enable */ - Enable all rules for the rest of the file.

What is TSLint?

TSLint is an extensible static analysis tool that checks TypeScript code for readability, maintainability, and functionality errors. It is widely supported across modern editors & build systems and can be customized with your own lint rules, configurations, and formatters.


1 Answers

You can use a inline comment to disable the tslint on that line by

selector: 'component',// tslint:disable-line

To exclude a set of files from being linted, add the below line to the tsconfig file

"tslint.exclude": "**/folder/**/*.ts"

In your case

"tslint.exclude": "**/fn-library/**/*.ts"
like image 110
Aravind Avatar answered Sep 18 '22 23:09

Aravind