vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Rules settings for the format code command

Open Nimzozo opened this issue 10 years ago • 8 comments

It would be great to be able to define rules for the format code command. Personnally, I would need to change the default indentation level for specific code lines (wrapped lines) and to disable the command for the comments. (They are indented when I wouldn't like to)

Also, this improvement can be used in different languages not in the same way, I recognize it could take time to make it available.

Nimzozo avatar Feb 16 '16 01:02 Nimzozo

For which language would you like these settings?

egamma avatar Feb 16 '16 07:02 egamma

Currently JavaScript.

Nimzozo avatar Feb 16 '16 14:02 Nimzozo

The formatting support provided TypeScript supports settings which we currently do not expose to the user.

egamma avatar Feb 21 '16 12:02 egamma

This would be very helpful. We have rules defined in .eslintrc.json that conflict with the MS-dictated formatting rules applied when using the format code command, so every time we use the command we have to fix formatting elsewhere in the file.

One example is we prefer spaces before and after the star in generator functions, whereas the format code command removes the space before the star.

It would be nice if there was an option to use one of the available linting plugins (jshint, eslint, etc) and hook into their rules, but even being able to statically define our own ruleset per-project would be okay.

jdforsythe avatar Aug 03 '16 17:08 jdforsythe

As a JSLint user, I was precisely looking for a "double-indent" possibility for the setting "editor.wrappingIndent".

Nimzozo avatar Feb 20 '17 12:02 Nimzozo

Is it possible? For example, now TS auto formatter does:

import { something } from 'something'

Is it possible to make it not add spaces between curly braces and text here:

import {something} from 'something'

?

wclr avatar Mar 23 '17 19:03 wclr

I am looking for same feature as @whitecolor when auto formatting my JavaScript code. Actually our whole team has to fix lint errors after auto formatting code. This is annoying and reduces productivity because cleaning up the code after auto format feels nightmarish.

KettuJKL avatar Apr 13 '17 04:04 KettuJKL

For the original issue:

TypeScript / JavaScript formatting options are exposed in settings (see javascript.format.* and typescript.format.*). Our built-in extension don't provide a way to do control these on a per-block or per-file basis. For more advanced formatting control like that, try using one of the dedicated formatting tools form the marketplace


@jdforsythe

#17627 tracks picking up TS formatter settings from other tools. Again though, you probably just want to install the eslint/jshint extensions and disable the built-in js/ts formatter.


@whitecolor

That is controlled by the settings:

"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces"
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces"

Closing as out of scope for the original feature request for per-block or per-line formatting options

mjbvz avatar Dec 19 '17 23:12 mjbvz