Microsoft/vscode

[json] option to format code with leading commas

Open

#24,869 建立於 2017年4月16日

在 GitHub 查看
 (14 留言) (22 反應) (1 負責人)TypeScript (74,848 star) (10,221 fork)batch import
feature-requestformattinghelp wantedjson

描述

Can we get an option in VS Code to have it format all lists by using leading commas instead of trailing commas?

This would so much simplify editing code and it would also greatly simplify the IDE's automatic code completion (e.g. the VS Code Settings editor).

With the suggested option set to true, comma separated lists would proposedly be formatted like this:

{ "workbench.iconTheme": "vs-seti"
, "editor.lineNumbers": "off"
, "editor.tabSize": 2
, "editor.insertSpaces": false
, "editor.autoClosingBrackets": false
}

Function calls using line wrapping for their arguments would look like this:

call( 1
    , "test"
    , new Console()
    );

a nested sample would look like this:

{ "version": "0.2.0"
, "configurations":
  [ { "type": "node"
    , "request": "launch"
    , "name": "Programm starten"
    , "program": "${file}"
    }
  , { "type": "node"
    , "request": "attach"
    , "name": "An den Port anfügen"
    , "address": "localhost"
    , "port": 5858
    }
  ]
}

Moreover, adding a new property to an object would be a snap:

Either copy/paste from an existing property (=> no more syntax errors due to redundant trailing commas, see screenshot below):

comma error

... or create a new property and you might immediately get IntelliSense right after typing the leading comma of the property to create.

The suggested formatting style is applicable to all languages

E.g. T-SQL:

CREATE TABLE
  ( id INT PRIMARY KEY IDENTITY
  , name NVARCHAR(100) NOT NULL UNIQUE CHECK(LEN(name) > 0)
  , created DATETIME NOT NULL DEFAULT(GETDATE())
  , updated DATETIME NOT NULL DEFAULT(GETDATE())
  )

貢獻者指南