DEV Community

Aditya Tyagi
Aditya Tyagi

Posted on • Originally published at adityatyagi.com

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.

/* tslint:disable */
sampleFunctionToIgnoreDuringLinting(){
console.log('This function will not be linted by tslint');
}
/* tslint:enable */
view raw index.ts hosted with ❤ by GitHub

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

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay