dprint / dprint

Pluggable and configurable code formatting platform written in Rust.

Home Page:https://dprint.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for key spacing alignment

zaydek opened this issue · comments

I'm primarily a Go developer and I love how gofmt aligns values, making it very easy to scan lines of code.

Without this, code reads as:

export type DropdownsContextType = {
	showSettings: boolean;
	setShowSettings: React.Dispatch<React.SetStateAction<boolean>>;
	showVariants: boolean;
	setShowVariants: React.Dispatch<React.SetStateAction<boolean>>;
	showCategories: boolean;
	setShowCategories: React.Dispatch<React.SetStateAction<boolean>>;
	showActions: boolean;
	setShowActions: React.Dispatch<React.SetStateAction<boolean>>;
	closeDropdowns: (dropdown?: DropdownType) => void;
};

With this, code reads as:

export type DropdownsContextType = {
	showSettings:      boolean;
	setShowSettings:   React.Dispatch<React.SetStateAction<boolean>>;
	showVariants:      boolean;
	setShowVariants:   React.Dispatch<React.SetStateAction<boolean>>;
	showCategories:    boolean;
	setShowCategories: React.Dispatch<React.SetStateAction<boolean>>;
	showActions:       boolean;
	setShowActions:    React.Dispatch<React.SetStateAction<boolean>>;
	closeDropdowns:    (dropdown?: DropdownType) => void;
};

I find the difference is night and day. Only typescript-eslint supports this https://typescript-eslint.io/rules/key-spacing/ but it's such a pain to configure eslint to work half as good as dprint, I'd love if this were a standard feature of dprint or in the least a plugin. Does anyone know how this would be implemented and can point me in the right direction or have interest in taking this on? My use case is only TS, JSON but I don't see why it couldn't be an optional dprint feature as well.

commented

Have you found any solution? I tried setting up Eslint Stylistic just for that as well but can't get it working so I gave up lol

Have you found any solution? I tried setting up Eslint Stylistic just for that as well but can't get it working so I gave up lol

Sorry for the late reply. Yes it is possible with Stylistic, I don't have a configuration handy, but I ended up just changing where I put comments and so on to make it easier for me to reason about code. For example, in Go, the convention with structs it you put comments to the right of the fields if your comments are short. With TypeScript, I just interleave comments and I find it's perfectly readable. So I'm just using prettier now. I like dprint but it's slightly less readable imo than prettier because of some nuances around &&, || and &. To each their own.