Building a Simple Linting Tool
Create a custom diagnostic tool using the compiler API.
What Is a Linting Tool?
A linting tool analyzes source code to report style or correctness issues. Using the TypeScript compiler API lets you build type-aware rules that ESLint plugins cannot achieve alone.
// Goal: warn when console.log is called in TypeScript filesProject Setup
Create a Node.js script that loads a TypeScript program, traverses the AST, and reports diagnostics.
import ts from "typescript";
import path from "path";
const files = ["src/index.ts"];
const program = ts.createProgram(files, { strict: true });All lessons in this course
- Creating a TypeScript Program with the API
- Traversing the AST with Visitors
- Custom Transformers and Code Generation
- Building a Simple Linting Tool