Skip to content

Rule section - group rules in categories #297

@tilmanschweitzer

Description

@tilmanschweitzer

The categories in the eslint documentation (http://eslint.org/docs/rules/) help to get an overview, what rules are useful for what use cases.

Eslint has the following categories. I marked those which could be useful for the angular rules. I added explanation to the possible errors:

Proposal

Possible errors

  • module-getter (angular modules referenced though global variables can lead to errors)
  • module-setter (angular modules referenced though global variables can lead to errors)
  • no-private-call (private apis change between version without any documentation and can lead to errors)

Best Practices

  • controller-as - disallow assignments to $scope in controllers
  • controller-as-route - require the use of controllerAs in routes or states
  • component-limit - limit the number of angular components per file
  • controller-as-vm - require and specify a capture variable for this in controllers
  • deferred - use $q(function(resolve, reject){}) instead of $q.deferred
  • di-unused - disallow unused DI parameters
  • directive-restrict - disallow any other directive restrict than 'A' or 'E'
  • empty-controller - disallow empty controllers
  • no-controller - disallow use of controllers (according to the component first pattern)
  • no-inline-template - disallow the use of inline templates
  • no-services - disallow DI of specified services for other angular components ($http for controllers, filters and directives)
  • on-watch - require $on and $watch deregistration callbacks to be saved in a variable

Deprecated angular features

  • no-cookiestore - use $cookies instead of $cookieStore
  • no-http-callback - disallow the $http methods success() and error()

Naming

  • controller-name - require and specify a prefix for all controller names
  • directive-name - require and specify a prefix for all directive names
  • file-name - require and specify a consistent component name pattern
  • filter-name - require and specify a prefix for all filter names
  • module-name - require and specify a prefix for all module names
  • service-name - require and specify a prefix for all service names

Code conventions

  • di - require a consistent DI syntax
  • di-order - require DI parameters to be sorted alphabetically
  • function-type - require and specify a consistent function style for components ('named' or 'anonymous')
  • module-dependency-order - require a consistent order of module dependencies
  • one-dependency-per-line - require all DI parameters to be located in their own line
  • no-service-method - use factory() instead of service()
  • rest-service - disallow different rest service and specify one of '$http', '$resource', 'Restangular'
  • watchers-execution - require and specify consistent use $scope.digest() or $scope.apply()

Angular wrappers

  • angularelement - use angular.element instead of $ or jQuery
  • definedundefined - use angular.isDefined and angular.isUndefined instead of other undefined checks
  • document-service - use $document instead of document
  • foreach - use angular.forEach instead of native Array.prototype.forEach
  • interval-service - use $interval instead of setInterval
  • json-functions - use angular.fromJson and 'angular.toJson' instead of JSON.parse and JSON.stringify
  • log - use the $log service instead of the console methods
  • no-angular-mock - require to use angular.mock methods directly
  • no-jquery-angularelement - disallow to wrap angular.element objects with jQuery or $
  • timeout-service - use $timeout instead of setTimeout
  • typecheck-array - use angular.isArray instead of typeof comparisons
  • typecheck-date - use angular.isDate instead of typeof comparisons
  • typecheck-function - use angular.isFunction instead of typeof comparisons
  • typecheck-number - use angular.isNumber instead of typeof comparisons
  • typecheck-object - use angular.isObject instead of typeof comparisons
  • typecheck-string - use angular.isString instead of typeof comparisons
  • window-service - use $window instead of window

Deprecated rules (will be removed in next major version)

  • typecheck-regexp - DEPRECATED! use angular.isRegexp instead of other comparisons (no native angular method)
  • no-digest - DEPRECATED! use $apply() instead of $digest() (replaced by watchers-execution)

Metadata

Metadata

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions