ronantakizawa/codereview-bench huggingface dataset:
Repository: freeCodeCamp/freeCodeCamp
File: api/src/routes/protected/classroom.ts (TypeScript)

Code before:
    {
      schema: {
        body: Type.Object({
          email: Type.String({ format: 'email' })
        }),
        response: {
          200: Type.Object({
            userId: Type.String()
          }),
          404: Type.Object({
            error: Type.String()
          })
        }
      }
    },
    async (request, reply) => {
      const { email } = request.body as { email: string };

      try {
        // Find the user by email
        const user = await fastify.prisma.user.findFirst({
          where: { email },
          select: {
            id: true,
            isClassroomAccount: true
          }
        });

        if (!user || !user.isClassroomAccount) {
          return reply.code(404).send({ error: 'User not found' });
        }

        return reply.send({
          userId: user.id
        });
      } catch (error) {
        fastify.log.error(error);
        return reply.code(500).send({ error: 'Failed to retrieve user id' });
      }
    }
  );

  // Endpoint to retrieve user(s) data from a list of user ids
  fastify.post(
    '/api/protected/classroom/get-user-data',
    {
      schema: {
        body: Type.Object({
          userIds: Type.Array(Type.String())
        }),
        response: {

Review comment (suggestion):
```suggestion
          where: { email, isClassroomAccount: true },
          select: { id: true }
```
i.e. select only what you're interested in, rather than getting everything and filtering.

Code after:
  // Endpoint to retrieve a user's ID from a user's email.
  // If we send a 404 error here, it will stop the entire classroom process from working.
  // Instead, we indicate that the user was not found through a null response and continue.
  fastify.post(
    '/api/protected/classroom/get-user-id',
    {
      schema: schemas.classroomGetUserIdSchema
    },
    async (request, reply) => {
      const { email } = request.body;

      // Basic email validation - return empty userId for invalid emails
      const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
      if (!emailRegex.test(email)) {
        return reply.send({ userId: '' });
      }

      try {
        // Find the user by email
        const user = await fastify.prisma.user.findFirst({
          where: { email, isClassroomAccount: true },
          select: { id: true }
        });

        if (!user) {
          return reply.send({ userId: '' });
        }

        return reply.send({
          userId: user.id
        });
      } catch (error) {
        fastify.log.error(error);
        return reply.code(500).send({ error: 'Failed to retrieve user id' });
      }
    }
  );

  // Endpoint to retrieve user(s) data from a list of user ids
  fastify.post(
    '/api/protected/classroom/get-user-data',
    {
      schema: schemas.classroomGetUserDataSchema
    },
    async (request, reply) => {
      const { userIds = [] } = request.body;

      // Limit number of users per request for performance
      // Send custom error message if this is exceeded
      if (userIds.length > 50) {
        return reply.code(400).send({
Repository: freeCodeCamp/freeCodeCamp
File: api/src/schemas/classroom/classroom.ts (TypeScript)

Code before:
import { Type } from '@fastify/type-provider-typebox';
export const classroomGetUserIdSchema = {
  body: Type.Object({
    email: Type.String({ format: 'email', maxLength: 1024 })
  }),
  response: {
    200: Type.Object({ userId: Type.String() }),
    404: Type.Object({ error: Type.String() }),
    500: Type.Object({ error: Type.String() })
  }
};
export const classroomGetUserDataSchema = {
  body: Type.Object({
    userIds: Type.Array(Type.String(), { maxItems: 50 })
  }),
  response: {
    200: Type.Object({
      data: Type.Record(
        Type.String(),
        Type.Array(
          Type.Object({
            id: Type.String(),
            completedDate: Type.Number(),
            challengeName: Type.Optional(Type.String())
          })
        )
      )
    }),
    400: Type.Object({ error: Type.String() }),
    500: Type.Object({ error: Type.String() })
  }
};


Review comment (suggestion):
```suggestion
            completedDate: Type.Number()
```
This looks like a mistake since `challengeName` is not a challenge property.

Code after:
import { Type } from '@fastify/type-provider-typebox';
export const classroomGetUserIdSchema = {
  body: Type.Object({
    email: Type.String({ maxLength: 1024 })
  }),
  response: {
    200: Type.Object({ userId: Type.String() }),
    500: Type.Object({ error: Type.String() })
  }
};
export const classroomGetUserDataSchema = {
  body: Type.Object({
    userIds: Type.Array(Type.String())
  }),
  response: {
    200: Type.Object({
      data: Type.Record(
        Type.String(),
        Type.Array(
          Type.Object({
            id: Type.String(),
            completedDate: Type.Number()
          })
        )
      )
    }),
    400: Type.Object({ error: Type.String() }),
    500: Type.Object({ error: Type.String() })
  }
};
Repository: freeCodeCamp/freeCodeCamp
File: tools/scripts/lint/index.test.js (JavaScript)

Code before:
    // the linter signals that a file failed by setting
    // exitCode to 1, so it needs (re)setting to 0
    process.exitCode = 0;
  });
  afterEach(() => {
    process.exitCode = 0;
  });

  it('should pass `good` markdown', async () => {
    await new Promise(resolve => {
      function callback() {
        expect(process.exitCode).toBe(0);
        resolve();
      }
      lint(good, callback);
    });
  });

  it('should fail invalid YML blocks', async () => {
    await new Promise(resolve => {
      function callback() {
        expect(process.exitCode).toBe(1);
        resolve();
      }
      lint(badYML, callback);
    });
  });

  it('should fail when code fences are not surrounded by newlines', async () => {
    await new Promise(resolve => {
      function callback() {
        expect(process.exitCode).toBe(1);
        resolve();
      }
      lint(badFencing, callback);
    });
  });

  it('should write to the console describing the problem', async () => {
    await new Promise(resolve => {
      function callback() {
        const expected =
          'badYML.md: 19: yaml-linter YAML code blocks should be valid [bad indentation of a mapping entry at line 3, column 17:\n          testString: testString\n                    ^] [Context: "```yml"]';
        expect(console.log.mock.calls.length).toBe(1);
        expect(console.log.mock.calls[0][0]).toEqual(
          expect.stringContaining(expected)
        );
        resolve();
      }
      lint(badYML, callback);
    });

Review comment (suggestion):
```suggestion
    await new Promise(resolve => lint(badYML, resolve));
    expect(process.exitCode).toBe(1);
```

Code after:
    // the linter signals that a file failed by setting
    // exitCode to 1, so it needs (re)setting to 0
    process.exitCode = 0;
  });
  afterEach(() => {
    process.exitCode = 0;
  });

  it('should pass `good` markdown', async () => {
    await new Promise(resolve => lint(good, resolve));
    expect(process.exitCode).toBe(0);
  });

  it('should fail invalid YML blocks', async () => {
    await new Promise(resolve => lint(badYML, resolve));
    expect(process.exitCode).toBe(1);
  });

  it('should fail when code fences are not surrounded by newlines', async () => {
    await new Promise(resolve => lint(badFencing, resolve));
    expect(process.exitCode).toBe(1);
  });

  it('should write to the console describing the problem', async () => {
    await new Promise(resolve => lint(badYML, resolve));

    const expected =
      'badYML.md: 19: yaml-linter YAML code blocks should be valid [bad indentation of a mapping entry at line 3, column 17:\n          testString: testString\n                    ^] [Context: "```yml"]';
    expect(console.log.mock.calls.length).toBe(1);
    expect(console.log.mock.calls[0][0]).toEqual(
      expect.stringContaining(expected)
    );
  });
});
Repository: freeCodeCamp/freeCodeCamp
File: tools/scripts/lint/index.test.js (JavaScript)

Code before:
      function callback() {
        expect(process.exitCode).toBe(0);
        resolve();
      }
      lint(good, callback);
    });
  });

  it('should fail invalid YML blocks', async () => {
    await new Promise(resolve => {
      function callback() {
        expect(process.exitCode).toBe(1);
        resolve();
      }
      lint(badYML, callback);
    });
  });

  it('should fail when code fences are not surrounded by newlines', async () => {
    await new Promise(resolve => {
      function callback() {
        expect(process.exitCode).toBe(1);
        resolve();
      }
      lint(badFencing, callback);
    });
  });

  it('should write to the console describing the problem', async () => {
    await new Promise(resolve => {
      function callback() {
        const expected =
          'badYML.md: 19: yaml-linter YAML code blocks should be valid [bad indentation of a mapping entry at line 3, column 17:\n          testString: testString\n                    ^] [Context: "```yml"]';
        expect(console.log.mock.calls.length).toBe(1);
        expect(console.log.mock.calls[0][0]).toEqual(
          expect.stringContaining(expected)
        );
        resolve();
      }
      lint(badYML, callback);
    });
  });
});


