Slide 1

Slide 1 text

Linting Angular github.com/mgechev twitter.com/mgechev blog.mgechev.com

Slide 2

Slide 2 text

github.com/mgechev twitter.com/mgechev blog.mgechev.com About deprecated

Slide 3

Slide 3 text

agenda

Slide 4

Slide 4 text

– angular.io “…a list of guidelines on building Angular applications…” Angular Style Guide

Slide 5

Slide 5 text

– angular.io “…a list of guidelines on building Angular applications…” Angular Style Guide

Slide 6

Slide 6 text

Using Style Guide in your project

Slide 7

Slide 7 text

Enforcing common style • Fork the official style guide • Modify the styles according to your needs • Introduce the style guide to your team • Verify that each individual code change follows it

Slide 8

Slide 8 text

Enforcing common style • Fork the official style guide • Modify the styles according to your needs • Introduce the style guide to your team • Verify that each individual code change follows it

Slide 9

Slide 9 text

Enforcing common style • Fork the official style guide • Modify the styles according to your needs • Introduce the style guide to the rest of your team • Verify that each individual code change follows it

Slide 10

Slide 10 text

Enforcing common style • Fork the official style guide • Modify the styles according to your needs • Introduce the style guide to the rest of your team • Verify that each individual code change follows it

Slide 11

Slide 11 text

Code Review process

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

manual boring error-prone

Slide 14

Slide 14 text

introducing codelyzer

Slide 15

Slide 15 text

“Codelyzer contains set of rules that provide automatic alignment to the Angular Style Guide”

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Why not instant feedback

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Why it’s possible in Angular 2

Slide 20

Slide 20 text

Analyzable templates https://flic.kr/p/irHwLW

Slide 21

Slide 21 text

Angular 1

Slide 22

Slide 22 text

Angular 1

Slide 23

Slide 23 text

Angular 1

Slide 24

Slide 24 text

Angular 1

Slide 25

Slide 25 text

Angular 2

Slide 26

Slide 26 text

Angular 2

Slide 27

Slide 27 text

How codelyzer Works

Slide 28

Slide 28 text

import { Component } from '@angular/core'; @Component({ selector: 'sd-home', template: `

{{ 'Hello ' + name }}

` }) class HomeComponent { name: string; } Typical Linter

Slide 29

Slide 29 text

import { Component } from '@angular/core'; @Component({ selector: 'sd-home', template: `

{{ 'Hello ' + name }}

` }) class HomeComponent { name: string; } Script class CustomHeading members decorators expression expression Component arguments properties property ObjectLiteral … name selector initializer custom- heading property name template initializer

{{heading}}

TypeScript AST

Slide 30

Slide 30 text

Angular has templates

Slide 31

Slide 31 text

import { Component } from '@angular/core'; @Component({ selector: 'sd-home', template: `

{{ 'Hello ' + name }}

` }) class HomeComponent { name: string; }

Slide 32

Slide 32 text

Script class CustomHeading members decorators … property name template initializer

{{foo + bar}}

… HtmlElementAst h1 HtmlTextAst {{“Hello” + name}} import { Component } from '@angular/core'; @Component({ selector: 'sd-home', template: `

{{ 'Hello ' + name }}

` }) class HomeComponent { name: string; } TypeScript + template ASTs

Slide 33

Slide 33 text

Angular’s templates have expressions

Slide 34

Slide 34 text

import { Component } from '@angular/core'; @Component({ selector: 'sd-home', template: `

{{ 'Hello ' + name }}

` }) class HomeComponent { name: string; }

Slide 35

Slide 35 text

Script class CustomHeading members decorators … property name template initializer

{{foo + bar}}

… HtmlElementAst h1 HtmlTextAst {{“Hello” + name}} import { Component } from '@angular/core'; @Component({ selector: 'sd-home', template: `

{{ 'Hello ' + name }}

` }) class HomeComponent { name: string; } + “Hello” name {{}} TypeScript + template + Angular expressions ASTs

Slide 36

Slide 36 text

codelyzer analyzes all produced ASTs based on their context

Slide 37

Slide 37 text

Based on tslint with extended parsing

Slide 38

Slide 38 text

Adoption

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

and later…

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Available in angular-cli

Slide 44

Slide 44 text

ng2lint

Slide 45

Slide 45 text

ng2lint

Slide 46

Slide 46 text

github.com/mgechev/ codelyzer

Slide 47

Slide 47 text

Thank you! github.com/mgechev twitter.com/mgechev blog.mgechev.com