Common Next.js issues that could use integrated ESLint rules #27051
Comments
|
I would love to work on this @leerob. Can you please assign this to me? |
@Patil2099 Which one specifically would you like to work on first? |
@leerob I'll work on Just to confirm, are you looking to include these interfaces as well https://developer.mozilla.org/en-US/docs/Web/API#interfaces ? |
I'm not sure how you were planning on detecting API/promises, but if it is typescript based it can probably either defer to this existing rule or extend it somehow if necessary: |
Another one: throw an error if using fs or other node packages on the client side. |
We enforce to be kebab-case file name, no more case sensitive vs not issues. Worth reading a bit more here: https://github.com/straw-hat-team/adr/tree/master/adrs/3122196229 I think the problem begins by adopting things that cause more harm than good in the long run with little to no value IMO. I don't remember anymore how many times I had to fix CI by telling people to fix the casing situation and reminds them to use I would discourage the usage of camelCase or PascalCase and stick to kebab-case as NodeJS used to be until we diverged. :2cents: |
@yordis I'm not saying Next.js ESLint should have a preference on how you do casing – that's a bit to stylistic to determine at the framework level. I'm talking about when you import a file |
Oh like, check for those errors?! Sorry, I misunderstood |
Hello everyone! I'm Keen and I just joined Google's WebSDK (Aurora) team this week
Please let me know if you have any concerns, otherwise I'll get started! |
hi all! @leerob I would like to try to implement this rule: Just to clarify, the rule should not allow using |
This commit (partially) tackles item 3 in vercel#27051: > Forgetting to await an async function inside an API route, works fine > locally but does out of band work which will cause issues if there’s > multiple requests. The work here is focused on TypeScript for now because `typescript-eslint` already provides `no-floating-promises` rule that precisely targets this scenario. This requires adding a new dependency (`@typescript-eslint/eslint-plugin`) to `eslint-config-next`. Although it is a superfluous dependency for JavaScript projects, it's not a big deal since `eslint-config-next` already has a dependency on `@typescript-eslint/parser`.
This commit (partially) tackles item 3 in vercel#27051: > Forgetting to await an async function inside an API route, works fine > locally but does out of band work which will cause issues if there’s > multiple requests. The work here is focused on TypeScript for now because `typescript-eslint` already provides `no-floating-promises` rule that precisely targets this scenario. This requires adding a new dependency (`@typescript-eslint/eslint-plugin`) to `eslint-config-next`. Although it is a superfluous dependency for JavaScript projects, it's not a big deal since `eslint-config-next` already has a dependency on `@typescript-eslint/parser`.
what do you think about a rule which suggests adding a |
@stefanprobst Yeah, I think that makes sense - only if there are duplicate elements right? If there's a single |
the docs on this are a bit sparse, but if i understand correctly the point is that it's hard to know if somewhere else in the tree the same for example, if you have: // pages/_app.js
import Head from "next/head";
export default function App({ Component, pageProps }) {
return (
<>
<Head>
<meta property="og:title" content="My app" />
</Head>
<Component {...pageProps} />
</>
);
} and // pages/index.js
import Head from "next/head";
export default function HomePage() {
return (
<>
<Head>
<meta property="og:title" content="Home page" />
</Head>
<main>
<h1>Hello world</h1>
</main>
</>
);
} you will end up with both note: |
Thoughts on a rule that lints if Docs state:
The rule could be opted into as a warning and reminder to set proper I've got a working implementation of this rule in a custom ESLint plugin stored on a private repo but would happily put it up for review if you think it would be handy! |
Describe the feature you'd like to request
These are common issues developers run into with Next.js. Some are mentioned in the docs, but ideally you don't have to go check the docs.
Describe the solution you'd like
Instead, ESLint can provide compile-time feedback and suggestions.
Trying to call an API route from inside
getStaticProps
/getServerSideProps
leading to next build failing.Trying to use
getStaticProps
inside of_app.js
, assuming it works like the other pages, but it doesn't.Forgetting to await an async function inside an API route, works fine locally but does out of band work which will cause issues if there’s multiple requests.
Code Example
Using
document
or other browser APIs outside ofuseEffect
File name casing (e.g.
myFile.js
vsMyFile.js
). This could potentially be solved with linting if import statement diffs from the actual file path? Not sure.Describe alternatives you've considered
N/A
The text was updated successfully, but these errors were encountered: