ESLint
Course: ESLint, Prettier and Pre-commit hooks - chapter 2
Ref - https://eslint.org/

Node.js express app
Section titled “Node.js express app”Let’s say you have a basic node.js app
import express from "express";
const app = express();let x = 1;
app.get("/", (req, res) => { res.json({ message: "Hi there" });});- Add ESLint
npm init @eslint/config@latest💡 Make sure you press
spaceto actually select the values. If you face issues, try usingyarninstead ofnpm(npm i -g yarn)

- Explore
eslint.config.mjs
import globals from "globals";import pluginJs from "@eslint/js";import tseslint from "typescript-eslint";
export default [ {languageOptions: { globals: globals.node }}, pluginJs.configs.recommended, ...tseslint.configs.recommended,];- You might have to install typescript
yarn add typescript- Update package.json
"scripts": { "lint": "eslint . " },-
Run
npm run lint
-
Try removing the extra variable
import express from "express";
const app = express();
app.get("/", (req, res) => { res.json({ message: "Hi there" });});-
Now run
npm run lint
-
Try breaking the indendation
import express from "express";
const app = express();
app.get("/", (req, res) => { res.json({ message: "Hi there" });});- Notice eslint still
DOESNTcomplain
Why ESLint doesnt complain?
Section titled “Why ESLint doesnt complain?”Because ESLint is ideally meant for checking code quality and not code formatting
You can still enable code formatting checks in eslint (discussed in next slide)