JavaScript

JavaScript

Made by DeepSource

Require and specify a prefix for all controller names JS-0535

Anti-pattern
Minor
angularjs

It is recommended to use a consistent prefix across all controllers. The recommended way to name controllers ares:

  • Controllers should be named after their feature
  • Controllers should use UpperCamelCase, as they are constructors

Having a consistent controller provides the following advantages:

  • Provides a way to identify and reference controllers quickly.
  • UpperCamelCase is conventional for identifying the object that can be instantiated using a constructor

It is also recommended to append the suffix Controller to every controller's name. The Controller suffix is more commonly used and is explicitly descriptive.

Note: This issue works based on the developer's eslint config. Changing the preferred controller naming format can be done by changing the rule's option for the rule named angular/controller-name.

Bad Practice

// error: The MyCtrl controller should follow this pattern: /^[A-Z][a-zA-Z0-9]*Controller$/
angular
    .module('myModule')
    .controller('MyCtrl', function () {
        // ...
    });

Recommended

angular
    .module('myModule')
    .controller('MyController', function () {
        // ...
    });