I'm getting the `SyntaxError: Unexpected token, expected "}" (73:6)` error when formatting a `*.spec.ts` file
wujekbogdan opened this issue · 3 comments
wujekbogdan commented
Your Environment
- Prettier version: 3.2.4
- node version [18.14.2]:
- package manager: [npm@8.12.1]
- IDE: [CLI]
Describe the bug
When running:
pnpm prettier --write /my-file.spec.ts
I'm getting the following error message
SyntaxError: Unexpected token, expected "}" (73:6)
To Reproduce
Try to format the following file with pnpm prettier --write /my-file.spec.ts
import { z } from 'zod';
import { mockLogger } from '@my-namespace/logger';
import {
combineModelWithDescriptions,
extractDescriptionsFromSchema,
useLogger,
} from './logger';
describe('logger', () => {
beforeAll(mockLogger);
describe('extractDescriptions', () => {
it('should extract descriptions', () => {
const schema = z.object({
test1: z.string().describe('test 1 description'),
test2: z.string(),
});
expect(extractDescriptionsFromSchema(schema)).toEqual({
test1: 'test 1 description',
test2: 'N/A',
});
});
});
describe('combineModelWithDescriptions', () => {
it('should combine model with descriptions', () => {
const schema = z.object({
test1: z.string().describe('test 1 description'),
test2: z.string(),
});
const model = schema.parse({
test1: 'test 1 value',
test2: 'test 2 value',
});
const descriptions = <typeof model>extractDescriptionsFromSchema(schema);
expect(combineModelWithDescriptions(model, descriptions)).toEqual([
['test1', 'test 1 description', 'test 1 value'],
['test2', 'N/A', 'test 2 value'],
]);
});
});
describe('log', () => {
it('should log summary on success', () => {
const schema = z.object({
test1: z.string().describe('test 1 description'),
test2: z.string(),
test3: z.string().optional(),
});
const model = schema.parse({
test1: 'test 1 value',
test2: 'test 2 value',
test3: 'test 3 value',
});
const logger = useLogger('test', schema, false);
expect(logger.success(model)).toEqual([
[
{
colSpan: 3,
content: `"test" package configuration`,
vAlign: 'center',
hAlign: 'center',
},
],
['Name', 'Description', 'Value'],
['test1', 'test 1 description', 'test 1 value'],
['test2', 'N/A', 'test 2 value'],
['test3', 'N/A', 'test 3 value'],
]);
});
it('should hide the values of secrets', () => {
const schema = z.object({
secret1: z.string().describe('test 1 description'),
password1: z.string(),
});
const model = schema.parse({
secret1: 'test 1 value',
password1: 'test 2 value',
});
const logger = useLogger('test', schema, false);
expect(logger.success(model)).toEqual([
[
{
colSpan: 3,
content: `"test" package configuration`,
vAlign: 'center',
hAlign: 'center',
},
],
['Name', 'Description', 'Value'],
['secret1', 'test 1 description', '********'],
['password1', 'N/A', '********'],
]);
});
it('should log summary on error', () => {
const schema = z.object({
test1: z.string().describe('test 1 description'),
test2: z.string(),
});
const model = schema.safeParse({
test1: process.env.MISSING_VARIABLE_1,
test2: process.env.MISSING_VARIABLE_1,
});
const logger = useLogger('test', schema, false);
if (model.success) {
return;
}
expect(logger.error(model.error)).toEqual([
[
{
colSpan: 3,
content: `"test" package configuration`,
vAlign: 'center',
hAlign: 'center',
},
],
['Name', 'Description', 'Error'],
['test1', 'test 1 description', 'invalid_type: Required'],
['test2', 'N/A', 'invalid_type: Required'],
]);
});
});
});
Expected behavior
It should not break
Configuration File (cat prettier.config.js )
module.exports = {
singleQuote: true,
trailingComma: 'es5',
plugins: ["@trivago/prettier-plugin-sort-imports"],
importOrder: ["<THIRD_PARTY_MODULES>", "^@my-namespace/(.*)$", "^[./]"],
};
Error log
SyntaxError: Unexpected token, expected "}" (73:6)
metawrap-dev commented
+1
TwinsMaj commented
+1
guest363 commented
Try to add in prettier.config.js
"overrides": [
{
"files": ["*.mts", "*.cts", "*.ts"],
"options": {
"parser": "babel-ts"
}
}
]