werk85/node-html-to-text

View on GitHub

Showing 85 of 85 total issues

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

          } else 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 89..93

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

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

  if (attribs.src && attribs.src.startsWith('data:')) {
    builder.startNoWrap();
    builder.addInline(
      render(elem, { decodeEntities: builder.options.decodeEntities }),
      { noWordTransform: true }
Severity: Major
Found in packages/html-to-md/src/md-formatters.js and 1 other location - About 1 hr to fix
packages/html-to-md/src/md-formatters.js on lines 136..144

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

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 (attribs.name && !attribs.href) {
    builder.startNoWrap();
    builder.addInline(
      render(elem, { decodeEntities: builder.options.decodeEntities }),
      { noWordTransform: true }
Severity: Major
Found in packages/html-to-md/src/md-formatters.js and 1 other location - About 1 hr to fix
packages/html-to-md/src/md-formatters.js on lines 103..111

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

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

  addInline (str, { noWordTransform = false } = {}) {
    if (!(
      this._stackItem instanceof BlockStackItem
      || this._stackItem instanceof ListItemStackItem
      || this._stackItem instanceof TableCellStackItem
Severity: Minor
Found in packages/base/src/block-text-builder.js - About 1 hr to fix

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

      for (const { node, prefix } of listItems) {
        builder.openListItem({ prefix: prefix });
        walk([node], builder);
        builder.closeListItem();
      }
    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 219..223

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

    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

      for (const { node, prefix } of listItems) {
        builder.openListItem({ prefix: prefix });
        walk([node], builder);
        builder.closeListItem();
      }
    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 202..206

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

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

    function formatList (elem, walk, builder, formatOptions, nextPrefixCallback) {
      const isNestedList = get(elem, ['parent', 'name']) === 'li';
    
      // With Roman numbers, index length is not as straightforward as with Arabic numbers or letters,
      // so the dumb length comparison is the most robust way to get the correct value.
    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 formatList has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    function formatList (elem, walk, builder, formatOptions, nextPrefixCallback) {
      const isNestedList = get(elem, ['parent', 'name']) === 'li';
    
      // With Roman numbers, index length is not as straightforward as with Arabic numbers or letters,
      // so the dumb length comparison is the most robust way to get the correct value.
    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 formatAnchor has 31 lines of code (exceeds 25 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

      Function formatAnchor has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function formatAnchor (elem, walk, builder, formatOptions) {
        const attribs = elem.attribs || {};
        if (attribs.name && !attribs.href) {
          builder.startNoWrap();
          builder.addInline(
      Severity: Minor
      Found in packages/html-to-md/src/md-formatters.js - About 1 hr to fix

        Function splitLongWord has 29 lines of code (exceeds 25 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 1 hr to fix

          Function compile has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function compile (options = {}) {
            const selectorsWithoutFormat = options.selectors.filter(s => !s.format);
            if (selectorsWithoutFormat.length) {
              throw new Error(
                'Following selectors have no specified format: ' +
          Severity: Minor
          Found in packages/base/src/index.js - About 1 hr to fix

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

              if (attribs.title) {
                builder.addLiteral(` "`);
                builder.addInline(attribs.title);
                builder.addLiteral(`"`);
              }
            Severity: Major
            Found in packages/html-to-md/src/md-formatters.js and 1 other location - About 1 hr to fix
            packages/html-to-md/src/md-formatters.js on lines 157..161

            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

                if (attribs.title) {
                  builder.addLiteral(` "`);
                  builder.addInline(attribs.title);
                  builder.addLiteral(`"`);
                }
            Severity: Major
            Found in packages/html-to-md/src/md-formatters.js and 1 other location - About 1 hr to fix
            packages/html-to-md/src/md-formatters.js on lines 120..124

            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

            Function findBases has 28 lines of code (exceeds 25 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

              Function collectDefinitionGroups has 28 lines of code (exceeds 25 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

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

                const selectorsMerge = (acc, src, options) => (
                  (acc.some(s => typeof s === 'object'))
                    ? concatMerge(acc, src, options) // selectors
                    : overwriteMerge(acc, src, options) // baseElements.selectors
                );
                Severity: Major
                Found in packages/html-to-md/src/html-to-md.js and 1 other location - About 1 hr to fix
                packages/html-to-text/src/html-to-text.js on lines 120..124

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

                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 selectorsMerge = (acc, src, options) => (
                  (acc.some(s => typeof s === 'object'))
                    ? concatMerge(acc, src, options) // selectors
                    : overwriteMerge(acc, src, options) // baseElements.selectors
                );
                Severity: Major
                Found in packages/html-to-text/src/html-to-text.js and 1 other location - About 1 hr to fix
                packages/html-to-md/src/html-to-md.js on lines 104..108

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

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

                  pushWord (word, noWrap = false) {
                    if (this.nextLineAvailableChars <= 0 && !noWrap) {
                      this.startNewLine();
                    }
                    const isLineStart = this.nextLineWords.length === 0;
                Severity: Minor
                Found in packages/base/src/inline-text-builder.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 renderRowsTag has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                function renderRowsTag (layout, colNumber, rowNumber) {
                  const outputLines = [];
                  for (let x = 0; x < colNumber; x++) {
                    for (let y = 0; y < rowNumber; y++) {
                      const cell = layout[x][y];
                Severity: Minor
                Found in packages/html-to-md/src/table-printer.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

                Severity
                Category
                Status
                Source
                Language