Ignore ESLint Directives in Code

The other day I’ve had to refactor a piece of angular code. Unfortunately, the original code was written a long time ago and has some issues like having $scope in controllers and a rather large number of unused variables. changing the $scope to this is a very time-consuming task as it implies prefixing functions and variables in the HTML code as well as selective replacements in JS ($scope.$watch for example must remain intact).

In order to minimise the effort, I’ve decided to only move the code blocks around using John Papa’s code.

In the refactored code, I’d like to get warnings for the new code, but skip them in the old one. Therefore, I can’t just disable the rules from the .eslintrc file. I found there are two ways to temporarily disable rules:

  1. for one line – using // eslint-disable-line <rule> , e.g.:

  2. for a block – using /* eslint-disable <rule> */ and

, e.g.:

function activate() {
$scope.myvar = ‘something’;
// …
/* eslint-enable angular/controller-as */

Using the two you can control the parser locally and allow incremental refactoring.


A little experiment: If you find this post and ad below useful, please check the ad out :-)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top