Skip to content

feat(eslint): add nextjs rules#285

Merged
kodiakhq[bot] merged 1 commit into
mainfrom
add-nextjs
Jul 25, 2025
Merged

feat(eslint): add nextjs rules#285
kodiakhq[bot] merged 1 commit into
mainfrom
add-nextjs

Conversation

@mheob
Copy link
Copy Markdown
Owner

@mheob mheob commented Jul 25, 2025

Summary by CodeRabbit

  • New Features

    • Added official Next.js support to the ESLint config, including a dedicated configuration and comprehensive Next.js rule coverage.
    • Users can now enable Next.js-specific linting rules with an optional configuration flag.
  • Documentation

    • Updated README with clearer feature descriptions, usage instructions, and a new section on enabling Next.js support.
    • Improved code examples and formatting for better clarity.
  • Chores

    • Added Next.js ESLint plugin as a dependency and updated workspace catalog.

@mheob mheob added enhancement 📈 New feature or request eslint 🚨 Belongs to ESLint config labels Jul 25, 2025
@height
Copy link
Copy Markdown

height Bot commented Jul 25, 2025

Link Height tasks by mentioning a task ID in the pull request title or commit messages, or description and comments with the keyword link (e.g. "Link T-123").

💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jul 25, 2025

🦋 Changeset detected

Latest commit: b53fb6b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@mheob/eslint-config Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented Jul 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
eslint-config ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 25, 2025 6:07am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 25, 2025

Walkthrough

This change introduces official Next.js support to the @mheob/eslint-config package. It adds a new Next.js configuration module, updates the config factory to support a nextjs option, extends type definitions and rules for Next.js, updates documentation, and ensures all relevant dependencies and catalog entries are present.

Changes

File(s) Change Summary
.changeset/two-badgers-serve.md Added a changeset documenting a minor version bump for Next.js config support.
pnpm-workspace.yaml Added @next/eslint-plugin-next to the catalog with version ^15.4.3.
packages/eslint-config/package.json,
src/cli/versions-map.generated.ts
Added @next/eslint-plugin-next as a devDependency, peerDependency, and peerDependenciesMeta; updated versionsMap with @next/eslint-plugin-next.
packages/eslint-config/README.md Updated documentation: clarified features, added Next.js usage instructions, updated code samples to TypeScript, revised plugin renaming table, and improved formatting and explanations.
packages/eslint-config/scripts/typegen.ts Imported and included the nextjs config in the type generation process.
packages/eslint-config/src/cli/constants.ts Reordered framework options, relabeled Astro and Vue, and added a dependency mapping for Next.js.
packages/eslint-config/src/configs/nextjs.ts Introduced a new ESLint config module for Next.js, providing recommended and core web vitals rules, dynamic plugin import, and rule normalization.
packages/eslint-config/src/configs/index.ts Exported the new nextjs config module from the central index.
packages/eslint-config/src/factory.ts Added support for a nextjs option in the config factory, included plugin renaming for Next.js, and conditionally added the Next.js config to the generated config array.
packages/eslint-config/src/typegen.d.ts Extended type definitions: added Next.js rule options, a type alias for a Next.js rule, and included Next.js config names in the ConfigNames union.
packages/eslint-config/src/types.ts Updated Rules and TypedFlatConfigItem types for more explicit typing, added a nextjs boolean or overrides option to OptionsConfig, and clarified documentation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant mheobConfigFactory
    participant NextjsConfigModule
    participant ESLint

    User->>mheobConfigFactory: Call mheob({ nextjs: true/overrides, ... })
    mheobConfigFactory->>NextjsConfigModule: Import and invoke nextjs(options)
    NextjsConfigModule->>NextjsConfigModule: Ensure @next/eslint-plugin-next is installed
    NextjsConfigModule->>NextjsConfigModule: Dynamically import plugin, build config array
    NextjsConfigModule-->>mheobConfigFactory: Return Next.js config items
    mheobConfigFactory->>ESLint: Provide aggregated config array (including Next.js)
    User->>ESLint: Run linting with generated config
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

Scope: all 2 workspace projects
Progress: resolved 0, reused 0, downloaded 1, added 0
Progress: resolved 53, reused 0, downloaded 53, added 0
/tmp/eslint/packages/eslint-config:
 ERR_PNPM_WORKSPACE_PKG_NOT_FOUND  In packages/eslint-config: "@mheob/tsconfig@workspace:*" is in the dependencies but no package named "@mheob/tsconfig" is present in the workspace

This error happened while installing a direct dependency of /tmp/eslint/packages/eslint-config

Packages found in the workspace:

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-nextjs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
.changeset/two-badgers-serve.md (1)

1-5: Consider expanding the changeset summary

The description "add nextjs config" is technically correct but very terse. A one-liner that briefly states what the new config does (e.g. “expose recommended & core-web-vitals rules via nextjs() option”) makes the changelog more helpful for consumers skimming releases.

packages/eslint-config/README.md (1)

392-392: Fix hard tab formatting issue.

Static analysis detected a hard tab character that should be replaced with spaces for consistency.

-	nextjs: true,
+  nextjs: true,
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf13a58 and b53fb6b.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • .changeset/two-badgers-serve.md (1 hunks)
  • packages/eslint-config/README.md (18 hunks)
  • packages/eslint-config/package.json (3 hunks)
  • packages/eslint-config/scripts/typegen.ts (2 hunks)
  • packages/eslint-config/src/cli/constants.ts (3 hunks)
  • packages/eslint-config/src/cli/versions-map.generated.ts (1 hunks)
  • packages/eslint-config/src/configs/index.ts (1 hunks)
  • packages/eslint-config/src/configs/nextjs.ts (1 hunks)
  • packages/eslint-config/src/factory.ts (3 hunks)
  • packages/eslint-config/src/typegen.d.ts (3 hunks)
  • packages/eslint-config/src/types.ts (2 hunks)
  • pnpm-workspace.yaml (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
packages/eslint-config/scripts/typegen.ts (1)
packages/eslint-config/src/configs/nextjs.ts (1)
  • nextjs (12-53)
packages/eslint-config/src/configs/nextjs.ts (3)
packages/eslint-config/src/types.ts (3)
  • OptionsFiles (35-38)
  • OptionsOverrides (65-67)
  • TypedFlatConfigItem (19-33)
packages/eslint-config/src/globs.ts (1)
  • GLOB_SRC (2-2)
packages/eslint-config/src/utils/package.ts (2)
  • ensurePackages (34-54)
  • interopDefault (16-22)
packages/eslint-config/src/factory.ts (1)
packages/eslint-config/src/configs/nextjs.ts (1)
  • nextjs (12-53)
packages/eslint-config/src/types.ts (1)
packages/eslint-config/src/typegen.d.ts (1)
  • RuleOptions (5-7314)
🪛 markdownlint-cli2 (0.17.2)
packages/eslint-config/README.md

392-392: Hard tabs
Column: 1

(MD010, no-hard-tabs)

🔇 Additional comments (21)
pnpm-workspace.yaml (1)

17-17: Verify single-source version management

@next/eslint-plugin-next now appears in the workspace catalog. Double-check that the same version range (^15.4.3) is declared in every place we manage this dependency (packages/eslint-config/package.json, versions-map.generated.ts, etc.) to avoid drift.

packages/eslint-config/scripts/typegen.ts (2)

14-15: Import looks correct — no issues found
The new nextjs import is placed alphabetically with the other config imports and matches the export path (../src).


46-47: Confirm combine() resolves async configs

nextjs() returns a Promise<TypedFlatConfigItem[]> (same as astro(), react(), etc.). Because you pass it directly into combine() and then await combine(...), the helper must internally await each element or accept promises. It already worked for the existing async configs, so this is likely fine, but if combine() ever changes to expect plain arrays this would silently break.

packages/eslint-config/src/cli/versions-map.generated.ts (1)

3-3: Map entry added – keep list alphabetised

Good catch adding @next/eslint-plugin-next. The list remains alphabetically sorted, so nothing further.

packages/eslint-config/src/configs/index.ts (1)

12-12: Export completes public surface

Exporting ./nextjs here exposes the new config through the package’s main entry – looks good.

packages/eslint-config/package.json (1)

82-82: LGTM! Dependency configuration follows established patterns.

The Next.js ESLint plugin is correctly added following the same pattern as other optional framework dependencies (React, Astro, Svelte) with catalog versioning in devDependencies, specific version constraint in peerDependencies, and marked as optional.

Also applies to: 102-102, 117-119

packages/eslint-config/src/cli/constants.ts (1)

81-81: LGTM! Next.js dependency mapping correctly added.

The nextjs entry in dependenciesMap correctly maps to the required @next/eslint-plugin-next package, following the established pattern for framework dependencies.

packages/eslint-config/src/configs/nextjs.ts (2)

5-10: LGTM! Helper function correctly normalizes rule formats.

The normalizeRules function properly handles the conversion of string rule values to arrays, ensuring consistent rule formatting across different ESLint rule configurations.


12-53: LGTM! Next.js configuration implementation follows established patterns.

The implementation correctly:

  • Uses ensurePackages to verify plugin availability
  • Follows the two-config pattern (setup + rules) consistent with other framework configs
  • Properly enables JSX parsing and applies recommended Next.js rules
  • Merges both recommended and core-web-vitals rule sets
  • Supports user overrides and React version detection
  • Uses appropriate TypeScript typing with OptionsFiles & OptionsOverrides
packages/eslint-config/src/factory.ts (3)

18-18: LGTM! Next.js config import properly added.

The import follows the established pattern for framework configurations.


59-59: LGTM! Plugin renaming entry correctly added.

The '@next/next': 'next' renaming entry provides consistent plugin prefix naming, following the same pattern as other framework plugins.


182-188: LGTM! Next.js config integration follows established patterns.

The conditional inclusion of the Next.js config correctly:

  • Uses the same pattern as other framework configs (React, Astro, Svelte)
  • Defaults to false requiring explicit enablement
  • Properly passes overrides using the getOverrides helper
  • Maintains consistency with the overall factory design
packages/eslint-config/README.md (3)

10-11: LGTM! Feature list correctly updated to include Next.js support.

The bullet point accurately reflects the new Next.js support alongside other framework options.


383-400: LGTM! Next.js documentation section follows established patterns.

The Next.js configuration section correctly:

  • Follows the same format as other framework sections (React, Svelte, Astro)
  • Provides accurate code examples using TypeScript extensions
  • Includes proper installation instructions for the required dependency
  • Uses consistent formatting and structure

250-250: LGTM! Plugin renaming table correctly updated.

The table entry accurately documents the next/* prefix renaming for the Next.js ESLint plugin, maintaining consistency with the established documentation format.

packages/eslint-config/src/types.ts (3)

12-12: LGTM! Well-designed type intersection for ESLint rules.

The combination of a flexible record type with strongly typed RuleOptions provides both type safety for known rules and flexibility for custom or future rules.


14-33: Excellent documentation and type safety improvements.

The comprehensive JSDoc comments and explicit property definitions enhance the developer experience while maintaining type safety. The approach of omitting and redefining properties from Linter.Config is a solid TypeScript pattern.


162-170: Perfect integration following established patterns.

The nextjs option implementation is consistent with other framework options in the codebase. The JSDoc documentation clearly specifies dependencies and the type allows both simple enablement and advanced configuration.

packages/eslint-config/src/typegen.d.ts (3)

1301-1404: LGTM! Comprehensive Next.js ESLint rule definitions.

The Next.js rule definitions are well-structured and complete. Each rule includes proper JSDoc documentation with descriptions and links to Next.js documentation. The type definitions correctly use Linter.RuleEntry<[]> for rules without options and NextNoHtmlLinkForPages for the rule that accepts configuration.


8919-8920: Correct type definition for Next.js rule options.

The NextNoHtmlLinkForPages type correctly defines the options for the next/no-html-link-for-pages rule, allowing either no configuration or a single parameter that can be a string or array of strings (representing page directory paths).


16161-16161: Config names follow established naming conventions.

The addition of 'mheob/nextjs/setup' and 'mheob/nextjs/rules' to the ConfigNames union type is consistent with the existing naming pattern and maintains alphabetical ordering.

@kodiakhq kodiakhq Bot merged commit 82adf3f into main Jul 25, 2025
9 checks passed
@kodiakhq kodiakhq Bot deleted the add-nextjs branch July 25, 2025 06:14
kodiakhq Bot pushed a commit that referenced this pull request Jul 25, 2025
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.


# Releases
## @mheob/eslint-config@8.12.0

### Minor Changes

-   [#286](#286) ([@mheob](https://github.com/mheob)): sorts `id` to the top of objects in JSON files

-   [#285](#285) ([@mheob](https://github.com/mheob)): add nextjs config

-   [#281](#281) ([@mheob](https://github.com/mheob)): update allowed exports for `react-router`

### Patch Changes

-   [#287](#287) ([@renovate](https://github.com/apps/renovate)): update all non-major deoendencies

## @mheob/commitlint-config@1.2.4

### Patch Changes

-   [#287](#287) ([@renovate](https://github.com/apps/renovate)): update all non-major deoendencies

## @mheob/prettier-config@3.3.4

### Patch Changes

-   [#287](#287) ([@renovate](https://github.com/apps/renovate)): update all non-major deoendencies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement 📈 New feature or request eslint 🚨 Belongs to ESLint config

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant