ckeditor/ckeditor5-engine

View on GitHub
src/model/operation/transform.js

Summary

Maintainability
F
6 days
Test Coverage

File transform.js has 950 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/operation/transform.js - About 2 days to fix

    Function updateRelation has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
    Open

        updateRelation( opA, opB ) {
            // The use of relations is described in a bigger detail in transformation functions.
            //
            // In brief, this function, for specified pairs of operation types, checks how positions defined in those operations relate.
            // Then those relations are saved. For example, for two move operations, it is saved if one of those operations target
    Severity: Minor
    Found in src/model/operation/transform.js - About 1 day 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 updateRelation has 102 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        updateRelation( opA, opB ) {
            // The use of relations is described in a bigger detail in transformation functions.
            //
            // In brief, this function, for specified pairs of operation types, checks how positions defined in those operations relate.
            // Then those relations are saved. For example, for two move operations, it is saved if one of those operations target
    Severity: Major
    Found in src/model/operation/transform.js - About 4 hrs to fix

      Function transformSets has 48 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function transformSets( operationsA, operationsB, options ) {
          // Create new arrays so the originally passed arguments are not changed.
          // No need to clone operations, they are cloned as they are transformed.
          operationsA = operationsA.slice();
          operationsB = operationsB.slice();
      Severity: Minor
      Found in src/model/operation/transform.js - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

            if (
                a.sourcePosition.isEqual( b.sourcePosition ) && !a.targetPosition.isEqual( b.targetPosition ) &&
                !context.bWasUndone && context.abRelation != 'splitAtSource'
            ) {
                const aToGraveyard = a.targetPosition.root.rootName == '$graveyard';
        Severity: Critical
        Found in src/model/operation/transform.js - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

              if ( a.graveyardPosition && b.graveyardPosition && a.graveyardPosition.isEqual( b.graveyardPosition ) ) {
                  const aInGraveyard = a.splitPosition.root.rootName == '$graveyard';
                  const bInGraveyard = b.splitPosition.root.rootName == '$graveyard';
          
                  // If `aIsWeak` it means that `a` points to graveyard while `b` doesn't. Don't move nodes then.
          Severity: Major
          Found in src/model/operation/transform.js - About 1 hr to fix

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

            export function transformSets( operationsA, operationsB, options ) {
                // Create new arrays so the originally passed arguments are not changed.
                // No need to clone operations, they are cloned as they are transformed.
                operationsA = operationsA.slice();
                operationsB = operationsB.slice();
            Severity: Minor
            Found in src/model/operation/transform.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 too many return statements within this function.
            Open

                return [ a ];
            Severity: Major
            Found in src/model/operation/transform.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                  return _makeMoveOperationsFromRanges( ranges, newTargetPosition );
              Severity: Major
              Found in src/model/operation/transform.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return [ a, moveOp ];
                Severity: Major
                Found in src/model/operation/transform.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return [ a ];
                  Severity: Major
                  Found in src/model/operation/transform.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return [ new NoOperation( 0 ) ];
                    Severity: Major
                    Found in src/model/operation/transform.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              return [ new NoOperation( a.baseVersion ) ];
                      Severity: Major
                      Found in src/model/operation/transform.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                            return [ a ];
                        Severity: Major
                        Found in src/model/operation/transform.js - About 30 mins to fix

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

                              if ( a.splitPosition.hasSameParentAs( b.position ) && a.splitPosition.offset < b.position.offset ) {
                                  a.howMany += b.howMany;
                              }
                          Severity: Major
                          Found in src/model/operation/transform.js and 1 other location - About 1 hr to fix
                          src/model/operation/transform.js on lines 2299..2301

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

                          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

                              if ( a.splitPosition.hasSameParentAs( b.splitPosition ) && a.splitPosition.offset < b.splitPosition.offset ) {
                                  a.howMany -= b.howMany;
                              }
                          Severity: Major
                          Found in src/model/operation/transform.js and 1 other location - About 1 hr to fix
                          src/model/operation/transform.js on lines 1977..1979

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

                          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

                                  if ( a.splitPosition.hasSameParentAs( b.sourcePosition ) && a.splitPosition.offset <= b.sourcePosition.offset ) {
                                      a.howMany -= b.howMany;
                                  }
                          Severity: Major
                          Found in src/model/operation/transform.js and 2 other locations - About 1 hr to fix
                          src/model/operation/transform.js on lines 2127..2129
                          src/model/operation/transform.js on lines 2162..2164

                          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

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

                                  if ( a.splitPosition.hasSameParentAs( b.targetPosition ) && a.splitPosition.offset < b.targetPosition.offset ) {
                                      a.howMany += b.howMany;
                                  }
                          Severity: Major
                          Found in src/model/operation/transform.js and 2 other locations - About 1 hr to fix
                          src/model/operation/transform.js on lines 2158..2160
                          src/model/operation/transform.js on lines 2162..2164

                          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

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

                                  if ( a.splitPosition.hasSameParentAs( b.targetPosition ) && a.splitPosition.offset < b.targetPosition.offset ) {
                                      a.howMany += b.howMany;
                                  }
                          Severity: Major
                          Found in src/model/operation/transform.js and 2 other locations - About 1 hr to fix
                          src/model/operation/transform.js on lines 2127..2129
                          src/model/operation/transform.js on lines 2158..2160

                          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

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

                              if ( a.targetPosition.isEqual( b.splitPosition ) ) {
                                  const mergeInside = b.howMany != 0;
                                  const mergeSplittingElement = b.graveyardPosition && a.deletionPosition.isEqual( b.graveyardPosition );
                          
                                  if ( mergeInside || mergeSplittingElement || context.abRelation == 'mergeTargetNotMoved' ) {
                          Severity: Minor
                          Found in src/model/operation/transform.js and 1 other location - About 55 mins to fix
                          src/model/operation/transform.js on lines 2040..2056

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

                          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

                                  if ( context.abRelation == 'mergeSameElement' || a.sourcePosition.offset > 0 ) {
                                      a.sourcePosition = b.moveTargetPosition.clone();
                                      a.targetPosition = a.targetPosition._getTransformedBySplitOperation( b );
                          
                                      return [ a ];
                          Severity: Minor
                          Found in src/model/operation/transform.js and 1 other location - About 55 mins to fix
                          src/model/operation/transform.js on lines 1863..1868

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

                          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

                              if ( !a.graveyardPosition && !context.bWasUndone && a.splitPosition.hasSameParentAs( b.sourcePosition ) ) {
                                  const splitPath = b.graveyardPosition.path.slice();
                                  splitPath.push( 0 );
                          
                                  const splitPosition = new Position( b.graveyardPosition.root, splitPath );
                          Severity: Minor
                          Found in src/model/operation/transform.js and 1 other location - About 55 mins to fix
                          src/model/operation/transform.js on lines 1436..1445

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

                          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

                                          } else {
                                              a.sourcePosition = b.graveyardPosition.clone();
                                              a.targetPosition = a.targetPosition._getTransformedByMergeOperation( b );
                          
                                              return [ a ];
                          Severity: Minor
                          Found in src/model/operation/transform.js and 1 other location - About 55 mins to fix
                          src/model/operation/transform.js on lines 1471..1476

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

                          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

                          setTransformation( InsertOperation, MoveOperation, ( a, b ) => {
                              // The default case.
                              //
                              a.position = a.position._getTransformedByMoveOperation( b );
                          
                          
                          Severity: Minor
                          Found in src/model/operation/transform.js and 1 other location - About 35 mins to fix
                          src/model/operation/transform.js on lines 1090..1096

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

                          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

                          setTransformation( InsertOperation, SplitOperation, ( a, b ) => {
                              // The default case.
                              //
                              a.position = a.position._getTransformedBySplitOperation( b );
                          
                          
                          Severity: Minor
                          Found in src/model/operation/transform.js and 1 other location - About 35 mins to fix
                          src/model/operation/transform.js on lines 1082..1088

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

                          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