
Security News
The Nightmare Before Deployment
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.
eslint-plugin-angular
Advanced tools
ESLint rules for your angular project with checks for best-practices, conventions or potential errors.
This repository will give access to new rules for the ESLint tool. You should use it only if you are developing an AngularJS application.
Since the 0.0.4 release, some rules defined in John Papa's Guideline have been implemented. In the description below, you will have a link to the corresponding part of the guideline, in order to have more information.
Install eslint as a dev-dependency:
npm install --save-dev eslint
Install eslint-plugin-angular as a dev-dependency:
npm install --save-dev eslint-plugin-angular
Use the shareable config by adding it to your eslintrc.config.mjs:
import angular from "eslint-plugin-angular";
export default defineConfig([{
plugins: {
angular
},
rules: {
...angular.configs.johnpapa.rules
}
}]);
Install eslint as a dev-dependency:
npm install --save-dev eslint
Install eslint-plugin-angular as a dev-dependency:
npm install --save-dev eslint-plugin-angular
Enable the plugin by adding it to your eslint.config.mjs:
import angular from "eslint-plugin-angular";
export default defineConfig([{
plugins: {
angular
}
}]);
You can also configure these rules in your eslint.config.mjs. All rules defined in this plugin have to be prefixed by 'angular/'
import angular from "eslint-plugin-angular";
export default defineConfig([{
plugins: {
angular
},
rules: {
"angular/controller-name": "error"
}
}]);
Rules in eslint-plugin-angular are divided into several categories to help you better understand their value.
The following rules detect patterns that can lead to errors.
angular.module('myModule') (y022)These are rules designed to prevent you from making mistakes. They either prescribe a better way of doing something or help you avoid footguns..
this in controllers (y032)$scope in controllers (y031)$q(function(resolve, reject){}) instead of $q.deferred$http for controllers, filters and directives)$on and $watch deregistration callbacks to be saved in a variableThese rules prevent you from using deprecated angular features.
$cookies instead of $cookieStore$http methods success() and error()These rules help you to specify several naming conventions.
Angular often provide multi ways to to something. These rules help you to define convention for your project.
inject functions should only consist of assignments from injected values to describe block variablesfactory() instead of service() (y040)$scope.digest() or $scope.apply()These rules help you to enforce the usage of angular wrappers.
angular.element instead of $ or jQueryangular.isDefined and angular.isUndefined instead of other undefined checks$document instead of document (y180)angular.forEach instead of native Array.prototype.forEach$interval instead of setInterval (y181)angular.fromJson and 'angular.toJson' instead of JSON.parse and JSON.stringify$log service instead of the console methodsangular.mock methods directlyangular.element objects with jQuery or $$timeout instead of setTimeout (y181)angular.isArray instead of typeof comparisonsangular.isDate instead of typeof comparisonsangular.isFunction instead of typeof comparisonsangular.isNumber instead of typeof comparisonsangular.isObject instead of typeof comparisonsangular.isString instead of typeof comparisons$window instead of window (y180)These rules help you avoiding misspellings.
It is an opensource project. Any help will be very useful. You can :
All development happens on the development branch. This means all pull requests should be made to the development branch.
If it is time to release, @Gillespie59 will bump the version in package.json, create a Git tag and merge the development branch into master. @Gillespie59 will then publish the new release to the npm registry.
We appreciate contributions and the following notes will help you before you open a Pull Request.
Have a look at the existing issues. There may exist similar issues with useful information.
There are some useful references for creating new rules. Specificly useful are:
context.getScope().rules/<your-rule>.js
<your-rule> is exactly the usage name in eslint configs angular/<your-rule>angularRule wrapper and the utils (both in rules/utils/) - they probably make things easier for yougulp docs tasktest/<your-rule>.js
gulp testcoverage/lcov-report/index.htmlexamples/<your-rule>.js
gulp docs task to test the examples and update the markdown documentationdocs/<your-rule>.md
gulp docs taskindex.js
rulesConfiguration.addRule('<your-rule>', [0, {someConfig: 'someValue'}])gulp task is workingREADME.md and docs/<your-rule>.mddevelopment branch NOT masterWe can use a property, defined in the ESLint configuration file, in order to know which version is used : Angular 1 or Angular 2. based on this property, you can create rules for each version.
import angular from "eslint-plugin-angular";
export default defineConfig([
{
files: ["**/*.js"],
plugins: {
angular
},
languageOptions: {
globals: {
angular: true
}
},
settings: {
angular: 2
},
rules: {
"angular/controller-name": ["error", "/[A-Z].*Controller$/"]
}
}
]);
And in your rule, you can access to this property thanks to the context object :
//If Angular 2 is used, we disabled the rule
if(context.settings.angular === 2){
return {};
}
return {
'CallExpression': function(node) {
}
};
Here is the basic configuration for the rules defined in the ESLint plugin, in order to be compatible with the guideline provided by @johnpapa :
rules: {
"no-use-before-define": "off"
}
| Emmanuel Demey | Tilman Potthof | Remco Haszing |
FAQs
ESLint rules for AngularJS projects
The npm package eslint-plugin-angular receives a total of 75,339 weekly downloads. As such, eslint-plugin-angular popularity was classified as popular.
We found that eslint-plugin-angular demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.

Research
/Security News
Impostor NuGet package Tracer.Fody.NLog typosquats Tracer.Fody and its author, using homoglyph tricks, and exfiltrates Stratis wallet JSON/passwords to a Russian IP address.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.