Everlaw / nbts

NetBeans TypeScript editor plugin
283 stars 46 forks source link

Question: formatting options #74

Closed RomkeVdMeulen closed 7 years ago

RomkeVdMeulen commented 8 years ago

I'm on Netbeans 8.1. If I have my TypeScript code auto-formatted, this

import {myFunction} from "./my-function";

always gets turned into

import { myFunction } from "./my-function";

I'd like to disable this, but when I look at Formatting in the Netbeans options, there's no TypeScript option in the Language dropdown, and no option in the JavaScript formatting option that controls this behaviour. Is there any other way I can disable this behaviour?

RomkeVdMeulen commented 7 years ago

On a related note: I'd like to prevent <string> myVal from being formatted as <string>myVal.

jeffrey-easyesi commented 7 years ago

In 2.1.4.1, the formatter now tries to honor the JS formatting preferences (and the Java setting for space after type cast, since JS doesn't have anything similar). I'm thinking it might be best to create a new formatting preference dialog for TypeScript though, since JS's don't correspond well to the formatting options that the TS language service provides.

RomkeVdMeulen commented 7 years ago

I agree. If you go by the recommended code style, casts would be (MyType) var in Java and <MyType>var in TypeScript (at least that's what's consistently used in the TypeScript handbook), so having one setting for both might be problematic.

Nice! I've upgraded to 2.1.4.1 and the above two points were indeed solved. Unfortunately, behaviour has changed elsewhere as well: now when I defined an object type inline, no spaces are placed within the braces. In this place, unlike with imports, I did prefer having the spaces there: not myFunc(data: {id: number}) but myFunc(data: { id: number }). This is only a minor nuisance, but if you ever do consider adding TypeScript specific formatting options, you might consider separating these two uses of curly braces (and possible people might have a different preference again when creating an object literal).

Thank you for your work on this excellent plugin.

Chris2011 commented 7 years ago

Should we create a new ticket which will say: Add TypeScript formatting options to the option -> Editor -> Formatting dialog?

Chris2011 commented 7 years ago

I created one: https://github.com/Everlaw/nbts/issues/81