oxc icon indicating copy to clipboard operation
oxc copied to clipboard

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

Open BracketJohn opened this issue 1 year ago • 4 comments

Description

We are on [email protected]. 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.

BracketJohn avatar Jul 17 '24 10:07 BracketJohn

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 avatar Jul 17 '24 10:07 Boshen

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

Boshen avatar Jul 17 '24 10:07 Boshen

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 avatar Jul 17 '24 12:07 BracketJohn

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 │     ) => {
    ╰────

BracketJohn avatar Jul 17 '24 12:07 BracketJohn

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

Boshen avatar Aug 23 '24 11:08 Boshen