
ESLint Has a Free API — Here's How to Lint and Fix JavaScript Programmatically
ESLint is the standard JavaScript linter with 200+ built-in rules and a rich plugin ecosystem. The new flat config format makes it simpler than ever. Installation npm install -D eslint npx eslint --init Flat Config (eslint.config.js) import js from " @eslint/js " ; import tseslint from " typescript-eslint " ; export default [ js . configs . recommended , ... tseslint . configs . recommended , { rules : { " no-unused-vars " : " warn " , " no-console " : [ " error " , { allow : [ " warn " , " error " ] }], " prefer-const " : " error " , " @typescript-eslint/no-explicit-any " : " warn " } }, { ignores : [ " dist/ " , " node_modules/ " , " *.config.js " ] } ]; Running ESLint npx eslint src/ # Lint files npx eslint src/ --fix # Auto-fix issues npx eslint src/ --format json # JSON output Programmatic API import { ESLint } from " eslint " ; const eslint = new ESLint ({ fix : true }); // Lint files const results = await eslint . lintFiles ([ " src/**/*.ts " ]); // Apply fixes await ESLint . ou
Continue reading on Dev.to Webdev
Opens in a new tab


