ESLint plugin for Next.js with 21 rules enforcing best practices and Core Web Vitals optimization.
tessl install tessl/npm-next--eslint-plugin-next@15.5.0A comprehensive ESLint plugin specifically designed for Next.js applications, providing 21 specialized linting rules that enforce Next.js best practices and optimize Core Web Vitals performance. The plugin includes preset configurations for both general Next.js development and performance-focused linting.
npm install --save-dev @next/eslint-plugin-nextimport plugin from "@next/eslint-plugin-next";
import { rules, configs, flatConfig } from "@next/eslint-plugin-next";const plugin = require("@next/eslint-plugin-next");
const { rules, configs, flatConfig } = require("@next/eslint-plugin-next");// .eslintrc.js
module.exports = {
extends: ["plugin:@next/next/recommended"],
// Or for performance focus:
// extends: ["plugin:@next/next/core-web-vitals"],
};// eslint.config.js
import { flatConfig } from "@next/eslint-plugin-next";
export default [
flatConfig.recommended,
// Or for performance focus:
// flatConfig.coreWebVitals,
];The plugin is organized around several key components:
Pre-configured ESLint rule sets optimized for different Next.js development scenarios.
interface PluginConfigs {
recommended: {
plugins: string[];
rules: Record<string, 'warn' | 'error'>;
};
'core-web-vitals': {
plugins: string[];
extends: string[];
rules: Record<string, 'error'>;
};
}
interface FlatConfig {
recommended: {
name: string;
plugins: Record<string, any>;
rules: Record<string, 'warn' | 'error'>;
};
coreWebVitals: {
name: string;
plugins: Record<string, any>;
rules: Record<string, 'warn' | 'error'>;
};
}Rules focused on optimizing loading performance and Core Web Vitals metrics.
interface PerformanceRules {
'google-font-display': Rule.RuleModule;
'google-font-preconnect': Rule.RuleModule;
'no-html-link-for-pages': Rule.RuleModule;
'no-sync-scripts': Rule.RuleModule;
'no-img-element': Rule.RuleModule;
'no-page-custom-font': Rule.RuleModule;
}Rules for proper Next.js document structure and head element management.
interface DocumentRules {
'no-head-element': Rule.RuleModule;
'no-head-import-in-document': Rule.RuleModule;
'no-document-import-in-page': Rule.RuleModule;
'no-duplicate-head': Rule.RuleModule;
'no-title-in-document-head': Rule.RuleModule;
'no-styled-jsx-in-document': Rule.RuleModule;
}Rules for proper script loading and asset management in Next.js applications.
interface ScriptRules {
'inline-script-id': Rule.RuleModule;
'next-script-for-ga': Rule.RuleModule;
'no-before-interactive-script-outside-document': Rule.RuleModule;
'no-script-component-in-head': Rule.RuleModule;
'no-unwanted-polyfillio': Rule.RuleModule;
'no-css-tags': Rule.RuleModule;
}Rules for enforcing Next.js conventions and preventing common mistakes.
interface ConventionRules {
'no-assign-module-variable': Rule.RuleModule;
'no-async-client-component': Rule.RuleModule;
'no-typos': Rule.RuleModule;
}import type { Rule } from 'eslint';
interface ESLintPlugin {
rules: Record<string, Rule.RuleModule>;
configs: {
recommended: {
plugins: string[];
rules: Record<string, 'warn' | 'error'>;
};
'core-web-vitals': {
plugins: string[];
extends: string[];
rules: Record<string, 'error'>;
};
};
}
interface ValidationError {
message: string;
line?: number;
column?: number;
severity: 'error' | 'warn';
}