简体   繁体   中英

Angular 4 : How to disable lint warning to emit when running npm build command?

I am working on an Angular 4 app which is being implemented using webpack (not a CLI project). When I run npm start or npm run build, the webpack dev-server throws a lot of lint warnings like:

190, 13]: Identifier 'payload' is
228, 17]: Identifier 'payload' is
1, 34]: ' should be "
2, 42]: ' should be "
4, 28]: ' should be "
5, 37]: ' should be "
6, 33]: ' should be "
10, 16]: ' should be "
11, 23]: ' should be "
66, 23]: ' should be "
72, 23]: ' should be "
78, 23]: ' should be "
84, 23]: ' should be "
90, 23]: ' should be "
96, 23]: ' should be " 

Is there a way we can disable all the warnings in the console? It should only show the errors if any

You can't disable "all warnings", because the linting rules don't have a severity as such - you can set / change rule severities in your linter configuration file (eg tslint.json ).

You can however disable individual TSLint rules that throw individual warnings. Specifically for ' should be " in tslint.json look for the rule quotemark . In your case it should say something like this:

    "quotemark": [
        true, "single"
    ],

Simply delete that line to rid of the warning.

https://palantir.github.io/tslint/rules/quotemark/

Instead of disabling the rule, a better approach would be to update the rule to what you actually need, ie in case of quotemark you may want to consider to changing it to "double". Otherwise you loose the benefit of having a linter. However if you do that, you will get the opposite warning if you have single quotes in the code.

For any other warnings, similarly find the corresponding rule and remove/update it. It takes some effort, but the end result is a rule set that works for your project/team.

Another approach would be to go the other way and trim tslint.json to basics, and gradually add the rules you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM