werk85/node-html-to-text

View on GitHub

Showing 85 of 85 total issues

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

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

          function pathRewrite (path, rewriter, baseUrl, metadata, elem) {
            const modifiedPath = (typeof rewriter === 'function')
              ? rewriter(path, metadata, elem)
              : path;
            return (modifiedPath[0] === '/' && baseUrl)
          Severity: Major
          Found in packages/html-to-text/src/text-formatters.js and 1 other location - About 1 hr to fix
          packages/html-to-md/src/md-formatters.js on lines 87..94

          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

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

          function pathRewrite (path, rewriter, baseUrl, metadata, elem) {
            const modifiedPath = (typeof rewriter === 'function')
              ? rewriter(path, metadata, elem)
              : path;
            return (modifiedPath[0] === '/' && baseUrl)
          Severity: Major
          Found in packages/html-to-md/src/md-formatters.js and 1 other location - About 1 hr to fix
          packages/html-to-text/src/text-formatters.js on lines 113..120

          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

          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

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

            module.exports = {
              input: 'src/html-to-md.js',
              output: [
                { file: 'lib/html-to-md.mjs', format: 'es' },
                { file: 'lib/html-to-md.cjs', format: 'cjs' }
            Severity: Major
            Found in packages/html-to-md/rollup.config.js and 1 other location - About 1 hr to fix
            packages/html-to-text/rollup.config.js on lines 8..17

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

            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

            module.exports = {
              input: 'src/html-to-text.js',
              output: [
                { file: 'lib/html-to-text.mjs', format: 'es' },
                { file: 'lib/html-to-text.cjs', format: 'cjs' },
            Severity: Major
            Found in packages/html-to-text/rollup.config.js and 1 other location - About 1 hr to fix
            packages/html-to-md/rollup.config.js on lines 8..17

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

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

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

            function formatBlock (elem, walk, builder, formatOptions) {
              builder.openBlock({ leadingLineBreaks: formatOptions.leadingLineBreaks || 2 });
              walk(elem.children, builder);
              builder.closeBlock({ trailingLineBreaks: formatOptions.trailingLineBreaks || 2 });
            }
            Severity: Major
            Found in packages/base/src/generic-formatters.js and 1 other location - About 1 hr to fix
            packages/html-to-text/src/text-formatters.js on lines 44..48

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

            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

            function formatParagraph (elem, walk, builder, formatOptions) {
              builder.openBlock({ leadingLineBreaks: formatOptions.leadingLineBreaks || 2 });
              walk(elem.children, builder);
              builder.closeBlock({ trailingLineBreaks: formatOptions.trailingLineBreaks || 2 });
            }
            Severity: Major
            Found in packages/html-to-text/src/text-formatters.js and 1 other location - About 1 hr to fix
            packages/base/src/generic-formatters.js on lines 51..55

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

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

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

                        if (previouslyStashedSpace || this.testLeadingWhitespace(text)) {
                          inlineTextBuilder.pushWord(transform(m[0]), noWrap);
                        } else {
                          inlineTextBuilder.concatWord(transform(m[0]), noWrap);
                        }
              Severity: Major
              Found in packages/base/src/whitespace-processor.js and 1 other location - About 1 hr to fix
              packages/base/src/whitespace-processor.js on lines 60..64

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

              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 handleDeprecatedOptions has 35 lines of code (exceeds 25 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
                Severity
                Category
                Status
                Source
                Language