Home

Awesome

eslint plugin angular Npm version Npm downloads per month

Greenkeeper badge

ESLint rules for your angular project with checks for best-practices, conventions or potential errors.

Build Status Npm dependencies devDependency Status Join the chat at https://gitter.im/Gillespie59/eslint-plugin-angular Coverage Status

Summary

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.

Contents

Usage with shareable config

  1. Install eslint as a dev-dependency:

    npm install --save-dev eslint
    
  2. Install eslint-plugin-angular as a dev-dependency:

    npm install --save-dev eslint-plugin-angular
    
  3. Use the shareable config by adding it to your .eslintrc:

    extends: plugin:angular/johnpapa
    

Usage without shareable config

  1. Install eslint as a dev-dependency:

    npm install --save-dev eslint
    
  2. Install eslint-plugin-angular as a dev-dependency:

    npm install --save-dev eslint-plugin-angular
    
  3. Enable the plugin by adding it to your .eslintrc:

    plugins:
      - angular
    
  4. You can also configure these rules in your .eslintrc. All rules defined in this plugin have to be prefixed by 'angular/'

    plugins:
      - angular
    rules:
      - angular/controller_name: 0
    

Rules

Rules in eslint-plugin-angular are divided into several categories to help you better understand their value.

Possible Errors

The following rules detect patterns that can lead to errors.

Best Practices

These are rules designed to prevent you from making mistakes. They either prescribe a better way of doing something or help you avoid footguns..

Deprecated Angular Features

These rules prevent you from using deprecated angular features.

Naming

These rules help you to specify several naming conventions.

Conventions

Angular often provide multi ways to to something. These rules help you to define convention for your project.

Angular Wrappers

These rules help you to enforce the usage of angular wrappers.

Misspelling

These rules help you avoiding misspellings.


Need your help

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.

How to create a new rule

We appreciate contributions and the following notes will help you before you open a Pull Request.

Check the issues

Have a look at the existing issues. There may exist similar issues with useful information.

Read the documentation

There are some useful references for creating new rules. Specificly useful are:

Files you have to create

Files you have to touch

Before you open your PR

Rules specific for Angular 1 or 2

We 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.

plugins:
  - angular

rules:
    angular/controller-name:
      - 2
      - '/[A-Z].*Controller$/'

globals:
    angular: true

settings:
    angular: 2

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) {
    }
};

Default ESLint configuration file

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:
      - 0

Who uses it?

Team

Emmanuel DemeyTilman PotthofRemco Haszing
Emmanuel DemeyTilman PotthofRemco Haszing