$30 off During Our Annual Pro Sale. View Details »

Building Custom TSLint Rules

Ash Furrow
October 30, 2018

Building Custom TSLint Rules

Ash Furrow

October 30, 2018
Tweet

More Decks by Ash Furrow

Other Decks in Programming

Transcript

  1. Building Custom TSLint Rules
    Ash Furrow, Artsy

    View Slide

  2. whoami
    - Hi I’m Ash
    - Artsy
    - Canadian
    - Recovering iOS developer
    - Photography
    - Guitar
    - Likes type systems
    - Really likes developer tooling

    View Slide

  3. View Slide

  4. View Slide

  5. TSLint
    - Checks (“lints”) your code for problems
    - There are a bunch of built-in rules
    - Line length
    - Alphabetically ordered imports
    - Variable name consistency
    - Prevent unnecessary type assertions
    - etc
    - And you can build your own!

    View Slide

  6. Custom TSLint Rules
    - Rules are just code
    - Rules provide details of what’s wrong
    - Optionally, rules can fix the code automatically ✨
    - Two types of rules:
    - String-based rules
    - AST-based rules
    - So what’s an AST?

    View Slide

  7. Abstract Syntax Trees
    - Compiler data type
    - Machine-readable representation of your code
    if (user.isAdmin) {
    return "Hello, Admin."
    } else {
    return "401 lol"
    }
    if user.isAdmin
    return return
    "Hello, Admin" "401 lol"

    View Slide

  8. astexplorer.net

    View Slide

  9. Demo
    - Okay time for code now please

    View Slide

  10. Resources
    - github.com/ashfurrow/tsnyc-tslint-rules (see: STEPS.md)
    - github.com/ashfurrow/tslint-playground (more resources linked to from here)

    View Slide