Skip to content

Commit 4d89297

Browse files
authored
Merge pull request #82 from gitKrystan/prettier-trailing-comma
2 parents 2c3217f + 7f676e0 commit 4d89297

13 files changed

Lines changed: 42 additions & 45 deletions

File tree

.prettierrc.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@ module.exports = {
22
plugins: ['prettier-plugin-jsdoc'],
33
singleQuote: true,
44
tsdoc: true,
5-
6-
// TODO: Remove this in the next PR
7-
trailingComma: 'es5',
85
};

src/parse.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const typescript = babelParsers['babel-ts'] as Parser<Node | undefined>;
4343

4444
const preprocess: Required<Parser<Node | undefined>>['preprocess'] = (
4545
text: string,
46-
options: Options
46+
options: Options,
4747
) => {
4848
let preprocessed: string;
4949
if (text.includes(TEMPLATE_TAG_PLACEHOLDER)) {
@@ -111,7 +111,7 @@ function makeEnter(options: Options): (path: NodePath) => void {
111111
hasRawGlimmerArrayExpression(node.tag)
112112
) {
113113
throw new SyntaxError(
114-
'Ember <template> tag used as tagged template expression.'
114+
'Ember <template> tag used as tagged template expression.',
115115
);
116116
} else if (
117117
isMemberExpression(node) &&
@@ -144,7 +144,7 @@ function makeExit(): (path: NodePath) => void {
144144

145145
function tagGlimmerExpression(
146146
node: RawGlimmerArrayExpression | RawGlimmerClassProperty,
147-
forceSemi: boolean
147+
forceSemi: boolean,
148148
): void {
149149
const extra: GlimmerExpressionExtra = {
150150
isGlimmerTemplate: true,
@@ -176,7 +176,7 @@ function desugarDefaultExportTemplates(preprocessed: string): string {
176176

177177
// (^|;)\s*(\()?\s*\[__GLIMMER_TEMPLATE
178178
const sugaredDefaultExport = new RegExp(
179-
`(^|;)\\s*(\\()?\\s*\\${placeholderOpen}`
179+
`(^|;)\\s*(\\()?\\s*\\${placeholderOpen}`,
180180
);
181181
const desugaredDefaultExport = `$1 export default $2${placeholderOpen}`;
182182

src/print/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const printer: Printer<Node | undefined> = {
3838
path: AstPath<Node | undefined>,
3939
options: Options,
4040
print: (path: AstPath<Node | undefined>) => doc.builders.Doc,
41-
args: unknown
41+
args: unknown,
4242
) {
4343
const { node } = path;
4444
const hasPrettierIgnore = checkPrettierIgnore(path);
@@ -99,28 +99,28 @@ export const printer: Printer<Node | undefined> = {
9999
const content = await printTemplateContent(
100100
node,
101101
textToDoc,
102-
embedOptions as Options
102+
embedOptions as Options,
103103
);
104104
return printTemplateLiteral(content);
105105
} else if (!wasPreprocessed && isGlimmerClassProperty(node)) {
106106
const content = await printTemplateContent(
107107
node.key.arguments[0],
108108
textToDoc,
109-
embedOptions as Options
109+
embedOptions as Options,
110110
);
111111
return printTemplateTag(
112112
content,
113-
node.extra.isDefaultTemplate ?? false
113+
node.extra.isDefaultTemplate ?? false,
114114
);
115115
} else if (!wasPreprocessed && isGlimmerArrayExpression(node)) {
116116
const content = await printTemplateContent(
117117
node.elements[0].arguments[0],
118118
textToDoc,
119-
embedOptions as Options
119+
embedOptions as Options,
120120
);
121121
return printTemplateTag(
122122
content,
123-
node.extra.isDefaultTemplate ?? false
123+
node.extra.isDefaultTemplate ?? false,
124124
);
125125
}
126126
} catch (error: unknown) {
@@ -163,7 +163,7 @@ function trimPrinted(printed: doc.builders.Doc[]): void {
163163

164164
function printRawText(
165165
{ node }: AstPath<Node | undefined>,
166-
options: Options
166+
options: Options,
167167
): string {
168168
if (!node) {
169169
return '';
@@ -195,7 +195,7 @@ function checkPrettierIgnore(path: AstPath<Node | undefined>): boolean {
195195

196196
function docMatchesString(
197197
doc: doc.builders.Doc | undefined,
198-
string: string
198+
string: string,
199199
): doc is string {
200200
return typeof doc === 'string' && doc.trim() === string;
201201
}

src/print/template.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export async function printTemplateContent(
2222
// Don't use our `Options` here even though technically they are available
2323
// because we don't want to accidentally pass them into `textToDoc`. We
2424
// should normalize them into standard Prettier options at this point.
25-
options: PrettierOptions
25+
options: PrettierOptions,
2626
) => Promise<doc.builders.Doc>,
27-
options: Options
27+
options: Options,
2828
): Promise<doc.builders.Doc> {
2929
const text = node.quasis.map((quasi) => quasi.value.raw).join(' ');
3030
return await textToDoc(text.trim(), {
@@ -45,7 +45,7 @@ export async function printTemplateContent(
4545
*/
4646
export function printTemplateTag(
4747
content: doc.builders.Doc,
48-
useHardline: boolean
48+
useHardline: boolean,
4949
): doc.builders.Doc {
5050
const line = useHardline ? hardline : softline;
5151
return group([
@@ -58,7 +58,7 @@ export function printTemplateTag(
5858

5959
/** Prints the given template content as a template literal. */
6060
export function printTemplateLiteral(
61-
content: doc.builders.Doc
61+
content: doc.builders.Doc,
6262
): doc.builders.Doc {
6363
return group(['`', content, '`']);
6464
}

src/types/glimmer.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface GlimmerTemplateExtra {
3131

3232
/** Type predicate */
3333
export function isGlimmerTemplateLiteral(
34-
node: Node | null | undefined
34+
node: Node | null | undefined,
3535
): node is GlimmerTemplateLiteral {
3636
return isTemplateLiteral(node) && node.extra?.['isGlimmerTemplate'] === true;
3737
}
@@ -47,7 +47,7 @@ export type GlimmerExpression = GlimmerArrayExpression | GlimmerClassProperty;
4747

4848
/** Type predicate */
4949
export function isGlimmerExpression(
50-
node: Node | null | undefined
50+
node: Node | null | undefined,
5151
): node is GlimmerExpression {
5252
return node?.extra?.['isGlimmerTemplate'] === true;
5353
}
@@ -58,7 +58,7 @@ export interface GlimmerArrayExpression extends RawGlimmerArrayExpression {
5858

5959
/** Type predicate */
6060
export function isGlimmerArrayExpression(
61-
node: Node | null | undefined
61+
node: Node | null | undefined,
6262
): node is GlimmerArrayExpression {
6363
return isArrayExpression(node) && isGlimmerExpression(node);
6464
}
@@ -69,7 +69,7 @@ export interface GlimmerClassProperty extends RawGlimmerClassProperty {
6969

7070
/** Type predicate */
7171
export function isGlimmerClassProperty(
72-
node: Node | null | undefined
72+
node: Node | null | undefined,
7373
): node is GlimmerClassProperty {
7474
return isClassProperty(node) && isGlimmerExpression(node);
7575
}
@@ -88,7 +88,7 @@ export interface GlimmerExportDefaultDeclaration
8888

8989
/** Type predicate */
9090
export function isGlimmerExportDefaultDeclaration(
91-
node: unknown
91+
node: unknown,
9292
): node is GlimmerExportDefaultDeclaration {
9393
return (
9494
isNode(node) &&
@@ -111,7 +111,7 @@ export interface GlimmerExportDefaultDeclarationTS
111111

112112
/** Type predicate */
113113
export function isGlimmerExportDefaultDeclarationTS(
114-
node: unknown
114+
node: unknown,
115115
): node is GlimmerExportDefaultDeclarationTS {
116116
return (
117117
isNode(node) &&
@@ -137,7 +137,7 @@ export interface GlimmerTSAsExpression
137137

138138
/** Type predicate */
139139
export function isGlimmerTSAsExpression(
140-
node: unknown
140+
node: unknown,
141141
): node is GlimmerTSAsExpression {
142142
return (
143143
isNode(node) &&
@@ -160,7 +160,7 @@ export interface GlimmerExpressionStatement
160160

161161
/** Type predicate */
162162
export function isGlimmerExpressionStatement(
163-
node: unknown
163+
node: unknown,
164164
): node is GlimmerExpressionStatement {
165165
return (
166166
isNode(node) &&
@@ -183,7 +183,7 @@ export interface GlimmerExpressionStatementTS
183183

184184
/** Type predicate */
185185
export function isGlimmerExpressionStatementTS(
186-
node: unknown
186+
node: unknown,
187187
): node is GlimmerExpressionStatementTS {
188188
return (
189189
isNode(node) &&
@@ -200,7 +200,7 @@ export function getGlimmerExpression(
200200
| GlimmerExpressionStatement
201201
| GlimmerExpressionStatementTS
202202
| GlimmerClassProperty
203-
| GlimmerArrayExpression
203+
| GlimmerArrayExpression,
204204
): GlimmerExpression {
205205
switch (node.type) {
206206
case 'ExportDefaultDeclaration': {

src/types/raw.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface RawGlimmerArrayExpression extends ArrayExpression {
2929

3030
/** Type predicate */
3131
export function isRawGlimmerArrayExpression(
32-
value: Node | null | undefined
32+
value: Node | null | undefined,
3333
): value is RawGlimmerArrayExpression {
3434
return (
3535
isArrayExpression(value) && isRawGlimmerCallExpression(value.elements[0])
@@ -74,7 +74,7 @@ export interface RawGlimmerClassProperty extends ClassProperty {
7474

7575
/** Type predicate */
7676
export function isRawGlimmerClassProperty(
77-
value: Node | null | undefined
77+
value: Node | null | undefined,
7878
): value is RawGlimmerClassProperty {
7979
return isClassProperty(value) && isRawGlimmerCallExpression(value.key);
8080
}
@@ -95,7 +95,7 @@ export interface RawGlimmerCallExpression extends CallExpression {
9595

9696
/** Type predicate */
9797
export function isRawGlimmerCallExpression(
98-
value: Node | null | undefined
98+
value: Node | null | undefined,
9999
): value is RawGlimmerCallExpression {
100100
return (
101101
isCallExpression(value) &&

src/utils/ambiguity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
*/
3434
export function hasAmbiguousNextLine(
3535
path: NodePath,
36-
options: Options
36+
options: Options,
3737
): boolean {
3838
// Note: getNextSibling().node will be undefined if there is no sibling
3939
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition

src/utils/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function isRecord(value: unknown): value is Record<string, unknown> {
1010
*/
1111
export function assert(
1212
message: string,
13-
condition?: unknown
13+
condition?: unknown,
1414
): asserts condition {
1515
if (!condition) {
1616
throw new Error(message);
@@ -20,7 +20,7 @@ export function assert(
2020
/** Asserts that the given item is not undefined. */
2121
export function assertExists<T>(
2222
item: T | undefined,
23-
message = 'assertExists failed'
23+
message = 'assertExists failed',
2424
): T {
2525
assert(message, item !== undefined);
2626
return item;

tests/helpers/ambiguous.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ export async function getAmbiguousCases(): Promise<TestCase[]> {
3838
* @see https://github.com/gitKrystan/prettier-plugin-ember-template-tag/issues/1 for more details
3939
*/
4040
export function makeAmbiguousExpressionTest(
41-
ambiguousExpressions = AMBIGUOUS_EXPRESSIONS
41+
ambiguousExpressions = AMBIGUOUS_EXPRESSIONS,
4242
) {
4343
return function ambiguousExpressionTest(
4444
config: Config,
45-
testCase: TestCase
45+
testCase: TestCase,
4646
): void {
4747
for (const ambiguousExpression of ambiguousExpressions) {
4848
describe(ambiguousExpression, () => {
@@ -87,7 +87,7 @@ export function makeAmbiguousExpressionTest(
8787

8888
async function behavesLikeFormattedAmbiguousCase(
8989
code: string,
90-
formatOptions: Partial<Options> = {}
90+
formatOptions: Partial<Options> = {},
9191
): Promise<void> {
9292
try {
9393
const result = await format(code, formatOptions);

tests/helpers/cases.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ export interface TestCase {
1313
*/
1414
export async function getCases(
1515
baseDirectory: fs.PathLike,
16-
directory: fs.PathLike
16+
directory: fs.PathLike,
1717
): Promise<TestCase[]> {
1818
const entries = await fs.promises.readdir(directory, { withFileTypes: true });
1919
const cases = await Promise.all(
2020
entries.map(async (entry) => {
2121
if (entry.isDirectory()) {
2222
return getCases(
2323
baseDirectory,
24-
path.join(directory.toString(), entry.name)
24+
path.join(directory.toString(), entry.name),
2525
);
2626
} else {
2727
const filename = path.join(directory.toString(), entry.name);
@@ -34,7 +34,7 @@ export async function getCases(
3434
path: filename,
3535
};
3636
}
37-
})
37+
}),
3838
);
3939

4040
return cases.flat();

0 commit comments

Comments
 (0)