ahbeng/NUSMods

View on GitHub

Showing 538 of 538 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

describe(SET_PLANNER_MIN_YEAR, () => {
  test('should set min year', () => {
    expect(reducer(defaultState, setPlannerMinYear('2016/2017'))).toEqual({
      ...defaultState,
      minYear: '2016/2017',
Severity: Major
Found in website/src/reducers/planner.test.ts and 1 other location - About 4 hrs to fix
website/src/reducers/planner.test.ts on lines 56..72

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 115.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function checkPrerequisite has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

export function checkPrerequisite(moduleSet: Set<ModuleCode>, tree: PrereqTree) {
  function walkTree(fragment: PrereqTree): PrereqTree[] | null {
    if (typeof fragment === 'string') {
      if (fragment.includes(GRADE_REQUIREMENT_SEPARATOR)) {
        const [module] = fragment.split(GRADE_REQUIREMENT_SEPARATOR);
Severity: Minor
Found in website/src/utils/planner.ts - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  test('shows at most 10 choices when there are many modules', () => {
    const { getByRole, getAllByRole } = make({
      venueBank: { venueList: VENUES.slice(0, 2) },
    });
    userEvent.type(getByRole('textbox'), '1 ');
Severity: Major
Found in website/src/views/layout/GlobalSearchContainer.test.tsx and 1 other location - About 3 hrs to fix
website/src/views/layout/GlobalSearchContainer.test.tsx on lines 118..154

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 112.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  test('prioritize showing venues when there are many venues even if there are modules', () => {
    const { getByRole, getAllByRole } = make({
      moduleBank: { moduleList: MODULES.slice(0, 5) },
    });
    userEvent.type(getByRole('textbox'), '1 ');
Severity: Major
Found in website/src/views/layout/GlobalSearchContainer.test.tsx and 1 other location - About 3 hrs to fix
website/src/views/layout/GlobalSearchContainer.test.tsx on lines 156..177

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 112.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

File GlobalSearchContainer.test.tsx has 327 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Provider } from 'react-redux';
import { MemoryRouter } from 'react-router-dom';
import produce from 'immer';
Severity: Minor
Found in website/src/views/layout/GlobalSearchContainer.test.tsx - About 3 hrs to fix

    File planner.test.ts has 325 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import { clone } from 'lodash';
    import { getAcadYearModules, getPrereqModuleCode } from 'selectors/planner';
    import { PlannerState } from 'types/reducers';
    import { ModuleCode } from 'types/modules';
    
    
    Severity: Minor
    Found in website/src/selectors/planner.test.ts - About 3 hrs to fix

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

        it('gives null for unsupported weeks', () => {
          expect(getAcadSem(-1)).toBe(null);
          expect(getAcadSem(0)).toBe(null);
          expect(getAcadSem(54)).toBe(null);
          expect(getAcadSem(1000)).toBe(null);
      Severity: Major
      Found in packages/nusmoderator/src/academicCalendar.test.ts and 1 other location - About 3 hrs to fix
      packages/nusmoderator/src/academicCalendar.test.ts on lines 71..77

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 109.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 3 locations. Consider refactoring.
      Open

      const AsyncContributeContainer = Loadable({
        loader: () =>
          retryImport(() => import(/* webpackChunkName: "contribute" */ './ContributeContainer')),
        loading: (props: LoadingComponentProps) => {
          if (props.error) {
      Severity: Major
      Found in website/src/views/contribute/ContributeContainer/index.tsx and 2 other locations - About 3 hrs to fix
      website/src/views/modules/ModuleFinderContainer/index.tsx on lines 7..21
      website/src/views/today/TodayContainer/index.tsx on lines 9..22

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 109.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 3 locations. Consider refactoring.
      Open

      const AsyncTodayContainer = Loadable({
        loader: () => retryImport(() => import(/* webpackChunkName: "today" */ './TodayContainer')),
        loading: (props: LoadingComponentProps) => {
          if (props.error) {
            return <ApiError dataName="page" retry={props.retry} />;
      Severity: Major
      Found in website/src/views/today/TodayContainer/index.tsx and 2 other locations - About 3 hrs to fix
      website/src/views/contribute/ContributeContainer/index.tsx on lines 7..21
      website/src/views/modules/ModuleFinderContainer/index.tsx on lines 7..21

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 109.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

        it('gives null for unsupported weeks', () => {
          expect(getAcadWeekName(-1)).toBe(null);
          expect(getAcadWeekName(0)).toBe(null);
          expect(getAcadWeekName(18)).toBe(null);
          expect(getAcadWeekName(1000)).toBe(null);
      Severity: Major
      Found in packages/nusmoderator/src/academicCalendar.test.ts and 1 other location - About 3 hrs to fix
      packages/nusmoderator/src/academicCalendar.test.ts on lines 50..56

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 109.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 3 locations. Consider refactoring.
      Open

      const AsyncModuleFinderContainer = Loadable({
        loader: () =>
          retryImport(() => import(/* webpackChunkName: "module-finder" */ './ModuleFinderContainer')),
        loading: (props: LoadingComponentProps) => {
          if (props.error) {
      Severity: Major
      Found in website/src/views/modules/ModuleFinderContainer/index.tsx and 2 other locations - About 3 hrs to fix
      website/src/views/contribute/ContributeContainer/index.tsx on lines 7..21
      website/src/views/today/TodayContainer/index.tsx on lines 9..22

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 109.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      NusModsParser has 30 functions (exceeds 20 allowed). Consider refactoring.
      Open

      export class NusModsParser extends Parser {
          public static readonly COMMA = 1;
          public static readonly LPAREN = 2;
          public static readonly RPAREN = 3;
          public static readonly IF_IN = 4;
      Severity: Minor
      Found in scrapers/nus-v2/src/services/requisite-tree/antlr4/NusModsParser.ts - About 3 hrs to fix

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        export async function image(page: Page, data: PageData, options: ViewportOptions = {}) {
          if (options.pixelRatio || (options.height && options.width)) {
            await setViewport(page, options);
          }
        
        
        Severity: Major
        Found in export/src/render-serverless.ts and 1 other location - About 3 hrs to fix
        export/src/render.ts on lines 92..101

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 107.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        export async function image(page: Page, data: PageData, options: ViewportOptions = {}) {
          if (options.pixelRatio || (options.height && options.width)) {
            await setViewport(page, options);
          }
        
        
        Severity: Major
        Found in export/src/render.ts and 1 other location - About 3 hrs to fix
        export/src/render-serverless.ts on lines 58..67

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 107.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Function scraper has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
        Open

        async function scraper() {
          const getDepartmentsResponse = await axios.post<ApiResponse<GetDepartmentsResponseData[]>>(
            `${baseUrl}/config/get-acadorg`,
            {
              eff_status: 'A',
        Severity: Minor
        Found in scrapers/cpex-scraper/src/index.ts - About 3 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        File ModulePageContent.tsx has 314 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import { memo, useState } from 'react';
        import classnames from 'classnames';
        import ScrollSpy from 'react-scrollspy';
        import { kebabCase, map, mapValues, values, sortBy } from 'lodash';
        
        
        Severity: Minor
        Found in website/src/views/modules/ModulePageContent.tsx - About 3 hrs to fix

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

                  {
                    ...defaultState,
                    modules: {
                      0: { id: '0', moduleCode: 'CS1010S', year: '2018/2019', semester: 2, index: 0 },
                      1: { id: '1', moduleCode: 'CS2030', year: '2018/2019', semester: 2, index: 1 },
          Severity: Major
          Found in website/src/reducers/planner.test.ts and 2 other locations - About 3 hrs to fix
          website/src/reducers/planner.test.ts on lines 134..142
          website/src/selectors/planner.test.ts on lines 115..122

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 104.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

            const initial: PlannerState = {
              ...defaultState,
          
              modules: {
                0: { id: '0', moduleCode: 'CS1010S', year: '2018/2019', semester: 1, index: 0 },
          Severity: Major
          Found in website/src/reducers/planner.test.ts and 2 other locations - About 3 hrs to fix
          website/src/reducers/planner.test.ts on lines 153..160
          website/src/selectors/planner.test.ts on lines 115..122

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 104.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

                  getState({
                    ...defaultState,
                    modules: {
                      0: { id: '0', moduleCode: 'CS1010S', year: '2018/2019', semester: 1, index: 1 },
                      1: { id: '1', moduleCode: 'MA1521', year: '2018/2019', semester: 1, index: 0 },
          Severity: Major
          Found in website/src/selectors/planner.test.ts and 2 other locations - About 3 hrs to fix
          website/src/reducers/planner.test.ts on lines 134..142
          website/src/reducers/planner.test.ts on lines 153..160

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 104.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          test('findExamClashes should return non-empty object if exams starting at different times clash', () => {
            const sem: Semester = 1;
            const examClashes = findExamClashes([CS1010S, CS3216 as any, CS1010A], sem);
            const examDate = _.get(getModuleSemesterData(CS1010A, sem), 'examDate');
            if (!examDate) throw new Error('Cannot find ExamDate');
          Severity: Major
          Found in website/src/utils/timetables.test.ts and 1 other location - About 3 hrs to fix
          website/src/utils/timetables.test.ts on lines 368..374

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 104.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Severity
          Category
          Status
          Source
          Language