Review comment (suggestion):
```suggestion
    await new Promise(resolve => lint(badFencing, resolve));
    expect(process.exitCode).toBe(1);
```

Code after:
import path from 'path';
import { describe, it, beforeEach, afterEach, expect, vi } from 'vitest';
import lint from '.';

describe('markdown linter', () => {
  const good = { path: path.join(__dirname, './fixtures/good.md') };
  const badYML = { path: path.join(__dirname, './fixtures/badYML.md') };
  const badFencing = { path: path.join(__dirname, './fixtures/badFencing.md') };
  beforeEach(() => {
    console.log = vi.fn();
    // the linter signals that a file failed by setting
    // exitCode to 1, so it needs (re)setting to 0
    process.exitCode = 0;
  });
  afterEach(() => {
    process.exitCode = 0;
  });

  it('should pass `good` markdown', async () => {
    await new Promise(resolve => lint(good, resolve));
    expect(process.exitCode).toBe(0);
  });

  it('should fail invalid YML blocks', async () => {
    await new Promise(resolve => lint(badYML, resolve));
    expect(process.exitCode).toBe(1);
  });

  it('should fail when code fences are not surrounded by newlines', async () => {
    await new Promise(resolve => lint(badFencing, resolve));
    expect(process.exitCode).toBe(1);
  });

  it('should write to the console describing the problem', async () => {
    await new Promise(resolve => lint(badYML, resolve));

    const expected =
      'badYML.md: 19: yaml-linter YAML code blocks should be valid [bad indentation of a mapping entry at line 3, column 17:\n          testString: testString\n                    ^] [Context: "```yml"]';
    expect(console.log.mock.calls.length).toBe(1);
    expect(console.log.mock.calls[0][0]).toEqual(
      expect.stringContaining(expected)
    );
  });
});
Repository: freeCodeCamp/freeCodeCamp
File: tools/scripts/lint/index.test.js (JavaScript)

