VSCodeBeautify icon indicating copy to clipboard operation
VSCodeBeautify copied to clipboard

object in array,the first brace stays in new line

Open see311 opened this issue 6 years ago • 7 comments

  • Operating System (+Version): WIN10
  • VS Code Version: 1.24.0
  • beautify Version: 1.3.1 NOTE: Please provide code snippets instead of screen shots. Your issue needs to be replicated, and we need the failing code (text) to do this.

Provide the settings you use: (VS Code workspace and user settings, .jsbeautifyrc, .editorconfig) eg.: VS Code:

{
    "files.autoSave": "onFocusChange",
    "editor.snippetSuggestions": "top",
    "emmet.showSuggestionsAsSnippets": true,
    "vetur.format.defaultFormatter.html": "js-beautify-html",
    "html.format.wrapAttributes": "force-aligned",
    "vetur.format.defaultFormatterOptions": {
        "js-beautify-html": {
            "defaultHtmlOptions.wrapAttributes": "force-aligned"
        }
    },
    "emmet.includeLanguages": {
        "vue-html": "html",
        "nunjucks": "html"
    },
    "editor.tabSize": 2,
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
    "git.enableSmartCommit": true,
    "git.autofetch": true,
    "beautify.language": {
        "js": {
            "type": [
                "javascript",
                "json"
            ],
            "filename": [
                ".jshintrc",
                ".jsbeautify"
            ]
        },
        "css": [
            "css",
            "scss"
        ],
        "html": {
            "type": [
                "htm",
                "html",
                "nunjucks"
            ],
            "ext": [
                "nunjucks"
            ]
        }
    },
    "files.associations": {
        "*.html": "html"
    },
    "[javascript]": {},
    "emmet.showAbbreviationSuggestions": false,
    "workbench.iconTheme": "vscode-great-icons",
    "workbench.activityBar.visible": true,
    "[html]": {},
    "window.zoomLevel": 0,
    "search.location": "panel",
    "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": true,
    "javascript.format.placeOpenBraceOnNewLineForControlBlocks": true,
    "javascript.format.placeOpenBraceOnNewLineForFunctions": true,
    "html.suggest.angular1": false,
    "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,
}

Action performed

Format javascript file with HookyQR.beautifyFile command provide example code

routes: [{
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld,
    },
    {
      path: '/login',
      component: Login,
    }
]

Expected results

Expected ... to ... provide example (expected) output

routes: [
  {
    path: '/',
    name: 'HelloWorld',
    component: HelloWorld,
  },
  {
    path: '/login',
    component: Login,
  }
]

Actual results

Details of what happened ... provide example (actual) output

see311 avatar Jun 12 '18 06:06 see311

You can use either "brace_style": "none,preserve-inline" or "brace_style": "expand,preserve-inline" to get that result, but it will obviously affect other parts of your code.

HookyQR avatar Jun 12 '18 06:06 HookyQR

@HookyQR after I use "brace_style": "none,preserve-inline" or "brace_style": "expand,preserve-inline", it change to:

routes: [
{
  path: '/',
  name: 'HelloWorld',
  component: HelloWorld
},
{
  path: '/',
  name: 'HelloWorld',
  component: HelloWorld
}]

there is no indent before the brace and the last brace get together

see311 avatar Jun 14 '18 02:06 see311

That's because the code itself is invalid. It should have either routes = or the whole thing should be surrounded by a curly brace pair. The parser simply thinks it's still at the top level at that point, cos, it kind of is. ;)

HookyQR avatar Jun 14 '18 02:06 HookyQR

@HookyQR sorry, my fault. the routes is in the object, it's a property of an object. likes:

{
  routes: [
  {
    path: '/',
    name: 'HelloWorld',
    component: HelloWorld
  },
  {
    path: '/',
    name: 'HelloWorld',
    component: HelloWorld
  }]
}

see311 avatar Jun 15 '18 03:06 see311

I still don't see what the problem is. Can you please provide snippets for before, actual after, and expected after.

HookyQR avatar Oct 17 '18 07:10 HookyQR

I think the expected after is :

{
   routes: [
      {
        path: '/',
        name: 'HelloWorld',
        component: HelloWorld
      },
      {
        path: '/',
        name: 'HelloWorld',
        component: HelloWorld
      }
   ]
}

(and I support that too)

Gazzia avatar Jan 11 '19 16:01 Gazzia

The last curly and square brace keep stacking on one line: }]

The opening brackets are fine but the ending arent following the same.

gregg-cbs avatar Oct 31 '22 15:10 gregg-cbs