html-to-text/node-html-to-text

View on GitHub

Showing 55 of 85 total issues

Function constructor has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
Open

  constructor (options) {
    this.whitespaceChars = (options.preserveNewlines)
      ? options.whitespaceCharacters.replace(/\n/g, '')
      : options.whitespaceCharacters;
    const whitespaceCodes = charactersToCodes(this.whitespaceChars);
Severity: Minor
Found in packages/base/src/whitespace-processor.js - About 6 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 tableToString has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

function tableToString (tableRows, rowSpacing, colSpacing) {
  const layout = [];
  let colNumber = 0;
  const rowNumber = tableRows.length;
  const rowOffsets = [0];
Severity: Minor
Found in packages/html-to-text/src/table-printer.js - About 4 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 md-formatters.js has 295 lines of code (exceeds 250 allowed). Consider refactoring.
Open


import { get, trimCharacter, trimCharacterEnd } from '@html-to-text/base/src/util';
import { render } from 'dom-serializer';
import { existsOne, innerText } from 'domutils';

Severity: Minor
Found in packages/html-to-md/src/md-formatters.js - About 3 hrs to fix

    BlockTextBuilder has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class BlockTextBuilder {
    
      /**
       * Creates an instance of BlockTextBuilder.
       *
    Severity: Minor
    Found in packages/base/src/block-text-builder.js - About 2 hrs to fix

      Function formatDataTable has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

      function formatDataTable (elem, walk, builder, formatOptions) {
        builder.openTable();
        elem.children.forEach(walkTable);
        builder.closeTable({
          tableToString: (rows) => tableToString(rows, formatOptions.rowSpacing ?? 0, formatOptions.colSpacing ?? 3),
      Severity: Minor
      Found in packages/html-to-text/src/text-formatters.js - 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 splitLongWord has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        splitLongWord (word) {
          const parts = [];
          let idx = 0;
          while (word.length > this.maxLineLength) {
      
      
      Severity: Minor
      Found in packages/base/src/inline-text-builder.js - 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

      File text-formatters.js has 266 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      
      import { get, numberToLetterSequence, numberToRoman, trimCharacter, trimCharacterEnd } from '@html-to-text/base/src/util';
      
      import { tableToString } from './table-printer';
      
      
      Severity: Minor
      Found in packages/html-to-text/src/text-formatters.js - About 2 hrs to fix

        Function constructor has 56 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          constructor (options) {
            this.whitespaceChars = (options.preserveNewlines)
              ? options.whitespaceCharacters.replace(/\n/g, '')
              : options.whitespaceCharacters;
            const whitespaceCodes = charactersToCodes(this.whitespaceChars);
        Severity: Major
        Found in packages/base/src/whitespace-processor.js - About 2 hrs to fix

          Function formatDataTable has 52 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function formatDataTable (elem, walk, builder, formatOptions) {
            builder.openTable();
            elem.children.forEach(walkTable);
            builder.closeTable({
              tableToString: (rows) => tableToString(rows, formatOptions.rowSpacing ?? 0, formatOptions.colSpacing ?? 3),
          Severity: Major
          Found in packages/html-to-text/src/text-formatters.js - About 2 hrs to fix

            File block-text-builder.js has 253 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            
            import {
              // eslint-disable-next-line no-unused-vars
              StackItem, BlockStackItem,
              TableCellStackItem, TableRowStackItem, TableStackItem,
            Severity: Minor
            Found in packages/base/src/block-text-builder.js - About 2 hrs to fix

              Function tableToString has 49 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function tableToString (tableRows, rowSpacing, colSpacing) {
                const layout = [];
                let colNumber = 0;
                const rowNumber = tableRows.length;
                const rowOffsets = [0];
              Severity: Minor
              Found in packages/html-to-text/src/table-printer.js - About 1 hr to fix

                Function collectDefinitionGroups has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                function collectDefinitionGroups (elem) {
                  const defItems = [];
                  function handleDtDd (el) {
                    if (el.name === 'dt' || el.name === 'dd') {
                      defItems.push(el);
                Severity: Minor
                Found in packages/html-to-md/src/md-formatters.js - About 1 hr 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 handleDeprecatedOptions has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                function handleDeprecatedOptions (options) {
                  if (options.tags) {
                    const tagDefinitions = Object.entries(options.tags).map(
                      ([selector, definition]) => ({ ...definition, selector: selector || '*' })
                    );
                Severity: Minor
                Found in packages/html-to-text/src/html-to-text.js - About 1 hr 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 formatDataTable has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                function formatDataTable (elem, walk, builder, formatOptions) {
                  builder.openTable();
                  elem.children.forEach(walkTable);
                  const hasHeader = existsOne(
                    (el) => el.name === 'thead' || el.name === 'th',
                Severity: Minor
                Found in packages/html-to-md/src/md-formatters.js - About 1 hr 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 formatDataTable has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function formatDataTable (elem, walk, builder, formatOptions) {
                  builder.openTable();
                  elem.children.forEach(walkTable);
                  const hasHeader = existsOne(
                    (el) => el.name === 'thead' || el.name === 'th',
                Severity: Minor
                Found in packages/html-to-md/src/md-formatters.js - About 1 hr to fix

                  Function findBases has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function findBases (dom, options, baseSelectorsPicker) {
                    const results = [];
                  
                    function recursiveWalk (walk, /** @type { DomNode[] } */ dom) {
                      dom = dom.slice(0, options.limits.maxChildNodes);
                  Severity: Minor
                  Found in packages/base/src/index.js - About 1 hr 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 formatAnchor has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function formatAnchor (elem, walk, builder, formatOptions) {
                    function getHref () {
                      if (formatOptions.ignoreHref) { return ''; }
                      if (!elem.attribs || !elem.attribs.href) { return ''; }
                      let href = elem.attribs.href.replace(/^mailto:/, '');
                  Severity: Minor
                  Found in packages/html-to-text/src/text-formatters.js - About 1 hr 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 tableToString has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function tableToString (tableRows, firstRowIsHeader, spanMode) {
                    if (
                      spanMode === 'tag' &&
                      tableRows.some(r => r[0] && (r[0].colspan > 1 || r[0].rowspan > 1))
                    ) {
                  Severity: Minor
                  Found in packages/html-to-md/src/table-printer.js - About 1 hr to fix

                    Function addLiteral has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                    Open

                      addLiteral (text, inlineTextBuilder, noWrap = true) {
                        if (!text) { return; }
                        const previouslyStashedSpace = inlineTextBuilder.stashedSpace;
                        let anyMatch = false;
                        let m = this.newlineOrNonNewlineStringRe.exec(text);
                    Severity: Minor
                    Found in packages/base/src/whitespace-processor.js - About 1 hr 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 walkTable has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      function walkTable (elem) {
                        if (elem.type !== 'tag') { return; }
                    
                        const formatHeaderCell = (formatOptions.uppercaseHeaderCells !== false)
                          ? (cellNode) => {
                    Severity: Minor
                    Found in packages/html-to-text/src/text-formatters.js - About 1 hr to fix
                      Severity
                      Category
                      Status
                      Source
                      Language