2.4.2 • Published 5 months ago

eslint-plugin-propper-nextjs v2.4.2

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

eslint-plugin-propper-nextjs

Overview

eslint-plugin-propper-nextjs is a custom ESLint plugin designed to enforce best practices for Next.js projects.
It ensures correct default exports in Next.js reserved files, restricts default exports in other files,
and enforces import and styling rules for consistency.


Installation

To install this plugin, run:

npm install --save-dev eslint-plugin-propper-nextjs eslint-plugin-import

or with pnpm:

pnpm install -D eslint-plugin-propper-nextjs eslint-plugin-import

Peer Dependencies

This package requires eslint-plugin-import as a peer dependency. Make sure it is installed to avoid errors.


Usage

For ESLint 9+ (Flat Config)

Modify your eslint.config.js:

import { FlatCompat } from "@eslint/eslintrc";
import { dirname } from "path";
import { fileURLToPath } from "url";
import propperNextJsPlugin from "eslint-plugin-propper-nextjs";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const compat = new FlatCompat({
  baseDirectory: __dirname,
});

const eslintConfig = [
  ...compat.extends("next/core-web-vitals", "next/typescript"),
  propperNextJsPlugin.configs.recommended, // ✅ Enables all recommended rules
  {
    ignores: ["node_modules", ".next"],
  },
];

export default eslintConfig;

For ESLint 8 and Below (.eslintrc.js format)

If using legacy ESLint config, modify .eslintrc.js:

module.exports = {
  plugins: ["propper-nextjs", "import"],
  extends: ["plugin:propper-nextjs/recommended"],
};

Rules Included

Next.js Default Export Rules

File TypeExpected Default Export Name
layout.tsxLayout
page.tsxPage
loading.tsxLoading
not-found.tsxNotFound
error.tsxError
global-error.tsxGlobalError
template.tsxTemplate

✅ Ensures correct naming for default exports in Next.js reserved files.
Prevents default exports in non-Next.js files (e.g., inside components/, lib/).
✅ Supports both named functions (export function Page() {}) and arrow functions (export const Page = () => {}).
Auto-fixable: Converts export default function() into export const ComponentName = () => {};.


Import & Code Styling Rules

RuleDescription
"import/order"Enforces structured import grouping
"import/no-duplicates"Prevents duplicate imports
"import/no-cycle"Detects circular dependencies
"import/no-extraneous-dependencies"Ensures only installed dependencies are imported
"import/first"Ensures imports come before other statements
"import/newline-after-import"Enforces a blank line after imports
"no-console"Disallows console.log in production
"quotes": ["error", "single"]Enforces single quotes for strings
"no-trailing-spaces"Removes unnecessary spaces at the end of lines
"prefer-const"Requires const for variables that are never reassigned

Release Notes

What's New in This Version?

  • Merged Rules for Next.js Exports: Now, one rule handles both naming conventions & default export restrictions.
  • Improved Plugin Registration: Fully compatible with ESLint 9+ Flat Config.
  • Removed Utility File Rule: No longer enforces utility function names.
  • Auto-Fix Enhancements: ESLint can now fix default export violations more effectively.

How This Works

1️⃣ Ensures Next.js reserved files follow correct naming conventions.
2️⃣ Prevents default exports in non-Next.js files (e.g., components/).
3️⃣ Helps structure imports and maintain clean code.
4️⃣ Auto-fixable to enforce best practices effortlessly.


Contributing

Pull requests are welcome! If you have ideas for new rules or improvements, feel free to open an issue.


Author

Maintained by Aziz Shahhuseynov.

2.4.2

5 months ago

2.4.0

5 months ago

2.2.2

5 months ago

2.2.1

5 months ago

2.1.1

5 months ago

2.0.0

5 months ago

1.1.0

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago