Microsoft/vscode

[json] option to format code with leading commas

Open

#24 869 ouverte le 16 avr. 2017

Voir sur GitHub
 (14 commentaires) (22 réactions) (1 assigné)TypeScript (10 221 forks)batch import
feature-requestformattinghelp wantedjson

Métriques du dépôt

Stars
 (74 848 stars)
Métriques de merge PR
 (Merge moyen 11h 43m) (1 000 PRs mergées en 30 j)

Description

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())
  )

Guide contributeur