Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for key spacing alignment #835

Closed
zaydek opened this issue Apr 4, 2024 · 2 comments
Closed

Support for key spacing alignment #835

zaydek opened this issue Apr 4, 2024 · 2 comments

Comments

@zaydek
Copy link

zaydek commented Apr 4, 2024

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.

@chungleee
Copy link

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

@zaydek
Copy link
Author

zaydek commented May 24, 2024

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.

@zaydek zaydek closed this as completed May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants