Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Next] Enforce default import for Next.js file conventions #103

Open
mwskwong opened this issue Mar 5, 2024 · 4 comments
Open

[Next] Enforce default import for Next.js file conventions #103

mwskwong opened this issue Mar 5, 2024 · 4 comments
Labels
enhancement New feature or request eslint

Comments

@mwskwong
Copy link
Contributor

mwskwong commented Mar 5, 2024

There are a few file conventions in Next.js that must contain default export. Currently, using this style guide out of the box will cause an error in those files, because of the import/no-default-export rule. It is suggested to override those specific files to enforce default export. e.g.

// https://github.com/vercel/style-guide/blob/canary/eslint/next.js
module.exports = {
  extends: ["plugin:@next/next/recommended"],
  overrides: [
    {
      files: JAVASCRIPT_FILES,
      parserOptions: { babelOptions },
    },
    // added override
    {
      files: [
        "next.config.mjs",
        "app/**/page.tsx",
        "app/**/layout.tsx",
        "app/**/not-found.tsx",
        "app/**/*error.tsx",
        "app/apple-icon.tsx",
        "app/**/opengraph-image.tsx",
        "app/sitemap.ts",
        "app/robots.ts",
        // ...
      ],
      rules: {
        "import/no-default-export": "off",
        "import/prefer-default-export": ["error", { target: "any" }],
      },
    },
  ],
};
@mrmckeb mrmckeb added eslint enhancement New feature or request labels Mar 8, 2024
@mrmckeb
Copy link
Contributor

mrmckeb commented Mar 8, 2024

We've had feedback that this is frustrating, and we did open the conversation to support named exports in Next.js, but I think that was hard for them to prioritise.
vercel/next.js#35717

I'd be happy for you to create a PR for this if you'd like?

@mwskwong
Copy link
Contributor Author

mwskwong commented Mar 15, 2024

@mrmckeb Just wondering what's the direction Vercel is going regarding this? If there isn't a clear plan on changing things to like export const Page = ... yet, I'm happy to create a PR on updating the ESLint config.

@mrmckeb
Copy link
Contributor

mrmckeb commented Apr 9, 2024

There isn't that I'm aware of, sorry. It's something we've discussed before, but I don't think it's on the roadmap.

@mwskwong
Copy link
Contributor Author

There isn't that I'm aware of, sorry. It's something we've discussed before, but I don't think it's on the roadmap.

Since ESLint v9 is making use of flat config by default, I believe it may be beneficial to focus on that first before applying this change to avoid double effort.

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
Projects
None yet
Development

No branches or pull requests

2 participants