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

I'm getting the SyntaxError: Unexpected token, expected "}" (73:6) error when formatting a *.spec.ts file #280

Open
wujekbogdan opened this issue Jan 31, 2024 · 2 comments

Comments

@wujekbogdan
Copy link

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
Copy link

+1

1 similar comment
@TwinsMaj
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants