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

ESLint plugin #1036

Open
amannn opened this issue May 1, 2024 · 2 comments
Open

ESLint plugin #1036

amannn opened this issue May 1, 2024 · 2 comments
Labels
area: ergonomics enhancement New feature or request

Comments

@amannn
Copy link
Owner

amannn commented May 1, 2024

This issue acts to collect ideas for an ESLint plugin that next-intl could provide to support developers.

Ensure navigation APIs from next-intl are used

✅ See #1082

Use async APIs in async components

Using hooks in async components should be flagged as an error. AFAIK the React ESLint plugin will do this, but we could offer an (autofixable) alternative.

Linting for unused translations

External tools support this, but we could consider supporting this if there's an ESLint plugin.

See also: #503

@amannn amannn added enhancement New feature or request unconfirmed Needs triage. area: ergonomics labels May 1, 2024
@amannn amannn removed the unconfirmed Needs triage. label May 9, 2024
@Gawdfrey
Copy link
Contributor

I think a lot of the power in the lint rules here are that they have a customisable message that allows the developer to point others to the correct location, unsure on how doable/ergonomic it is do that with a eslint package 🤔
But, I am currently using these rules:

  "rules": {
    "no-restricted-imports": [
      "error",
      {
        "name": "next/link",
        "message": "Please use @shared/navigation instead."
      },
      {
        "name": "next/navigation",
        "importNames": [
          "redirect",
          "permanentRedirect",
          "useRouter",
          "usePathname"
        ],
        "message": "Please use @shared/navigation instead."
      },
      {
        "name": "next/router",
        "message": "Please use @shared/navigation instead."
      }
    ]
  }

Just banning the usage of the function that are exported from next-intl and pointing to where I export them. The last rule is just to avoid usage of the old router.

I definitely think some of these should be documented somehow :)

@amannn
Copy link
Owner Author

amannn commented May 22, 2024

Oh that's a good idea with no-restricted-imports, even easier to manage!

Being able to provide a customizable message is certainly possible with ESLint, but you'd have to configure at least the rule yourself—just using a preset wouldn't be enough. I think as a first step, adding a page to the workflows section with the rules you're using would be a good idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ergonomics enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants