Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Only add quotes around object properties where needed #2405

Closed
Tracked by #2403
MichaReiser opened this issue Apr 13, 2022 · 0 comments · Fixed by #2536
Closed
Tracked by #2403

Only add quotes around object properties where needed #2405

MichaReiser opened this issue Apr 13, 2022 · 0 comments · Fixed by #2536
Assignees
Labels
A-Formatter Area: formatter I-Normal Implementation: normal understanding of the tool and awareness

Comments

@MichaReiser
Copy link
Contributor

MichaReiser commented Apr 13, 2022

Description

It isn't necessary to put object properties in quotes (string literal name) if they form a valid identifier.

Input

type X = {
  "a": string;
  b: number;
};

interface X {
  "member": string;
}

class Y {
  "other" = 4;
  "method"() {}
  get "getter"() {}
  set "setterr"(value) {}
  "constructor"() {}
}

let value = { "a": "test", "quotes-required": "test" };

({ "a": test } = value);

let { "a": test } = value;

Prettier

type X = {
	a: string;
	b: number;
};

interface X {
	member: string;
}

class Y {
	"other" = 4;
	method() {}
	get getter() {}
	set setterr(value) {}
	constructor() {}
}

let value = { a: "test", "quotes-required": "test" };

({ a: test } = value);

let { a: test } = value;

Rome

type X = { "a": string, b: number };

interface X { "member": string }

class Y {
	"other" = 4;
	"method"() {}
	get "getter"() {}
	set "setterr"(value) {}
	"constructor"() {}
}

let value = { "a": "test", "quotes-required": "test" };

({ "a": test } = value);

let { "a": test } = value;

Expected

Rome formatter to match Prettier's output

Note

Don't remove quotes from numeric properties in TypeScript because that can result in type checker errors (prettier doesn't remove the quotes as well).

Playground

@MichaReiser MichaReiser added the A-Formatter Area: formatter label Apr 13, 2022
@ematipico ematipico self-assigned this Apr 27, 2022
@ematipico ematipico added the I-Normal Implementation: normal understanding of the tool and awareness label May 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Formatter Area: formatter I-Normal Implementation: normal understanding of the tool and awareness
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants