ckeditor/ckeditor5-engine

View on GitHub
src/model/differ.js

Summary

Maintainability
F
1 wk
Test Coverage

Function _handleChange has a Cognitive Complexity of 111 (exceeds 5 allowed). Consider refactoring.
Open

    _handleChange( inc, changes ) {
        // We need a helper variable that will store how many nodes are to be still handled for this change item.
        // `nodesToHandle` (how many nodes still need to be handled) and `howMany` (how many nodes were affected)
        // needs to be differentiated.
        //
Severity: Minor
Found in src/model/differ.js - About 2 days 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 differ.js has 592 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/model/differ.js - About 1 day to fix

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

        getChanges( options = { includeChangesInGraveyard: false } ) {
            // If there are cached changes, just return them instead of calculating changes again.
            if ( this._cachedChanges ) {
                if ( options.includeChangesInGraveyard ) {
                    return this._cachedChangesWithGraveyard.slice();
    Severity: Minor
    Found in src/model/differ.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 _handleChange has 141 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        _handleChange( inc, changes ) {
            // We need a helper variable that will store how many nodes are to be still handled for this change item.
            // `nodesToHandle` (how many nodes still need to be handled) and `howMany` (how many nodes were affected)
            // needs to be differentiated.
            //
    Severity: Major
    Found in src/model/differ.js - About 5 hrs to fix

      Function bufferOperation has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
      Open

          bufferOperation( operation ) {
              // Below we take an operation, check its type, then use its parameters in marking (private) methods.
              // The general rule is to not mark elements inside inserted element. All inserted elements are re-rendered.
              // Marking changes in them would cause a "double" changing then.
              //
      Severity: Minor
      Found in src/model/differ.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 getChanges has 102 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          getChanges( options = { includeChangesInGraveyard: false } ) {
              // If there are cached changes, just return them instead of calculating changes again.
              if ( this._cachedChanges ) {
                  if ( options.includeChangesInGraveyard ) {
                      return this._cachedChangesWithGraveyard.slice();
      Severity: Major
      Found in src/model/differ.js - About 4 hrs to fix

        Function bufferOperation has 79 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            bufferOperation( operation ) {
                // Below we take an operation, check its type, then use its parameters in marking (private) methods.
                // The general rule is to not mark elements inside inserted element. All inserted elements are re-rendered.
                // Marking changes in them would cause a "double" changing then.
                //
        Severity: Major
        Found in src/model/differ.js - About 3 hrs to fix

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

          function _generateActionsFromChanges( oldChildrenLength, changes ) {
              const actions = [];
          
              let offset = 0;
              let oldChildrenHandled = 0;
          Severity: Minor
          Found in src/model/differ.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

          Differ has 23 functions (exceeds 20 allowed). Consider refactoring.
          Open

          export default class Differ {
              /**
               * Creates a `Differ` instance.
               *
               * @param {module:engine/model/markercollection~MarkerCollection} markerCollection Model's marker collection.
          Severity: Minor
          Found in src/model/differ.js - About 2 hrs to fix

            Function _generateActionsFromChanges has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function _generateActionsFromChanges( oldChildrenLength, changes ) {
                const actions = [];
            
                let offset = 0;
                let oldChildrenHandled = 0;
            Severity: Minor
            Found in src/model/differ.js - About 1 hr to fix

              Function _getAttributesDiff has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  _getAttributesDiff( range, oldAttributes, newAttributes ) {
                      // Results holder.
                      const diffs = [];
              
                      // Clone new attributes as we will be performing changes on this object.
              Severity: Minor
              Found in src/model/differ.js - About 1 hr to fix

                Avoid deeply nested control flow statements.
                Open

                                        if ( inc.offset <= old.offset ) {
                                            inc.nodesToHandle -= old.howMany;
                                            old.howMany = 0;
                                        } else if ( inc.offset < oldEnd ) {
                                            const intersectionLength = oldEnd - inc.offset;
                Severity: Major
                Found in src/model/differ.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          if ( incEnd <= oldEnd ) {
                                              // On first sight in this case we don't need to split attribute operation into two.
                                              // However the changes set is later converted to actions (see `_generateActionsFromChanges`).
                                              // For that reason, no two changes may intersect.
                                              // So we cannot have an attribute change that "contains" remove change.
                  Severity: Major
                  Found in src/model/differ.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                            if ( inc.offset < old.offset ) {
                                                const intersectionLength = incEnd - old.offset;
                    
                                                old.offset = inc.offset;
                    
                    
                    Severity: Major
                    Found in src/model/differ.js - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                          } else if ( inc.offset >= old.offset && inc.offset < oldEnd ) {
                                              if ( incEnd > oldEnd ) {
                                                  inc.nodesToHandle = incEnd - oldEnd;
                                                  inc.offset = oldEnd;
                                              } else {
                      Severity: Major
                      Found in src/model/differ.js - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                                if ( incEnd > oldEnd ) {
                                                    // This case is similar to a case described when incoming change was insert and old change was attribute.
                                                    // See comment above.
                                                    //
                                                    // This time incoming change is attribute. We need to split incoming change in this case too.
                        Severity: Major
                        Found in src/model/differ.js - About 45 mins to fix

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

                              _isInInsertedElement( element ) {
                                  const parent = element.parent;
                          
                                  if ( !parent ) {
                                      return false;
                          Severity: Minor
                          Found in src/model/differ.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 _getChildrenSnapshot has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                          function _getChildrenSnapshot( children ) {
                              const snapshot = [];
                          
                              for ( const child of children ) {
                                  if ( child.is( 'text' ) ) {
                          Severity: Minor
                          Found in src/model/differ.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 _getAttributesDiff has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              _getAttributesDiff( range, oldAttributes, newAttributes ) {
                                  // Results holder.
                                  const diffs = [];
                          
                                  // Clone new attributes as we will be performing changes on this object.
                          Severity: Minor
                          Found in src/model/differ.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 2 locations. Consider refactoring.
                          Open

                              getMarkersToAdd() {
                                  const result = [];
                          
                                  for ( const [ name, change ] of this._changedMarkers ) {
                                      if ( change.newRange != null ) {
                          Severity: Major
                          Found in src/model/differ.js and 1 other location - About 2 hrs to fix
                          src/model/differ.js on lines 301..311

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

                          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

                              getMarkersToRemove() {
                                  const result = [];
                          
                                  for ( const [ name, change ] of this._changedMarkers ) {
                                      if ( change.oldRange != null ) {
                          Severity: Major
                          Found in src/model/differ.js and 1 other location - About 2 hrs to fix
                          src/model/differ.js on lines 318..328

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

                          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

                              _getRemoveDiff( parent, offset, name ) {
                                  return {
                                      type: 'remove',
                                      position: Position._createAt( parent, offset ),
                                      name,
                          Severity: Major
                          Found in src/model/differ.js and 1 other location - About 1 hr to fix
                          src/model/differ.js on lines 898..906

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

                          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

                              _getInsertDiff( parent, offset, name ) {
                                  return {
                                      type: 'insert',
                                      position: Position._createAt( parent, offset ),
                                      name,
                          Severity: Major
                          Found in src/model/differ.js and 1 other location - About 1 hr to fix
                          src/model/differ.js on lines 917..925

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

                          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

                                          prevDiff.type == 'insert' && thisDiff.type == 'insert' &&
                                          prevDiff.name == '$text' && thisDiff.name == '$text' &&
                                          prevDiff.position.parent == thisDiff.position.parent &&
                          Severity: Minor
                          Found in src/model/differ.js and 1 other location - About 35 mins to fix
                          src/model/differ.js on lines 492..494

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

                                          prevDiff.type == 'remove' && thisDiff.type == 'remove' &&
                                          prevDiff.name == '$text' && thisDiff.name == '$text' &&
                                          prevDiff.position.isEqual( thisDiff.position );
                          Severity: Minor
                          Found in src/model/differ.js and 1 other location - About 35 mins to fix
                          src/model/differ.js on lines 498..500

                          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