How can you suppress tslint warnings from npm linked packages?
Asked Answered
I

1

7

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
    }
}
Ikhnaton answered 2/6, 2017 at 20:5 Comment(8)
place the block inside /* tslint:disable */Doublecross
I would suggest what @Doublecross is suggesting, but your parent project tslint should not be linting files in node_modules I'm curious how do you lint the parent project? can you post the config file as well as how you trigger it?Pelligrini
@Doublecross The problem is I want linting to take place within the separate project seperately. Like I said, this worked fine when the package was install via npm. But it starts kicking out errors when the package in npm linked.Ikhnaton
@AhmedMusallam I added the tsconfig to the question.Ikhnaton
@SteveSchrab what version of tslint do you use? and how do you run it? do you use the tslint-cli? do you use a different utility?Pelligrini
@SteveSchrab Did you ever figure out why the linked modules were getting linted?Rezzani
@Rezzani I haven't yet.Ikhnaton
I think the answer to this is your not really supposed to ship TypeScript files in NPM packages. Can't find a source though.Ikhnaton
D
8

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"
Doublecross answered 2/6, 2017 at 20:13 Comment(8)
I would think "exclude": [ "node_modules/**/*", "dist/**/*" ], would cover the fn-library which is npm linked inside node_modules.Ikhnaton
"tslint.exclude" is an option of vscode-tslint and not the tslint cli.Pelligrini
where you are having the fn-library folder?Doublecross
It's symlinked via npm link into the node_modules folder. Which I suspect is the problem. It's not actually in the node_modules folder and tslint is looking at it from it's actual location.Ikhnaton
how you are using that project as a library or as a module?Doublecross
It's a library of Angular components that the app is using. Both are being developed at the same time, hence using npm link while developing both locally.Ikhnaton
In that case you should explicitly set that folder path in exclude.Doublecross
Is there a way I can disable the warning for the entirety of my project inside the tslint.json file?Laze

© 2022 - 2024 — McMap. All rights reserved.