<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ali Hamza</title>
    <description>The latest articles on Forem by Ali Hamza (@alihamza126).</description>
    <link>https://forem.com/alihamza126</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1347324%2F1cd3a6a1-35a4-423a-a09c-84a482708768.jpeg</url>
      <title>Forem: Ali Hamza</title>
      <link>https://forem.com/alihamza126</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/alihamza126"/>
    <language>en</language>
    <item>
      <title>Set up a Prettier, ESLint, Husky and lint-staged Integration with TypeScript in Next.js 16 | 2025</title>
      <dc:creator>Ali Hamza</dc:creator>
      <pubDate>Wed, 29 Oct 2025 08:56:56 +0000</pubDate>
      <link>https://forem.com/alihamza126/set-up-a-prettier-eslint-husky-and-lint-staged-integration-with-typescript-in-nextjs-16-2025-2k55</link>
      <guid>https://forem.com/alihamza126/set-up-a-prettier-eslint-husky-and-lint-staged-integration-with-typescript-in-nextjs-16-2025-2k55</guid>
      <description>&lt;p&gt;With the release of Next.js 16 and the latest ESLint updates, setting up a clean and consistent development workflow has become even smoother. In this article, we’ll walk through how to configure ESLint, Prettier, Husky, and lint-staged in a Next.js 16 project to maintain high code quality and ensure a seamless developer experience.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why Use ESLint, Prettier, Husky, and lint-staged?
&lt;/h1&gt;

&lt;p&gt;Maintaining clean and consistent code is crucial in any project, and that’s where these tools come in:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ESLint:&lt;/strong&gt; helps catch common bugs and enforces coding standards, keeping your codebase error-free and consistent.&lt;br&gt;
&lt;strong&gt;Prettier:&lt;/strong&gt; takes care of formatting automatically, so your code always looks neat and follows a uniform style.&lt;br&gt;
&lt;strong&gt;Husky:&lt;/strong&gt; lets you run scripts (like linting or formatting) before committing changes, ensuring only clean code gets pushed.&lt;br&gt;
&lt;strong&gt;lint-staged:&lt;/strong&gt; works alongside Husky to run these checks only on files that are staged for commit — making the process faster and more efficient.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Create a Next.js Project
&lt;/h2&gt;

