Next 14 App
npx create-next-app@latest

npm install --save-dev eslint prettier eslint-config-prettier eslint-plugin-prettier @typescript-eslint/parser @typescript-eslint/eslint-plugin husky lint-staged prettier-plugin-tailwindcss @commitlint/{cli,config-conventional} eslint-plugin-import-helpers
Development Dependencies for Next.js with TypeScript
--save-dev: Saves dependencies only for the development environment.
eslint: Tool to analyze and find problems in JavaScript and TypeScript code.
prettier: Code formatter that ensures a consistent style throughout the project.
eslint-config-prettier: Disables ESLint rules that might interfere with Prettier.
eslint-plugin-prettier: Integrates Prettier with ESLint to show formatting errors.
@typescript-eslint/parser: Parser that allows ESLint to understand TypeScript.
@typescript-eslint/eslint-plugin: Set of specific TypeScript rules for ESLint.
husky: Tool to create Git hooks, helping automate tasks before committing.
lint-staged: Runs linters on staged files in Git.
prettier-plugin-tailwindcss: Plugin for Prettier that automatically sorts Tailwind CSS classes.
@commitlint/cli, @commitlint/config-conventional: Tools to ensure commit messages follow a conventional standard.
eslint-plugin-import-helpers: ESLint plugin to automatically order imports.
Eslint Config
eslint.config.mjs
import { FlatCompat } from "@eslint/eslintrc";
import { dirname } from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
});
const eslintConfig = [
...compat.config({
extends: [
"next/core-web-vitals",
"next/typescript",
"prettier",
// nuevo
// "eslint:recommended",
// "plugin:@typescript-eslint/recommended",
// "plugin:react/recommended",
// "plugin:react-hooks/recommended",
// "plugin:@next/next/recommended",
// "prettier",
],
plugins: ["@typescript-eslint", "prettier", "eslint-plugin-import-helpers"],
parser: "@typescript-eslint/parser",
// parserOptions: {
// ecmaVersion: 2020,
// sourceType: "module",
// },
env: {
browser: true,
node: true,
},
ignorePatterns: ["node_modules", ".next", "public" , "eslint.config.mjs"],
rules: {
"import/no-unresolved": "error",
"import/extensions": "error",
// nuevo
// "prettier/prettier": ["error"],
// "react/react-in-jsx-scope": "error",
"react/prop-types": "error",
"no-multiple-empty-lines": ["error", { max: 1, maxEOF: 1 }],
"import-helpers/order-imports": [
"error",
{
newlinesBetween: "always",
groups: [
["/^next/", "module"],
"/@styles/",
"/@components/",
"/@lib/",
["parent", "sibling", "index"],
],
alphabetize: { order: "asc", ignoreCase: true },
},
],
},
// settings: {
// react: {
// version: "detect",
// },
// },
}),
];
export default eslintConfig;
Prettier Config
prettier.config.js
module.exports = {
"useTabs": false,
"singleQuote": false,
"plugins": ["prettier-plugin-tailwindcss"]
};
Commitlint Config
commitlint.config.js
module.exports = { extends: ["@commitlint/config-conventional"] };
Husky
npx husky install
pre-commit
npx lint-staged
commit-msg
npx --no -- commitlint --edit
Package.json
package.json
"format": "prettier --write .",
"lint": "eslint --fix . --ext .js,.jsx,.ts,.tsx",
"prepare": "husky install"
Lint Staged Config
.lintstagedrc
{
"**/*.{js,jsx,ts,tsx}": ["npm run format", "npm run lint"]
}
Ignore Eslint
.eslintignore
dist
package-lock.json
husky
configs
env
public
server.js
jsconfig.json
package.json
public
README.md
.eslintrc
.eslintrc.json
.eslintrc.js
.prettierrc.json
.eslint*
commitlint.config.js
next-env.d.ts
postcss.config.js
prettier.config.js
Ignore Prettier
.prettierignore
dist
package-lock.json
configs
env
husky
public
server.js
jsconfig.json
package.json
public
README.md
.eslintrc
.eslintrc.json
.eslintrc.js
.prettierrc.json
commitlint.config.js
next-env.d.ts
postcss.config.js
commitlint.config.js
prettier.config.js