oxc-project / oxc

⚓ A collection of JavaScript tools written in Rust.
https://oxc.rs
MIT License
10.91k stars 400 forks source link

`-D pedantic` throws `File is too long to fit on the screen` (even if `max-lines` is disabled) #4322

Closed BracketJohn closed 1 month ago

BracketJohn commented 2 months ago

Description

We are on oxlint@0.6.0. With the following .oxlintrc.json:

{
  "env": {
    "browser": true
  },
  "rules": {
    "max-lines": "off"
  }
}

And the following oxlint invocation:

> pnpm oxlint -c .oxlintrc.json --deny-warnings -D correctness -D perf -D suspicious -D pedantic
  ! File is too long to fit on the screen
  help: "server/trpc/routers/userTask/index.ts" seems like a minified file

Finished in 50ms on 766 files with 158 rules using 10 threads.
Found 0 warnings and 1 error.

The following invocation succeeds (note how I dropped -D pedantic):

pnpm oxlint -c .oxlintrc.json --deny-warnings -D correctness -D perf -D suspicious
Finished in 40ms on 766 files with 101 rules using 10 threads.
Found 0 warnings and 0 errors.

server/trpc/routers/userTask/index.ts is not a minified file. It's a tRPC router file with 556 LoC.

Expected behavior

Given the same .oxlintrc.json the invocation including -D pedantic returns:

> pnpm oxlint -c .oxlintrc.json --deny-warnings -D correctness -D perf -D suspicious -D pedantic

Finished in 50ms on 766 files with 158 rules using 10 threads.
Found 0 warnings and 0 errors.
Boshen commented 2 months ago

For context, it throws this if column number exceeds 400.

https://github.com/oxc-project/oxc/blob/3df9e697ccf1944359edf3b94fe569eb5a00b364/crates/oxc_diagnostics/src/service.rs#L154-L159

Boshen commented 2 months ago

An improvement should be print out the error message but don't print the code frame.

BracketJohn commented 2 months ago

Just to add / clarify, as I'm unsure whether the change you proposed would address it: The invocation currently also fails with a non-zero status code, blocking CI from passing. This to me feels undesired. I lack experience to say whether this is actually undesired or correct.

BracketJohn commented 2 months ago

Further info: I identified the line that is causing the error. It's the input-parameter line of this function-signature. It does not seem to exceed 400 column numbers (width as displayed by editor: 201):

export const getTasks = async (
  user: { email: string, role: UserRole },
  prisma: ExtendedPrismaClient,
  input: z.infer<typeof getTasksInputSchema> = { assignedToUsers: { in: [] }, assignedToRole: { in: [] }, isRelatedToOffer: 'is-related-or-unrelated', relatedOfferId: [], createdByEmail: { in: [] } },
) => {

}

Breaking this line as follows stops the File is too long to fit on the screen-error from being thrown:

export const getTasks = async (
  user: { email: string, role: UserRole },
  prisma: ExtendedPrismaClient,
  input: z.infer<typeof getTasksInputSchema> =
  { assignedToUsers:
      { in: [] }, assignedToRole: { in: [] }, isRelatedToOffer: 'is-related-or-unrelated', relatedOfferId: [], createdByEmail: { in: [] } },
) => {

}

And instead reveals the "true" error:

> oxlint -c .oxlintrc.json --deny-warnings -D correctness -D perf -D suspicious -D pedantic && eslint --max-warnings 0 .

  × eslint-plugin-unicorn(no-object-as-default-parameter): Do not use an object literal as default for parameter `input`.
    ╭─[server/trpc/routers/userTask/index.ts:33:3]
 32 │       input: z.infer<typeof getTasksInputSchema> =
 33 │ ╭─▶   { assignedToUsers:
 34 │ ╰─▶       { in: [] }, assignedToRole: { in: [] }, isRelatedToOffer: 'is-related-or-unrelated', relatedOfferId: [], createdByEmail: { in: [] } },
 35 │     ) => {
    ╰────
Boshen commented 1 month ago

Made some improvements in https://github.com/oxc-project/oxc/pull/5120