Code before:
    });
  });

  it('should fail when code fences are not surrounded by newlines', async () => {
    await new Promise(resolve => {
      function callback() {
        expect(process.exitCode).toBe(1);
        resolve();
      }
      lint(badFencing, callback);
    });
  });

  it('should write to the console describing the problem', async () => {
    await new Promise(resolve => {
      function callback() {
        const expected =
          'badYML.md: 19: yaml-linter YAML code blocks should be valid [bad indentation of a mapping entry at line 3, column 17:\n          testString: testString\n                    ^] [Context: "```yml"]';
        expect(console.log.mock.calls.length).toBe(1);
        expect(console.log.mock.calls[0][0]).toEqual(
          expect.stringContaining(expected)
        );
        resolve();
      }
      lint(badYML, callback);
    });
  });
});


Review comment (suggestion):
```suggestion
    await new Promise(resolve => lint(badYML, resolve));

    const expected =
      'badYML.md: 19: yaml-linter YAML code blocks should be valid [bad indentation of a mapping entry at line 3, column 17:\n          testString: testString\n                    ^] [Context: "```yml"]';
    expect(console.log.mock.calls.length).toBe(1);
    expect(console.log.mock.calls[0][0]).toEqual(
      expect.stringContaining(expected)
    );
```

Code after:
import path from 'path';
import { describe, it, beforeEach, afterEach, expect, vi } from 'vitest';
import lint from '.';

describe('markdown linter', () => {
  const good = { path: path.join(__dirname, './fixtures/good.md') };
  const badYML = { path: path.join(__dirname, './fixtures/badYML.md') };
  const badFencing = { path: path.join(__dirname, './fixtures/badFencing.md') };
  beforeEach(() => {
    console.log = vi.fn();
    // the linter signals that a file failed by setting
    // exitCode to 1, so it needs (re)setting to 0
    process.exitCode = 0;
  });
  afterEach(() => {
    process.exitCode = 0;
  });

  it('should pass `good` markdown', async () => {
    await new Promise(resolve => lint(good, resolve));
    expect(process.exitCode).toBe(0);
  });

  it('should fail invalid YML blocks', async () => {
    await new Promise(resolve => lint(badYML, resolve));
    expect(process.exitCode).toBe(1);
  });

  it('should fail when code fences are not surrounded by newlines', async () => {
    await new Promise(resolve => lint(badFencing, resolve));
    expect(process.exitCode).toBe(1);
  });

  it('should write to the console describing the problem', async () => {
    await new Promise(resolve => lint(badYML, resolve));

    const expected =
      'badYML.md: 19: yaml-linter YAML code blocks should be valid [bad indentation of a mapping entry at line 3, column 17:\n          testString: testString\n                    ^] [Context: "```yml"]';
    expect(console.log.mock.calls.length).toBe(1);
    expect(console.log.mock.calls[0][0]).toEqual(
      expect.stringContaining(expected)
    );
  });
});
Repository: freeCodeCamp/freeCodeCamp
File: client/src/components/Map/index.tsx (TypeScript)

