You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using "Format Selection" tool to format only part of a document in VS Code with this plugin enabled, it will often fail with a syntax error of "SyntaxError: 'return' outside of function." or similar.
To Reproduce
In a project that has this Prettier plugin configured, add a file with these contents (misformatting and all):
exportfunctionsomething(){if(true)return/* space intentional */5}
In VS Code with the Prettier plugin, select the interior of the function between curly brackets, and press Cmd/Ctrl-Shift-P to open the command palette and run the "Format Selection" command. Then check the Prettier output in the Output pane for the error.
Expected behavior
The code should be formatted, same as if this plugin was not installed at all.
// prettier.config.jsmodule.exports={singleQuote: true,semi: true,plugins: [// I commented out the other plugin for this test// 'prettier-plugin-tailwindcss','@trivago/prettier-plugin-sort-imports',],// `tailwindFunctions` has to do with the commented-out plugintailwindFunctions: ['clsx','cn','cva'],importOrder: [// framework-level packages'^vitest(/.*)?$','^@testing-library(/.*)?$','^(react|next)(/.*)?$','<THIRD_PARTY_MODULES>','^@/.*',// Absolute imports from the current project'^[./]',// Relative imports],};
Error log
["ERROR" - 9:34:30 AM] Error formatting document.
SyntaxError: 'return' outside of function. (10:2)
at constructor (/Users/dallonf/devroot/biggie/node_modules/.pnpm/@[email protected]/node_modules/@babel/parser/lib/index.js:356:19)
at TypeScriptParserMixin.raise (/Users/dallonf/devroot/biggie/node_modules/.pnpm/@[email protected]/node_modules/@babel/parser/lib/index.js:3223:19)
at TypeScriptParserMixin.parseReturnStatement (/Users/dallonf/devroot/biggie/node_modules/.pnpm/@[email protected]/node_modules/@babel/parser/lib/index.js:13000:12)
at TypeScriptParserMixin.parseStatementContent (/Users/dallonf/devroot/biggie/node_modules/.pnpm/@[email protected]/node_modules/@babel/parser/lib/index.js:12626:21)
at TypeScriptParserMixin.parseStatementContent (/Users/dallonf/devroot/biggie/node_modules/.pnpm/@[email protected]/node_modules/@babel/parser/lib/index.js:9345:18)
at TypeScriptParserMixin.parseStatementLike (/Users/dallonf/devroot/biggie/node_modules/.pnpm/@[email protected]/node_modules/@babel/parser/lib/index.js:12593:17)
at TypeScriptParserMixin.parseStatementOrSloppyAnnexBFunctionDeclaration (/Users/dallonf/devroot/biggie/node_modules/.pnpm/@[email protected]/node_modules/@babel/parser/lib/index.js:12583:17)
at TypeScriptParserMixin.parseIfStatement (/Users/dallonf/devroot/biggie/node_modules/.pnpm/@[email protected]/node_modules/@babel/parser/lib/index.js:12994:28)
at TypeScriptParserMixin.parseStatementContent (/Users/dallonf/devroot/biggie/node_modules/.pnpm/@[email protected]/node_modules/@babel/parser/lib/index.js:12624:21)
at TypeScriptParserMixin.parseStatementContent (/Users/dallonf/devroot/biggie/node_modules/.pnpm/@[email protected]/node_modules/@babel/parser/lib/index.js:9345:18)
Contribute to @trivago/prettier-plugin-sort-imports
I'm willing to fix this bug 🥇
The text was updated successfully, but these errors were encountered:
Your Environment
Describe the bug
When using "Format Selection" tool to format only part of a document in VS Code with this plugin enabled, it will often fail with a syntax error of "SyntaxError: 'return' outside of function." or similar.
To Reproduce
In a project that has this Prettier plugin configured, add a file with these contents (misformatting and all):
In VS Code with the Prettier plugin, select the interior of the function between curly brackets, and press Cmd/Ctrl-Shift-P to open the command palette and run the "Format Selection" command. Then check the Prettier output in the Output pane for the error.
Expected behavior
The code should be formatted, same as if this plugin was not installed at all.
Screenshots, code sample, etc
Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)
Error log
Contribute to @trivago/prettier-plugin-sort-imports
The text was updated successfully, but these errors were encountered: