ahbeng/NUSMods

View on GitHub

Showing 538 of 538 total issues

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

async function setViewport(page: Page, options: ViewportOptions = {}) {
  await page.setViewport({
    deviceScaleFactor: options.pixelRatio || 1,
    width: options.width || config.pageWidth,
    height: options.height || VIEWPORT_HEIGHT,
Severity: Major
Found in export/src/render-serverless.ts and 1 other location - About 2 hrs to fix
export/src/render.ts on lines 18..24

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 84.

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

async function setViewport(page: Page, options: ViewportOptions = {}) {
  await page.setViewport({
    deviceScaleFactor: options.pixelRatio || 1,
    width: options.width || config.pageWidth,
    height: options.height || VIEWPORT_HEIGHT,
Severity: Major
Found in export/src/render.ts and 1 other location - About 2 hrs to fix
export/src/render-serverless.ts on lines 17..23

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 84.

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 mapAttributes has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

export function mapAttributes(
  attributes: ModuleAttributeEntry[],
  logger: Logger,
): NUSModuleAttributes | undefined {
  const nusAttributes: NUSModuleAttributes = {};
Severity: Minor
Found in scrapers/nus-v2/src/tasks/GetSemesterData.ts - About 2 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

Function renderType has 60 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function renderType(type: EmptyGroupType) {
  switch (type) {
    case 'winter':
      return (
        <>
Severity: Major
Found in website/src/views/today/EmptyLessonGroup.tsx - About 2 hrs to fix

    Function run has 60 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      async run(input: Input) {
        const { semester, academicYear } = this;
    
        this.logger.info(`Getting semester data for ${academicYear} semester ${semester}`);
    
    
    Severity: Major
    Found in scrapers/nus-v2/src/tasks/GetSemesterData.ts - About 2 hrs to fix

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

      describe('getLessonTimeHours', () => {
        test('calculates hours correctly', () => {
          expect(getLessonTimeHours('0059')).toBe(0);
          expect(getLessonTimeHours('0100')).toBe(1);
          expect(getLessonTimeHours('2300')).toBe(23);
      Severity: Major
      Found in website/src/utils/timify.test.ts and 1 other location - About 2 hrs to fix
      website/src/utils/timify.test.ts on lines 25..31

      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 83.

      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

      describe('getLessonTimeMinutes', () => {
        test('calculates minutes correctly', () => {
          expect(getLessonTimeMinutes('0000')).toBe(0);
          expect(getLessonTimeMinutes('0001')).toBe(1);
          expect(getLessonTimeMinutes('0059')).toBe(59);
      Severity: Major
      Found in website/src/utils/timify.test.ts and 1 other location - About 2 hrs to fix
      website/src/utils/timify.test.ts on lines 17..23

      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 83.

      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

          expect(
            shallow(
              <SearchBox
                throttle={0}
                useInstantSearch={false}
      Severity: Major
      Found in website/src/views/components/SearchBox.test.tsx and 1 other location - About 2 hrs to fix
      website/src/views/components/SearchBox.test.tsx on lines 6..18

      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 83.

      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

          expect(
            shallow(
              <SearchBox
                throttle={0}
                useInstantSearch={false}
      Severity: Major
      Found in website/src/views/components/SearchBox.test.tsx and 1 other location - About 2 hrs to fix
      website/src/views/components/SearchBox.test.tsx on lines 34..46

      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 83.

      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 program_types has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public program_types(): Program_typesContext {
              let _localctx: Program_typesContext = new Program_typesContext(this._ctx, this.state);
              this.enterRule(_localctx, 2, NusModsParser.RULE_program_types);
              let _la: number;
              try {
      Severity: Major
      Found in scrapers/nus-v2/src/services/requisite-tree/antlr4/NusModsParser.ts - About 2 hrs to fix

        Function ModuleTreeComponent has 59 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export const ModuleTreeComponent: React.FC<Props> = (props) => {
          const { fulfillRequirements, prereqTree, moduleCode } = props;
        
          return (
            <>
        Severity: Major
        Found in website/src/views/modules/ModuleTree.tsx - About 2 hrs to fix

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

                {
                  moduleCode: 'EL5251',
                  semesterData: {
                    timetable: [
                      {
          Severity: Major
          Found in scrapers/nus-v2/src/tasks/CollateVenues.test.ts and 1 other location - About 2 hrs to fix
          scrapers/nus-v2/src/tasks/CollateVenues.test.ts on lines 568..584

          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 81.

          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

                {
                  moduleCode: 'EL6884',
                  semesterData: {
                    timetable: [
                      {
          Severity: Major
          Found in scrapers/nus-v2/src/tasks/CollateVenues.test.ts and 1 other location - About 2 hrs to fix
          scrapers/nus-v2/src/tasks/CollateVenues.test.ts on lines 551..567

          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 81.

          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 ical.test.ts has 262 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import { EventOption } from 'ical-generator';
          import config from 'config';
          import iCalForTimetable, {
            calculateNumericWeek,
            calculateWeekRange,
          Severity: Minor
          Found in website/src/utils/ical.test.ts - About 2 hrs to fix

            Function createIndex has 57 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            async function createIndex(client: Client): Promise<Client> {
              try {
                await client.indices.create({
                  index: INDEX_NAME,
                  body: {
            Severity: Major
            Found in scrapers/nus-v2/src/services/io/elastic.ts - About 2 hrs to fix

              Function makeExportHandler has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
              Open

              export function makeExportHandler<T>(
                parseExportData: (request: NowRequest) => T,
                performExport: (response: NowResponse, page: Page, data: T) => void | Promise<void>,
              ): NowApiHandler {
                return async function handler(request, response) {
              Severity: Minor
              Found in export/src/handler.ts - About 2 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

              describe(getEndTimeAsDate, () => {
                test('should return end time as date', () => {
                  const date = new Date(2018, 5, 10);
                  const lesson = createGenericLesson('Monday', '0830', '1045');
                  expect(getEndTimeAsDate(lesson, date)).toEqual(new Date(2018, 5, 10, 10, 45));
              Severity: Major
              Found in website/src/utils/timetables.test.ts and 1 other location - About 2 hrs to fix
              website/src/utils/timetables.test.ts on lines 641..647

              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 80.

              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

                const expected = {
                  start: new Date('2016-08-08T14:00+0800'),
                  end: new Date('2016-08-08T17:00+0800'),
                  summary: 'BFS1001 Sectional Teaching',
                  description: 'Personal Development & Career Management\nSectional Teaching Group A1',
              Severity: Major
              Found in website/src/utils/ical.test.ts and 1 other location - About 2 hrs to fix
              website/src/utils/ical.test.ts on lines 287..299

              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 80.

              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

              describe(getStartTimeAsDate, () => {
                test('should return start time as date', () => {
                  const date = new Date(2018, 5, 10);
                  const lesson = createGenericLesson('Monday', '0830', '1045');
                  expect(getStartTimeAsDate(lesson, date)).toEqual(new Date(2018, 5, 10, 8, 30));
              Severity: Major
              Found in website/src/utils/timetables.test.ts and 1 other location - About 2 hrs to fix
              website/src/utils/timetables.test.ts on lines 649..655

              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 80.

              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

                const expected = {
                  start: new Date('2016-08-08T18:30+0800'),
                  end: new Date('2016-08-08T20:30+0800'),
                  summary: 'BFS1001 Sectional Teaching',
                  description: 'Personal Development & Career Management\nSectional Teaching Group A1',
              Severity: Major
              Found in website/src/utils/ical.test.ts and 1 other location - About 2 hrs to fix
              website/src/utils/ical.test.ts on lines 254..266

              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 80.

              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