function-type - require and specify a consistent function style for components

July 29, 2025 ยท View on GitHub

Anonymous or named functions inside AngularJS components. The first parameter sets which type of function is required and can be 'named' or 'anonymous'. The second parameter is an optional list of angular object names.

Rule based on Angular 1.x

Styleguide Reference

Examples

The following patterns are considered problems when configured "anonymous":

/*eslint angular/function-type: [2,"anonymous"]*/

// invalid
angular.module('myModule').factory('myService', myServiceFn);
function myServiceFn() {
    // ...
} // error: Use anonymous functions instead of named function

The following patterns are not considered problems when configured "anonymous":

/*eslint angular/function-type: [2,"anonymous"]*/

// valid
angular.module('myModule').factory('myService', function () {
    // ...
});

The following patterns are considered problems when configured "named":

/*eslint angular/function-type: [2,"named"]*/

// invalid
angular.module('myModule').factory('myService', function () {
    // ...
}); // error: Use named functions instead of anonymous function

The following patterns are not considered problems when configured "named":

/*eslint angular/function-type: [2,"named"]*/

// valid
angular.module('myModule').factory('myService', function myService() {
    // ...
});

// valid
angular.module('myModule').factory('myService', myServiceFn);
function myServiceFn() {
    // ...
}

Version

This rule was introduced in eslint-plugin-angular 0.1.0