
Code Transformation and Linting with ASTs
Learning Paths:
Topics:
Table of Contents
Code Transformation and Linting with Abstract Syntax Trees
Abstract Syntax Trees
Examples of Abstract Syntax Trees
Kent discusses the importance of Abstract Syntax Trees (AST) by examining examples where they are used: plugins for Babel and ESLint as well as within Codemods.Introducing Abstract Syntax Trees
Through visual and online demonstrations, Kent discusses what an Abstract Syntax Tree (AST) is. AST is a visual tree representation of the abstract syntax of programming code. AST's can help aid in learning how programming works by quickly seeing the progression of code through a program.Exploring ASTs
To demonstrate the power of AST, Kent will review three use cases in the course: building out Babel and ESLint plugins, and then showing how to use AST with Codemods. Using the AST Explorer tool, Kent starts with an ESLint example to show how to traverse AST so that programmers can track stylistic code, logical problems, or domain specific issues to keep bugs from entering the codebase.
ESLint Plugin and AST
Challenge 1: Making a Plugin
In this challenge, students write an ESLint plugin.Challenge 1: Solution
Kent walks through the solution to Challenge 1.Challenge 2: Adding New Methods
In this challenge, students write a plugin that integrates new methods and functions that past validation.Challenge 2: Solution
Kent walks through the solution to Challenge 2 and takes questions from students.Challenge 3: Schema Property
In this challenge, students learn about using the JSON schema property.Challenge 3: Solution
Kent walks through the solution to Challenge 3.Challenge 4: Edge Cases
In this challenge, students learn how to create plugins for edge cases.Challenge 4: Solution
Kent walks through the solution to Challenge 4 and takes questions from students.Challenge 5: Applying Fixes
In this challenge, students learn how to incorporate the ability to fix bad code automatically.Challenge 5: Solution
Kent walks through the solution to Challenge 5.
Babel Plugin and AST
Introducing Babel and AST
In showing how to set up working with Abstract Syntax Trees in Babel, Kent demonstrates the differences and similarities between working with ESLint.Challenge 6: Captains Log
In this challenge, students use a snapshot of transpired code.Challenge 6: Solution
Kent walks through the solution to Challenge 6.Challenge 7: Prefixing
In this challenge, students continue to build out the plugin by attaching a prefix to a function.Challenge 7: Solution
Kent walks through the solution to Challenge 7.Challenge 8: Arrow Function
In this challenge, students add support for arrow function expression.Challenge 8: Solution
Kent walks through the solution to Challenge 8.Challenge 9: Divide Function
In this challenge, students add support for divide function.Challenge 9: Solution
Kent walks through the solution to Challenge 9.
Codemods and AST
Introducing Codemods and AST
Kent reviews integrating Codemod, a library used to refactor code which can be partially automated, with AST.Challenge 10: Upgrade Patterns
In this challenge, students update code to swap out jQuery with vanilla JavaScript.Challenge 10: Solution
Kent walks through the solution to Challenge 10.Challenge 11: Swap Out Utilities
In this challenge, students continue to work to swap out more jQuery with vanilla JavaScript functions.Challenge 11: Solution
Kent walks through the solution to Challenge 11.