Code before:
import i18next from 'i18next';
import React, { Fragment } from 'react';
import { Spacer } from '@freecodecamp/ui';
import { useTranslation, Trans, withTranslation } from 'react-i18next';

import {
  type SuperBlocks,
  SuperBlockStage,
  getStageOrder,
  superBlockStages,
  archivedSuperBlocks
} from '../../../../shared-dist/config/curriculum';
import { SuperBlockIcon } from '../../assets/superblock-icon';
import LinkButton from '../../assets/icons/link-button';
import { ButtonLink, Link } from '../helpers';
import { showUpcomingChanges } from '../../../config/env.json';
import DailyCodingChallengeWidget from '../daily-coding-challenge/widget';

import './map.css';
interface MapProps {
  forLanding?: boolean;
}

const linkSpacingStyle = {
  display: 'flex',
  justifyContent: 'space-between',
  alignItems: 'center',
  gap: '15px'
};

Review comment (suggestion):
`Map` already uses the `useTranslation` hook so we shouldn't need this HOC.

```suggestion
import { useTranslation, Trans } from 'react-i18next';
```

Code after:
import i18next from 'i18next';
import React, { Fragment } from 'react';
import { Spacer } from '@freecodecamp/ui';
import { useTranslation, Trans } from 'react-i18next';

import {
  type SuperBlocks,
  SuperBlockStage,
  getStageOrder,
  superBlockStages,
  archivedSuperBlocks
} from '../../../../shared-dist/config/curriculum';
import { SuperBlockIcon } from '../../assets/superblock-icon';
import LinkButton from '../../assets/icons/link-button';
import { ButtonLink, Link } from '../helpers';
import { showUpcomingChanges } from '../../../config/env.json';
import DailyCodingChallengeWidget from '../daily-coding-challenge/widget';

import './map.css';
interface MapProps {
  forLanding?: boolean;
}

const linkSpacingStyle = {
  display: 'flex',
  justifyContent: 'space-between',
  alignItems: 'center',
  gap: '15px'
};
Repository: freeCodeCamp/freeCodeCamp
File: client/src/components/archived-warning/index.tsx (TypeScript)

Code before:
import React from 'react';
import { withTranslation, Trans } from 'react-i18next';
import { Callout } from '@freecodecamp/ui';

import { Link } from '../helpers';

const ArchivedWarning = () => {
  return (
    <Callout variant='info'>
      <p className='text-center' style={{ marginBottom: 0, fontSize: '1rem' }}>
        <Trans i18nKey='learn.archive.content-not-updated'>
          <strong style={{ color: 'var(--blue-dark)' }}>placeholder</strong>
          <Link to={'/learn/full-stack-developer'}>placeholder</Link>
        </Trans>
      </p>
    </Callout>
  );
};

export default withTranslation()(ArchivedWarning);


Review comment (suggestion):
The component doesn't seem to need `withTranslation`.

```suggestion
import { Trans } from 'react-i18next';
```

Code after:
import React from 'react';
import { Trans } from 'react-i18next';
import { Callout } from '@freecodecamp/ui';