&lt;p&gt;create a new Next.js project by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-next-app@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On installation, you’ll see the following prompts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What is your project named? next-app
Would you like to use TypeScript? No / Yes  --- Yes 
Would you like to use ESLint? No / Yes --- Yes
Would you like to use Tailwind CSS? No / Yes --- Yes
Would you like to use `src/` directory? No / Yes --- Yes
Would you like to use App Router? (recommended) No / Yes --- Yes
Would you like to customize the default import alias (@/*)? No / Yes --- No
What import alias would you like configured? @/*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you complete the setup prompts, create-next-app will automatically generate a new folder using your chosen project name and initialize the project structure inside it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Install Dependencies
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev eslint eslint-config-next eslint-config-prettier husky prettier lint-staged

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Create Prettier Configurations
&lt;/h2&gt;

&lt;p&gt;Create an Prettier configuration file (prettier.config.js) and a Prettier ignore file (.prettierignore):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;prettier.config.js:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The prettier.config.js file defines your Prettier formatting rules — it’s where you set your code style preferences to keep your project clean and consistent.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
  semi: true,
  singleQuote: true,
  trailingComma: 'es5',
  tabWidth: 2,
  printWidth: 80,
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;semi:&lt;/strong&gt; true – Ensures semicolons are added at the end of every statement for cleaner syntax.&lt;br&gt;
&lt;strong&gt;singleQuote:&lt;/strong&gt; true – Uses single quotes (' ') instead of double quotes (" ").&lt;br&gt;
&lt;strong&gt;trailingComma:&lt;/strong&gt; 'es5' – Adds trailing commas where valid in ES5 (like in objects, arrays, etc.) to make code diffs cleaner.&lt;br&gt;
&lt;strong&gt;tabWidth:&lt;/strong&gt; 2 – Sets indentation to 2 spaces for consistent and readable code.&lt;br&gt;
&lt;strong&gt;printWidth:&lt;/strong&gt; 80 – Wraps lines that exceed 80 characters to maintain readability.&lt;/p&gt;
&lt;h2&gt;
  
  
  .prettierignore
&lt;/h2&gt;

&lt;p&gt;The .prettierignore file tells Prettier which files or folders to skip during code formatting.&lt;br&gt;
It works just like a .gitignore file — you can list specific files, directories, or file patterns that you don’t want Prettier to format.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.next
.cache
package-lock.json
public
node_modules
next-env.d.ts
next.config.ts
yarn.lock
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: Create ESLint Configurations
&lt;/h2&gt;

&lt;p&gt;Create an ESLint configuration file (eslint.config.mjs) :&lt;/p&gt;

&lt;h2&gt;
  
  
  eslint.config.mjs
&lt;/h2&gt;

&lt;p&gt;The eslint.config.mjs file defines rules and settings for ESLint, a tool that helps you find and fix problems in your JavaScript or TypeScript code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { defineConfig, globalIgnores } from 'eslint/config';
import nextVitals from 'eslint-config-next/core-web-vitals';
import prettier from 'eslint-config-prettier/flat';

const eslintConfig = defineConfig([
  ...nextVitals,
  prettier,
  {
    rules: {
      // Add custom rules
    },
  },
  globalIgnores([
    '.next/**',
    'out/**',
    'build/**',
    'next-env.d.ts',
    'node_modules/**',
  ]),
]);

export default eslintConfig;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;defineConfig&lt;/code&gt; – Used to define ESLint configuration in a structured way.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;globalIgnores&lt;/code&gt; – Specifies files and folders ESLint should ignore.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nextVitals&lt;/code&gt; – Imports Next.js Core Web Vitals rules for better performance and accessibility.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;...nextVitals&lt;/code&gt; – Loads Next.js-specific ESLint settings focused on performance, accessibility, and best practices.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;prettier&lt;/code&gt; – Ensures that Prettier’s formatting rules override ESLint’s style-related rules to prevent conflicts.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rules&lt;/code&gt; – A section where you can add custom ESLint rules to enforce specific coding styles.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;globalIgnores([...])&lt;/code&gt; - Excludes specific files and folders from linting to improve performance and avoid unnecessary warnings:&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Create Husky Configurations
&lt;/h2&gt;

&lt;p&gt;Create an Husky configuration file (.huskyrc):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;.huskyrc&lt;/strong&gt;&lt;br&gt;
The .huskyrc file is used to configure Git hooks with the help of Husky — a tool that makes it easy to manage and automate Git hooks in your project.&lt;br&gt;
Git hooks are scripts that run automatically at specific stages of the Git workflow, such as before committing (pre-commit) or before pushing (pre-push), helping enforce code quality and consistency.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "hooks": {
      "pre-commit": "lint-staged"
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I have defined a single Git hook: pre-commit. This hook is set to run the lint-staged command before each commit. Here’s a breakdown:&lt;/p&gt;

&lt;p&gt;pre-commit: This is the name of the Git hook. It corresponds to the hook that runs just before a commit is made.&lt;/p&gt;

&lt;p&gt;lint-staged: This is the command that will be executed when the pre-commit hook is triggered. lint-staged is a tool that runs linters (code style checkers, etc.) on files that are staged for the commit.&lt;/p&gt;

&lt;p&gt;And to initialize the our pre-commit hooks run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx husky init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 6: Add Scripts to package.json&lt;/p&gt;

&lt;p&gt;Add scripts to your package.json:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "eslint .",
    "lint:fix": "eslint . --fix",
    "format": "prettier --write .",
    "check-format": "prettier --check .",
    "check-types": "tsc --pretty --noEmit",
    "prepare": "husky"
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;By setting up ESLint, Prettier, Husky, and lint-staged in your Next.js project, you ensure a consistent code style and catch potential issues early in the development process. This leads to cleaner code and a more efficient and collaborative development workflow. Happy coding with Next.js!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>nextjs</category>
      <category>eslint</category>
      <category>prettier</category>
    </item>
  </channel>
</rss>
