ckeditor/ckeditor5-engine

View on GitHub
src/dev-utils/view.js

Summary

Maintainability
F
3 days
Test Coverage

File view.js has 457 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: Minor
Found in src/dev-utils/view.js - About 7 hrs to fix

    Function _getPositions has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
    Open

        _getPositions( node ) {
            if ( node.is( 'documentFragment' ) || node.is( 'element' ) ) {
                // Copy elements into the array, when nodes will be removed from parent node this array will still have all the
                // items needed for iteration.
                const children = [ ...node.getChildren() ];
    Severity: Minor
    Found in src/dev-utils/view.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 _getPositions has 68 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        _getPositions( node ) {
            if ( node.is( 'documentFragment' ) || node.is( 'element' ) ) {
                // Copy elements into the array, when nodes will be removed from parent node this array will still have all the
                // items needed for iteration.
                const children = [ ...node.getChildren() ];
    Severity: Major
    Found in src/dev-utils/view.js - About 2 hrs to fix

      Function _walkView has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          _walkView( root, callback ) {
              const ignore = this.ignoreRoot && this.root === root;
      
              if ( root.is( 'element' ) || root.is( 'documentFragment' ) ) {
                  if ( root.is( 'element' ) && !ignore ) {
      Severity: Minor
      Found in src/dev-utils/view.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 _convertViewElements has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      function _convertViewElements( rootNode ) {
          if ( rootNode.is( 'element' ) || rootNode.is( 'documentFragment' ) ) {
              // Convert element or leave document fragment.
      
              const convertedElement = rootNode.is( 'documentFragment' ) ?
      Severity: Minor
      Found in src/dev-utils/view.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 _createRanges has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          _createRanges() {
              const ranges = [];
              let range = null;
      
              for ( const item of this._positions ) {
      Severity: Minor
      Found in src/dev-utils/view.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 _stringifyTextRanges has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          _stringifyTextRanges( node ) {
              const length = node.data.length;
              let result = node.data.split( '' );
              let rangeStartToken, rangeEndToken;
      
      
      Severity: Minor
      Found in src/dev-utils/view.js - About 1 hr to fix

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

        export function parse( data, options = {} ) {
            const viewDocument = new ViewDocument( new StylesProcessor() );
        
            options.order = options.order || [];
            const rangeParser = new RangeParser( {
        Severity: Minor
        Found in src/dev-utils/view.js - About 1 hr to fix

          Function _stringifyTextRanges has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              _stringifyTextRanges( node ) {
                  const length = node.data.length;
                  let result = node.data.split( '' );
                  let rangeStartToken, rangeEndToken;
          
          
          Severity: Minor
          Found in src/dev-utils/view.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 _stringifyElementRanges has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              _stringifyElementRanges( element, offset ) {
                  let start = '';
                  let end = '';
                  let collapsed = '';
          
          
          Severity: Minor
          Found in src/dev-utils/view.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

          Avoid deeply nested control flow statements.
          Open

                                  if ( !this.sameSelectionCharacters && item.textOffset !== 0 && item.textOffset !== text.length ) {
                                      throw new Error( `Parse error - range delimiter '${ item.bracket }' is placed inside text node.` );
                                  }
          Severity: Major
          Found in src/dev-utils/view.js - About 45 mins to fix

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

            function _convertElement( viewDocument, viewElement ) {
                const info = _convertElementNameAndInfo( viewElement );
                const ElementConstructor = allowedTypes[ info.type ];
                const newElement = ElementConstructor ? new ElementConstructor( viewDocument, info.name ) : new ViewElement( viewDocument, info.name );
            
            
            Severity: Minor
            Found in src/dev-utils/view.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

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

                _stringifyElementType( element ) {
                    if ( this.showType ) {
                        for ( const type in allowedTypes ) {
                            if ( element instanceof allowedTypes[ type ] ) {
                                return type;
            Severity: Minor
            Found in src/dev-utils/view.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

            There are no issues that match your filters.

            Category
            Status