import { Link } from '../helpers';

import './index.css';

const ArchivedWarning = () => {
  return (
    <Callout variant='info'>
      <p className='text-center archived-warning'>
        <Trans i18nKey='learn.archive.content-not-updated'>
          <strong>placeholder</strong>
          <Link to={'/learn/full-stack-developer'}>placeholder</Link>
        </Trans>
      </p>
    </Callout>
  );
};

export default ArchivedWarning;
Repository: freeCodeCamp/freeCodeCamp
File: client/src/components/archived-warning/index.tsx (TypeScript)

Code before:
import React from 'react';
import { withTranslation, Trans } from 'react-i18next';
import { Callout } from '@freecodecamp/ui';

import { Link } from '../helpers';

const ArchivedWarning = () => {
  return (
    <Callout variant='info'>
      <p className='text-center' style={{ marginBottom: 0, fontSize: '1rem' }}>
        <Trans i18nKey='learn.archive.content-not-updated'>
          <strong style={{ color: 'var(--blue-dark)' }}>placeholder</strong>
          <Link to={'/learn/full-stack-developer'}>placeholder</Link>
        </Trans>
      </p>
    </Callout>
  );
};

export default withTranslation()(ArchivedWarning);


Review comment (suggestion):
```suggestion
export default ArchivedWarning;
```

Code after:
import React from 'react';
import { Trans } from 'react-i18next';
import { Callout } from '@freecodecamp/ui';

import { Link } from '../helpers';

import './index.css';

const ArchivedWarning = () => {
  return (
    <Callout variant='info'>
      <p className='text-center archived-warning'>
        <Trans i18nKey='learn.archive.content-not-updated'>
          <strong>placeholder</strong>
          <Link to={'/learn/full-stack-developer'}>placeholder</Link>
        </Trans>
      </p>
    </Callout>
  );
};

export default ArchivedWarning;
Repository: freeCodeCamp/freeCodeCamp
File: client/src/templates/Challenges/exam-download/exam-token-controls.tsx (TypeScript)

Code before:
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Button, Spacer } from '@freecodecamp/ui';

import { examEnvironmentAuthorizationTokenApi } from '../../../utils/ajax';
import { Loader } from '../../../components/helpers';

export function ExamTokenControls(): JSX.Element {
  const { t } = useTranslation();

  const [copySuccess, setCopySuccess] = useState<string | null>(null);
  const [copyError, setCopyError] = useState<string | null>(null);

  const [generateToken, generateMutation] =
    examEnvironmentAuthorizationTokenApi.usePostGenerateExamEnvironmentAuthorizationTokenMutation();

  const getTokenQuery =
    examEnvironmentAuthorizationTokenApi.useGetExamEnvironmentAuthorizationTokenQuery();
  const [token, setToken] = useState<string | null>(
    getTokenQuery.data?.examEnvironmentAuthorizationToken ?? null
  );

  useEffect(() => {
    const data = generateMutation.data;
    if (!data) return;


Review comment (suggestion):
```suggestion
import React, { useState } from 'react';
```
Not needed. See below.

Code after:
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Button, Spacer } from '@freecodecamp/ui';

import { examEnvironmentAuthorizationTokenApi } from '../../../utils/ajax';
import { Loader } from '../../../components/helpers';

export function ExamTokenControls(): JSX.Element {
  const { t } = useTranslation();

  const [copySuccess, setCopySuccess] = useState<string | null>(null);
  const [copyError, setCopyError] = useState<string | null>(null);

  const [generateToken, generateMutation] =
    examEnvironmentAuthorizationTokenApi.usePostGenerateExamEnvironmentAuthorizationTokenMutation();

  const getTokenQuery =
    examEnvironmentAuthorizationTokenApi.useGetExamEnvironmentAuthorizationTokenQuery();
  const existingToken = getTokenQuery.data?.examEnvironmentAuthorizationToken;
  const updatedToken = generateMutation.data?.examEnvironmentAuthorizationToken;
  const token = updatedToken ?? existingToken;

  function handleCopyExamToken() {
    navigator.clipboard.writeText(token ?? '').then(
      () => {
        setCopySuccess(t('exam-token.copied'));