ElectronicBabylonianLiterature/ebl-frontend

View on GitHub
src/fragmentarium/ui/fragment/PdfExport.tsx

Summary

Maintainability
F
1 wk
Test Coverage
B
87%

File PdfExport.tsx has 661 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import React from 'react'
import { Fragment } from 'fragmentarium/domain/fragment'
import Record from 'fragmentarium/ui/info/Record'

import { ReactElement } from 'react'
Severity: Major
Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 1 day to fix

    Function addMainTableWithFootnotes has 136 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function addMainTableWithFootnotes(
      table: JQuery,
      notes: JQuery,
      jQueryRef: any,
      yPos: number,
    Severity: Major
    Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 5 hrs to fix

      Function getTransliterationText has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

      function getTransliterationText(
        el: HTMLElement | Text | Comment | Document,
        doc: jsPDF,
        xPos: number,
        yPos: number,
      Severity: Minor
      Found in src/fragmentarium/ui/fragment/PdfExport.tsx - 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 dealWithFootNotesHtml has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function dealWithFootNotesHtml(
        el: HTMLElement | Text | Comment | Document,
        doc: jsPDF,
        xPos: number,
        yPos: number
      Severity: Minor
      Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 1 hr to fix

        Function addGlossary has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function addGlossary(
          glossaryHtml: JQuery,
          jQueryRef: JQuery,
          yPos: number,
          doc: any
        Severity: Minor
        Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 1 hr to fix

          Function getColumnSizes has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function getColumnSizes(
            table: JQuery,
            jQueryRef: JQuery,
            outerPaddingForTable: number,
            firstColumnMinWidth: number,
          Severity: Minor
          Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 1 hr to fix

            Function dealWithGlossaryHtml has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function dealWithGlossaryHtml(
              el: HTMLElement | Text | Comment | Document,
              doc: jsPDF,
              xPos: number,
              yPos: number
            Severity: Minor
            Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 1 hr to fix

              Function addFootnotes has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Wontfix

              function addFootnotes(
                notes: JQuery,
                padding: number,
                jQueryRef: JQuery,
                yPos: number,
              Severity: Minor
              Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 1 hr to fix

                Function addPdfHeadLine has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Wontfix

                function addPdfHeadLine(doc: jsPDF, fragment: Fragment, yPos: number): number {
                  const headlineParts = getPdfHeadline(fragment)
                  const outerPaddingForCredits = 20
                
                  doc.setFont('JunicodeBold', 'normal')
                Severity: Minor
                Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 1 hr to fix

                  Function addUnderLine has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Wontfix

                  function addUnderLine(
                    yPos: any,
                    endpos: number,
                    num: number,
                    page: number,
                  Severity: Minor
                  Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 1 hr to fix

                    Function addUnderLine has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                      yPos: any,
                      endpos: number,
                      num: number,
                      page: number,
                      endposFirstColumn: number,
                    Severity: Minor
                    Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                          if (checkIfNewPage(yPos, doc)) {
                                            newPageStarted = true
                                            doc.addPage()
                                            yPos = 15
                                            maxYPos.coords = 15
                      Severity: Major
                      Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 45 mins to fix

                        Function getPdfDoc has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                          tableHtml: JQuery,
                          notesHtml: JQuery,
                          jQueryRef: JQuery,
                          wordService: WordService,
                          fragment: Fragment
                        Severity: Minor
                        Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 35 mins to fix

                          Function addFootnotes has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                            notes: JQuery,
                            padding: number,
                            jQueryRef: JQuery,
                            yPos: number,
                            doc: jsPDF
                          Severity: Minor
                          Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 35 mins to fix

                            Function getTransliterationText has 5 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                              el: HTMLElement | Text | Comment | Document,
                              doc: jsPDF,
                              xPos: number,
                              yPos: number,
                              add: boolean
                            Severity: Minor
                            Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 35 mins to fix

                              Function getColumnSizes has 5 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                table: JQuery,
                                jQueryRef: JQuery,
                                outerPaddingForTable: number,
                                firstColumnMinWidth: number,
                                doc: jsPDF
                              Severity: Minor
                              Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 35 mins to fix

                                Function addMainTableWithFootnotes has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                  table: JQuery,
                                  notes: JQuery,
                                  jQueryRef: any,
                                  yPos: number,
                                  doc: any
                                Severity: Minor
                                Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 35 mins to fix

                                  Function setDocStyle has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                  function setDocStyle(el: any, doc: jsPDF) {
                                    const superScript = el.is('sup')
                                    const allSmall = el.css('font-variant') === 'all-small-caps'
                                  
                                    if (el.css('font-style') === 'italic' || el.is('em'))
                                  Severity: Minor
                                  Found in src/fragmentarium/ui/fragment/PdfExport.tsx - About 35 mins 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

                                    lis.each((i, el) => {
                                      let linePos = padding
                                  
                                      $(el)
                                        .contents()
                                  Severity: Major
                                  Found in src/fragmentarium/ui/fragment/PdfExport.tsx and 1 other location - About 6 hrs to fix
                                  src/fragmentarium/ui/fragment/PdfExport.tsx on lines 555..576

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

                                  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

                                    divs.each((i, el) => {
                                      let linePos = paddingForGlossary
                                  
                                      $(el)
                                        .contents()
                                  Severity: Major
                                  Found in src/fragmentarium/ui/fragment/PdfExport.tsx and 1 other location - About 6 hrs to fix
                                  src/fragmentarium/ui/fragment/PdfExport.tsx on lines 499..520

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

                                  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

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

                                    const tableHtml: JQuery = $(
                                      renderToString(
                                        <MemoryRouter>
                                          <DictionaryContext.Provider value={wordService}>
                                            <TransliterationLines text={fragment.text} />
                                  Severity: Major
                                  Found in src/fragmentarium/ui/fragment/PdfExport.tsx and 1 other location - About 2 hrs to fix
                                  src/fragmentarium/ui/fragment/WordExport.tsx on lines 52..60

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

                                  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

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

                                          if ($(el).is('span.Transliteration__Word')) {
                                            if (
                                              $(el).contents().text().length > 0 &&
                                              $(el).contents()[0].nodeType === 3
                                            ) {
                                  Severity: Major
                                  Found in src/fragmentarium/ui/fragment/PdfExport.tsx and 1 other location - About 2 hrs to fix
                                  src/fragmentarium/ui/fragment/PdfExport.tsx on lines 661..674

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

                                  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

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

                                        .each((i, el) => {
                                          if (
                                            $(el).contents().text().length > 0 &&
                                            $(el).contents()[0].nodeType === 3
                                          ) {
                                  Severity: Major
                                  Found in src/fragmentarium/ui/fragment/PdfExport.tsx and 1 other location - About 2 hrs to fix
                                  src/fragmentarium/ui/fragment/PdfExport.tsx on lines 603..616

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

                                  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

                                  function getCredit(records: JQuery): string {
                                    return (
                                      'Credit: electronic Babylonian Library Project; ' +
                                      records
                                        .find('.Record__entry')
                                  Severity: Major
                                  Found in src/fragmentarium/ui/fragment/PdfExport.tsx and 1 other location - About 1 hr to fix
                                  src/common/HtmlToWord.tsx on lines 112..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 73.

                                  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

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

                                    const notesHtml: JQuery = $(
                                      renderToString(
                                        <DictionaryContext.Provider value={wordService}>
                                          <TransliterationNotes notes={fragment.text.notes} />
                                        </DictionaryContext.Provider>
                                  Severity: Major
                                  Found in src/fragmentarium/ui/fragment/PdfExport.tsx and 1 other location - About 1 hr to fix
                                  src/fragmentarium/ui/fragment/WordExport.tsx on lines 61..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 70.

                                  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

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

                                    const glossaryJsx: JSX.Element = await glossaryFactory
                                      .createGlossary(fragment.text)
                                      .then((glossaryData) => {
                                        return Glossary({ data: glossaryData })
                                      })
                                  Severity: Major
                                  Found in src/fragmentarium/ui/fragment/PdfExport.tsx and 1 other location - About 1 hr to fix
                                  src/fragmentarium/ui/fragment/WordExport.tsx on lines 209..213

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

                                  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

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

                                    const glossaryHtml: JQuery = $(
                                      renderToString(
                                        wrapWithMemoryRouter(
                                          <DictionaryContext.Provider value={wordService}>
                                            {glossaryJsx}
                                  Severity: Major
                                  Found in src/fragmentarium/ui/fragment/PdfExport.tsx and 1 other location - About 1 hr to fix
                                  src/fragmentarium/ui/fragment/WordExport.tsx on lines 214..222

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

                                  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

                                  There are no issues that match your filters.

                                  Category
                                  Status