Rules that detect patterns likely to cause runtime errors or unexpected behavior in AngularJS applications.
Prevents common typos when naming methods defined on the scope object.
/**
* Avoid mistakes when naming methods defined on the scope object
* Detects typos in scope method names that could lead to runtime errors
*/
const avoidScopeTypos = {
meta: {
docs: { url: "https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/avoid-scope-typos.md" };
schema: [];
};
create: (context: ESLintContext) => ESLintVisitor;
};Usage Example:
// ✗ BAD - Common typos that cause runtime errors
$scope.$on('$destory', handler); // Should be '$destroy'
$scope.$applyAsync(); // Missing function argument
// ✓ GOOD - Correct scope method usage
$scope.$on('$destroy', handler);
$scope.$applyAsync(function() { /* handler */ });Disallows referencing modules with variables and requires using the getter syntax instead.
/**
* Require using angular.module() getter syntax instead of storing in variables
* Enforces consistent module access pattern: angular.module('myModule')
* Linked to John Papa's Angular Style Guide y022
*/
const moduleGetter = {
meta: {
docs: { url: "https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/module-getter.md" };
schema: [];
};
create: (context: ESLintContext) => ESLintVisitor;
};Usage Example:
// ✗ BAD - Storing module reference in variable
var app = angular.module('myApp');
app.controller('MyController', MyController);
// ✓ GOOD - Using getter syntax consistently
angular.module('myApp').controller('MyController', MyController);Disallows assigning modules to variables, works in conjunction with module-getter rule.
/**
* Disallow assigning modules to variables
* Enforces consistent module creation pattern
* Linked to John Papa's Angular Style Guide y021
*/
const moduleSetter = {
meta: {
docs: { url: "https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/module-setter.md" };
schema: [];
};
create: (context: ESLintContext) => ESLintVisitor;
};Usage Example:
// ✗ BAD - Assigning module to variable
var app = angular.module('myApp', []);
// ✓ GOOD - Direct module usage
angular.module('myApp', []);Disallows use of internal Angular properties prefixed with $$.
/**
* Disallow use of internal angular properties prefixed with $$
* Prevents reliance on Angular's private/internal APIs that may change
*/
const noPrivateCall = {
meta: {
docs: { url: "https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/no-private-call.md" };
schema: [];
};
create: (context: ESLintContext) => ESLintVisitor;
};Usage Example:
// ✗ BAD - Using internal Angular properties
var watchers = $scope.$$watchers;
element.$$isolateScope();
// ✓ GOOD - Using public APIs only
// Use documented public APIs instead of internal propertiesChecks for common misspelling of the $destroy event.
/**
* Check for common misspelling $on('destroy', ...)
* Prevents typos in lifecycle event handling that cause memory leaks
*/
const onDestroy = {
meta: {
docs: { url: "https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/on-destroy.md" };
schema: [];
};
create: (context: ESLintContext) => ESLintVisitor;
};Usage Example:
// ✗ BAD - Common misspelling causes handler to never be called
$scope.$on('destroy', function() {
// cleanup code that never runs
});
// ✓ GOOD - Correct event name
$scope.$on('$destroy', function() {
// cleanup code runs properly
});interface ESLintContext {
getSourceCode(): SourceCode;
report(descriptor: ReportDescriptor): void;
settings: {
angular?: number; // Angular version (1 or 2)
};
}
interface ESLintVisitor {
[key: string]: (node: any) => void;
}
interface ReportDescriptor {
node: any;
message: string;
data?: Record<string, any>;
}