Angular2 is the next version of the amazing JavaScript framework we use since few year. As this version is quiet different from the first version, the eslint-plugin-angular, available on NPM, should give the possilibility to create rules for the first or second version. And, in fact, it is very easy to do, and it is actually already usable.

We just need to add a new property in the global ESLint settings object we can define in the configuration file of this tool. For the eslint-plugin-angular, I have decided to create an… angular property, that can have two values : 1 (for Angular 1) or 2 (for Angular 2)

  - angular

      - 2
      - '/[A-Z].*Controller$/'

    angular: true

    angular: 2

Once this value defined, we can have access to this property in our rule. We just need to read the value of the context object, defined as a parameter of the module, in which the the rule is defined :

module.exports = function(context) {

  'use strict';

  //We disabled this rule for Angular2-based application
  if(context.settings.angular === 2){
    return {};

  return {

    'CallExpression': function(node) {

Emmanuel Demey

Consultant - Formateur Web

comments powered by Disqus