vercel / next.js

The React Framework
https://nextjs.org
MIT License
121.29k stars 25.96k forks source link

lint TP1006 #65280

Open artola opened 2 weeks ago

artola commented 2 weeks ago

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/goofy-ritchie-39dq82

To Reproduce

  1. start the app (next dev --turbo) or yarn dev (already modified for turbo).
  2. the app contains 2 links for 2 routes, click to navigate:
    • /foo = the console has NO ERROR printed
      
      import { NextResponse, type NextRequest } from "next/server";
      import path from "node:path";

export async function GET() { const p = path.resolve("./foo.txt");

return new NextResponse("NO ERROR :)"); }


  - /bar = the console has ERROR printed
```typescript
import { NextResponse, type NextRequest } from "next/server";
import path from "node:path";

function getPath(target: string) {
  return path.resolve(target);
}

export async function GET() {
  const p = getPath("./foo.txt");

  return new NextResponse("ERROR :(");
}

Note: Even if the function getPath is defined within the GET still the linter show errors:

 ✓ Compiled /bar in 156ms
 ⚠ ./app/bar/route.ts:5:10
lint TP1006 path.resolve(???*0*) is very dynamic
  3 |
  4 | function getPath(target: string) {
> 5 |   return path.resolve(target);
    |          ^^^^^^^^^^^^^^^^^^^^
  6 | }
  7 |
  8 | export async function GET() {

- *0* arguments[0]
  ⚠️  function calls are not analysed yet

 GET /bar 200 in 205ms
 ⚠ ./app/bar/route.ts:5:10
lint TP1006 path.resolve(???*0*) is very dynamic
  3 |
  4 | function getPath(target: string) {
> 5 |   return path.resolve(target);
    |          ^^^^^^^^^^^^^^^^^^^^
  6 | }
  7 |
  8 | export async function GET() {

- *0* arguments[0]
  ⚠️  function calls are not analysed yet

 GET /bar 200 in 27ms

Current vs. Expected behavior

Linter should understand these calls, otherwise I should know what to do :)

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 14.3.0-canary.36 // Latest available version is detected (14.3.0-canary.36).
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A
Done in 1.76s.

Which area(s) are affected? (Select all that apply)

Turbopack

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

Same behavior in latest as in canary 36.

PACK-3045

artola commented 2 days ago

Still happening with 14.3.0-canary.63 (turbo)

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!