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

Skip single characters was not printed. Please report this error! #15007

Closed
ahsanrana opened this issue Jul 3, 2023 · 4 comments · Fixed by #15076
Closed

Skip single characters was not printed. Please report this error! #15007

ahsanrana opened this issue Jul 3, 2023 · 4 comments · Fixed by #15076
Assignees
Labels
area:comments Issues with how Prettier prints comments lang:javascript Issues affecting JS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program

Comments

@ahsanrana
Copy link

when ever i try to format my js file , it gives me this error
["ERROR" - 10:30:02 PM] Error formatting document.
["ERROR" - 10:30:02 PM] Comment "Skip single characters" was not printed. Please report this error!

@kachkaev
Copy link
Member

kachkaev commented Jul 3, 2023

Please use the issue template to help us reproduce the bug. What source code was producing the error?

@kachkaev kachkaev added the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Jul 3, 2023
@ns-vpanfilov
Copy link

@kachkaev, I also have the same issue in typescript file after I updated to prettier 3.0.0 from 2.8.8

const a = {
  project: "SchemaCheck.String()",

  ns_dcs: [
    "SchemaCheck.StringArray()",
    (props:any) => {
      const val = props.value as string[]
      if (val.length == 2) return undefined // return success
      else return { message: 'array must include 2 items' }
    },
  ],  
}

output in vscode:

["INFO" - 1:30:39 PM] Formatting file:///home/op/packages/base-lib/src/coreTypes/messageTypes/ezDemoGre.ts
["INFO" - 1:30:39 PM] Using config file at '/home/op/packages/base-lib/.prettierrc.js'
["INFO" - 1:30:39 PM] PrettierInstance:
{
  "modulePath": "/home/op/node_modules/prettier/index.cjs",
  "importResolver": {},
  "callMethodResolvers": {},
  "currentCallMethodId": 79,
  "version": "3.0.0"
}
["INFO" - 1:30:39 PM] Using ignore file (if present) at /home/op/packages/base-lib/.prettierignore
["INFO" - 1:30:39 PM] File Info:
{
  "ignored": false,
  "inferredParser": "typescript"
}
["INFO" - 1:30:39 PM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 1:30:39 PM] Prettier Options:
{
  "filepath": "/home/op/packages/base-lib/src/coreTypes/messageTypes/ezDemoGre.ts",
  "parser": "typescript",
  "arrowParens": "always",
  "bracketSpacing": true,
  "bracketSameLine": false,
  "jsxSingleQuote": true,
  "printWidth": 100,
  "quoteProps": "consistent",
  "rangeStart": 0,
  "rangeEnd": null,
  "semi": false,
  "singleQuote": true,
  "tabWidth": 2,
  "trailingComma": "es5",
  "useTabs": false,
  "endOfLine": "lf"
}
["ERROR" - 1:30:39 PM] Error formatting document.
["ERROR" - 1:30:39 PM] Comment "return success" was not printed. Please report this error!
Error: Comment "return success" was not printed. Please report this error!
    at ensureAllCommentsPrinted (file:///home/op/node_modules/prettier/index.mjs:17941:13)
    at printAstToDoc (file:///home/op/node_modules/prettier/index.mjs:18102:3)
    at async coreFormat (file:///home/op/node_modules/prettier/index.mjs:18405:14)
    at async formatWithCursor (file:///home/op/node_modules/prettier/index.mjs:18603:14)
    at async Module.format2 (file:///home/op/node_modules/prettier/index.mjs:21789:25)
["INFO" - 1:30:39 PM] Formatting completed in 13ms.

@MatanelGordon
Copy link
Contributor

MatanelGordon commented Jul 10, 2023

Ok I think I got the problem.

playground link

The Code in Question:

const a = {
  project: "SchemaCheck.String()",

  ns_dcs: [
    "SchemaCheck.StringArray()",
    (props:any) => {
      const val = props.value as string[]
      if (val.length == 2) return undefined // return success
      else return { message: 'array must include 2 items' }
    },
  ],  
}

Result

So by formatting the former coed using prettier playground, I received the following error:

Error: Comment "return success" was not printed. Please report this error!
    at pu (https://prettier.io/lib/standalone.js:27:5829)
    at Ze (https://prettier.io/lib/standalone.js:27:7320)
    at async Ou (https://prettier.io/lib/standalone.js:27:11026)
    at async Rr (https://prettier.io/lib/standalone.js:32:581)
    at async formatCode (https://prettier.io/worker.js:170:12)
    at async handleFormatMessage (https://prettier.io/worker.js:82:24)
    at async self.onmessage (https://prettier.io/worker.js:37:14)

This error specifically refers to the one-line comment "return success" being adjacent to a real return statement.

Solution: Curly brackets

by adding curly brackets to the if-statement I was able to successfully run prettier

The Code

const f = (props:any) => {
  const val = props.value as string[]
  if (val.length == 2){
        return undefined // return success
  }
  else return { message: 'array must include 2 items' }
}

The Reason - trying to prettify the comment as code because of "return ..."

I think Prettier thinks the comment is a code incorrectly. Might be a bug in the breakdown to AST of single-line comments in single-line If-statements.

Edit: @kachkaev That should give you more than enough info to take it from here 😄

@fisker fisker self-assigned this Jul 11, 2023
@fisker fisker added type:bug Issues identifying ugly output, or a defect in the program area:comments Issues with how Prettier prints comments lang:javascript Issues affecting JS and removed status:awaiting response Issues that require answers to questions from maintainers before action can be taken labels Jul 11, 2023
@christiango
Copy link

I'm also seeing this and sharing my source code in case it helps :). This code results in a Error: Comment "Already locked from a previous run, so return early." was not printed. Please report this error!

    if (dataStorePageViewsInitLocked) return; // Already locked from a previous run, so return early.

@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Nov 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:comments Issues with how Prettier prints comments lang:javascript Issues affecting JS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants