ckeditor/ckeditor5-engine

View on GitHub
src/view/domconverter.js

Summary

Maintainability
F
6 days
Test Coverage

File domconverter.js has 545 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
 */

Severity: Major
Found in src/view/domconverter.js - About 1 day to fix

    Function domToView has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

        domToView( domNode, options = {} ) {
            if ( this.isBlockFiller( domNode, this.blockFillerMode ) ) {
                return null;
            }
    
    
    Severity: Minor
    Found in src/view/domconverter.js - About 5 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

    DomConverter has 35 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export default class DomConverter {
        /**
         * Creates DOM converter.
         *
         * @param {module:engine/view/document~Document} document The view document instance.
    Severity: Minor
    Found in src/view/domconverter.js - About 4 hrs to fix

      Function viewToDom has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
      Open

          viewToDom( viewNode, domDocument, options = {} ) {
              if ( viewNode.is( 'text' ) ) {
                  const textData = this._processDataFromViewText( viewNode );
      
                  return domDocument.createTextNode( textData );
      Severity: Minor
      Found in src/view/domconverter.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

      Function domPositionToView has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

          domPositionToView( domParent, domOffset ) {
              if ( this.isBlockFiller( domParent, this.blockFillerMode ) ) {
                  return this.domPositionToView( domParent.parentNode, indexOf( domParent ) );
              }
      
      
      Severity: Minor
      Found in src/view/domconverter.js - About 3 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 viewPositionToDom has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          viewPositionToDom( viewPosition ) {
              const viewParent = viewPosition.parent;
      
              if ( viewParent.is( 'text' ) ) {
                  const domParent = this.findCorrespondingDomText( viewParent );
      Severity: Minor
      Found in src/view/domconverter.js - About 3 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 findCorrespondingViewText has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          findCorrespondingViewText( domText ) {
              if ( isInlineFiller( domText ) ) {
                  return null;
              }
      
      
      Severity: Minor
      Found in src/view/domconverter.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 domToView has 44 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          domToView( domNode, options = {} ) {
              if ( this.isBlockFiller( domNode, this.blockFillerMode ) ) {
                  return null;
              }
      
      
      Severity: Minor
      Found in src/view/domconverter.js - About 1 hr to fix

        Function viewToDom has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            viewToDom( viewNode, domDocument, options = {} ) {
                if ( viewNode.is( 'text' ) ) {
                    const textData = this._processDataFromViewText( viewNode );
        
                    return domDocument.createTextNode( textData );
        Severity: Minor
        Found in src/view/domconverter.js - About 1 hr to fix

          Function domPositionToView has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              domPositionToView( domParent, domOffset ) {
                  if ( this.isBlockFiller( domParent, this.blockFillerMode ) ) {
                      return this.domPositionToView( domParent.parentNode, indexOf( domParent ) );
                  }
          
          
          Severity: Minor
          Found in src/view/domconverter.js - About 1 hr to fix

            Function viewPositionToDom has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                viewPositionToDom( viewPosition ) {
                    const viewParent = viewPosition.parent;
            
                    if ( viewParent.is( 'text' ) ) {
                        const domParent = this.findCorrespondingDomText( viewParent );
            Severity: Minor
            Found in src/view/domconverter.js - About 1 hr to fix

              Function findCorrespondingViewText has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  findCorrespondingViewText( domText ) {
                      if ( isInlineFiller( domText ) ) {
                          return null;
                      }
              
              
              Severity: Minor
              Found in src/view/domconverter.js - About 1 hr to fix

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

                    _getTouchingInlineDomNode( node, getNext ) {
                        if ( !node.parentNode ) {
                            return null;
                        }
                
                
                Severity: Minor
                Found in src/view/domconverter.js - About 1 hr to fix

                  Function _getTouchingInlineDomNode has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      _getTouchingInlineDomNode( node, getNext ) {
                          if ( !node.parentNode ) {
                              return null;
                          }
                  
                  
                  Severity: Minor
                  Found in src/view/domconverter.js - About 55 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

                  Function domSelectionToView has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      domSelectionToView( domSelection ) {
                          // DOM selection might be placed in fake selection container.
                          // If container contains fake selection - return corresponding view selection.
                          if ( domSelection.rangeCount === 1 ) {
                              let container = domSelection.getRangeAt( 0 ).startContainer;
                  Severity: Minor
                  Found in src/view/domconverter.js - About 45 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

                  Function _processDataFromViewText has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      _processDataFromViewText( node ) {
                          let data = node.data;
                  
                          // If any of node ancestors has a name which is in `preElements` array, then currently processed
                          // view text node is (will be) in preformatted element. We should not change whitespaces then.
                  Severity: Minor
                  Found in src/view/domconverter.js - About 45 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

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

                      _getTouchingViewTextNode( node, getNext ) {
                          const treeWalker = new ViewTreeWalker( {
                              startPosition: getNext ? ViewPosition._createAfter( node ) : ViewPosition._createBefore( node ),
                              direction: getNext ? 'forward' : 'backward'
                          } );
                  Severity: Minor
                  Found in src/view/domconverter.js - 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

                  Avoid too many return statements within this function.
                  Open

                                      return new ViewPosition( viewParent, 0 );
                  Severity: Major
                  Found in src/view/domconverter.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                        return null;
                    Severity: Major
                    Found in src/view/domconverter.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return null;
                      Severity: Major
                      Found in src/view/domconverter.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                            return firstChild;
                        Severity: Major
                        Found in src/view/domconverter.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                      return { parent: domParent, offset };
                          Severity: Major
                          Found in src/view/domconverter.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                    return null;
                            Severity: Major
                            Found in src/view/domconverter.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                          return null;
                              Severity: Major
                              Found in src/view/domconverter.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                                    return null;
                                Severity: Major
                                Found in src/view/domconverter.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                                  return { parent: domAfter, offset: INLINE_FILLER_LENGTH };
                                  Severity: Major
                                  Found in src/view/domconverter.js - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                                        return new ViewPosition( viewBefore.parent, viewBefore.index + 1 );
                                    Severity: Major
                                    Found in src/view/domconverter.js - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                                      return this.mapDomToView( domNode );
                                      Severity: Major
                                      Found in src/view/domconverter.js - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                    return viewElement;
                                        Severity: Major
                                        Found in src/view/domconverter.js - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                      return new ViewPosition( viewParent, offset );
                                          Severity: Major
                                          Found in src/view/domconverter.js - About 30 mins to fix

                                            Function _processDataFromDomText has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                                _processDataFromDomText( node ) {
                                                    let data = node.data;
                                            
                                                    if ( _hasDomParentOfType( node, this.preElements ) ) {
                                                        return getDataWithoutFiller( node );
                                            Severity: Minor
                                            Found in src/view/domconverter.js - About 25 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 3 locations. Consider refactoring.
                                            Open

                                                bindElements( domElement, viewElement ) {
                                                    this._domToViewMapping.set( domElement, viewElement );
                                                    this._viewToDomMapping.set( viewElement, domElement );
                                                }
                                            Severity: Minor
                                            Found in src/view/domconverter.js and 2 other locations - About 35 mins to fix
                                            src/conversion/mapper.js on lines 133..136
                                            src/view/domconverter.js on lines 186..189

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

                                            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 3 locations. Consider refactoring.
                                            Open

                                                bindDocumentFragments( domFragment, viewFragment ) {
                                                    this._domToViewMapping.set( domFragment, viewFragment );
                                                    this._viewToDomMapping.set( viewFragment, domFragment );
                                                }
                                            Severity: Minor
                                            Found in src/view/domconverter.js and 2 other locations - About 35 mins to fix
                                            src/conversion/mapper.js on lines 133..136
                                            src/view/domconverter.js on lines 154..157

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

                                            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