Ignoring a block of code while linting your typescript code — TSLINT

If you have been working with typescript oriented frameworks like Angular, you must be linting your code before submitting it. And if by any chance you are working in Angular and not linting your code, I just have 1 thing to say to you:

How dare you?

For the ones for whom “linting” comes as an alien term, let me explain it in a very simple way — linting helps you avoid make noob mistakes while adhering to industry standards of coding. From removing dead code to helping you declare your variables as const rather than let because the variable isn’t getting assigned any new value — its helps you do it all!

Hence, if you aren’t linting, please do.

Coming back to the topic…

So, recently I came across a use case wherein I wanted my tslint to ignore a particular block of code (a function to be precise) in a typescript file but lint the rest of the code. This was because I was working with:

It’s harder to read code than to write it.

After digging around and a few hit and trials, I got to the official docs of tslint and I wasn’t surprised it was such an easy thing. All you had to do is disable the tslint before the function starts and enable the tslint again just after the function ends.

And that’s it. If you are in Angular and run ng lint then the tslint will run through the entire codebase, ignoring this particular function.

If you use this anywhere, do share it with your colleagues and friends in your dev circle. Have questions, queries or feedback, please let me know in the comments below!

Originally published at adityatyagi.com

--

--

--

Programmer and a voracious reader who writes about web development | adityatyagi.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

From react-redux to @reduxjs/toolkit

How to Monitor Express GraphQL Apps in New Relic

Article pattern check system.

To describe the real world, use maps

Gatsby 1.x — In The Reading Of The Code Examples

Thank thunk

JavaScript30 — Day 13

How to build a collaborative drawing app with React.JS and Socket.io, and Node.js

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aditya Tyagi

Aditya Tyagi

Programmer and a voracious reader who writes about web development | adityatyagi.com

More from Medium

How to Get Started With TypeScript

How to Get Started With TypeScript

Conditionally Creating Array Literals

How global TypeScript utilities work under the hood — Required<Type>

Convenient Tactics of Logging in NodeJS and JavaScript in the Browser