beautifier / js-beautify

Beautifier for javascript
https://beautifier.io
MIT License
8.58k stars 1.37k forks source link

No way to format brace on separate line and indented #1789

Open rowild opened 4 years ago

rowild commented 4 years ago

Description

This is the default template for bug reports

NOTE:

  • Do not include screenshots! This library is a text processor, we need text inputs and outputs for debugging and fixing issues.
  • Check the list of open issues before filing a new issue.

Input

The code looked like this before beautification (from a standard vue-cli create (v4.3.1) project setup with router and vuex using eslint:recommended as linting config option):

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    component: () => import( /* webpackChunkName: "about" */ '../views/About.vue')
  }
]

Expected Output

(like the above code sample, which comes preformatted from vue-cli)

Actual Output

The code actually looked like this after beautification (the curly brace is put next to the bracket, now eslint complains that the line following the curly brace has 4 spaces, expected: 2):

const routes = [{
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    component: () => import( /* webpackChunkName: "about" */ '../views/About.vue')
  }
]

Steps to Reproduce

  1. In case you re-created the vue-cli project, openrouter/index.js in VScode
  2. just hit CMD+K CMD+F

Environment

OS: MacOS 10.13.6 NodeJS: 12.16.1

Settings

Using a .jsbeautifyrc:

{
    "indent_size": 2,
    "indent_char": " ",
    "indent_level": 0,
    "indent_with_tabs": false,
    "preserve_newlines": true,
    "max_preserve_newlines": 3,
    "jslint_happy": false,
    "space_after_anon_function": false,
    "brace_style": "expand,preserve-inline",  <== no matter, which configuration
    "keep_array_indentation": false,
    "keep_function_indentation": false,
    "space_before_conditional": true,
    "break_chained_methods": false,
    "eval_code": false,
    "unescape_strings": false,
    "wrap_line_length": 0
}

My suspicion is that there is no formatting option that allows to put the curly brace on the next line and keep it indented! (It is possible to tell beautify to put the brace on the next line, but without indentation! And the current behaviour puts either the beginning or the closing bracket/braces-couple on one line...)

swirle13 commented 1 year ago

Any update on this? Currently running into this when creating a team-specific formatter for json objects. We prefer the indented curly braces inside of a list in python. @bitwiseman

bitwiseman commented 1 year ago

@mjohnson159 PRs welcome.