JavaScript logoJavaScript/
JS-0534

Specify a prefix for all constant namesJS-0534

Minor severityMinor
Anti-pattern categoryAnti-pattern
angularjs

It is recommended to use consistent nomenclature for constants across the codebase because naming conventions help provide a consistent way to find the content at a glance.

There are few advantages of consistent, constant naming:

  • Provides a consistent way to identify and reference constants quickly.
  • Avoids name collisions with built-in constants and services that use the $ prefix because $ is a reserved keyword for Angular version v1.x.x.

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

Bad Practice

// error: The otherConstant constant should follow this pattern: /^xyz/
angular
    .module('myModule')
    .constant('otherConstant', function () {
        // ...
    });
angular
    .module('myModule')
    .constant('prefixConstant', function () {
        // ...
    });

References