Syntax Trees

Will Klein

Developer

Experience

 

Convention Tests

Convention Tests, AKA

  • Linters
  • Code analyzers
  • Static analysis

What If We could write our own convention tests?

Convention Test "Frameworks"

  • Common tests included
  • Pluggable testing API
  • ESLint, for example
// Life, Universe, and Everything
var answer = 6 * 7;
// Life, Universe, and Everything
var answer = 6 * 7;
10111010001011011101000101

...

How does this work?

// Life, Universe, and Everything
var answer = 6 * 7;
[var] [answer] [=] [6] [*] [7][;]

...

Tokenize

// Life, Universe, and Everything
var answer = 6 * 7;
[var] [answer] [=] [6] [*] [7][;]

...

...

Syntax Tree!

Parse

 

ESLint

  • Builds our syntax tree for us
  • Iterates over nodes in the tree
  • For each node, do we have a test?

Docs & Code

http://willkle.in

will.klein@gmail.com

Thanks

@willslab

Made with Slides.com