ckeditor/ckeditor5-engine

View on GitHub
src/model/range.js

Summary

Maintainability
F
5 days
Test Coverage

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

export default class Range {
    /**
     * Creates a range spanning from `start` position to `end` position.
     *
     * @param {module:engine/model/position~Position} start Start position.
Severity: Minor
Found in src/model/range.js - About 4 hrs to fix

    File range.js has 348 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/model/range.js - About 4 hrs to fix

      Function _getTransformedByMove has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          _getTransformedByMove( sourcePosition, targetPosition, howMany, spread = false ) {
              // Special case for transforming a collapsed range. Just transform it like a position.
              if ( this.isCollapsed ) {
                  const newPos = this.start._getTransformedByMove( sourcePosition, targetPosition, howMany );
      
      
      Severity: Minor
      Found in src/model/range.js - About 1 hr to fix

        Function _createFromRanges has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            static _createFromRanges( ranges ) {
                if ( ranges.length === 0 ) {
                    /**
                     * At least one range has to be passed to
                     * {@link module:engine/model/range~Range._createFromRanges `Range._createFromRanges()`}.
        Severity: Minor
        Found in src/model/range.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 _getTransformedByMove has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            _getTransformedByMove( sourcePosition, targetPosition, howMany, spread = false ) {
                // Special case for transforming a collapsed range. Just transform it like a position.
                if ( this.isCollapsed ) {
                    const newPos = this.start._getTransformedByMove( sourcePosition, targetPosition, howMany );
        
        
        Severity: Minor
        Found in src/model/range.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 _createFromRanges has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static _createFromRanges( ranges ) {
                if ( ranges.length === 0 ) {
                    /**
                     * At least one range has to be passed to
                     * {@link module:engine/model/range~Range._createFromRanges `Range._createFromRanges()`}.
        Severity: Minor
        Found in src/model/range.js - About 1 hr to fix

          Function getTransformedByOperations has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              getTransformedByOperations( operations ) {
                  const ranges = [ new Range( this.start, this.end ) ];
          
                  for ( const operation of operations ) {
                      for ( let i = 0; i < ranges.length; i++ ) {
          Severity: Minor
          Found in src/model/range.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 _getTransformedByMergeOperation has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              _getTransformedByMergeOperation( operation ) {
                  // Special case when the marker is set on "the closing tag" of an element. Marker can be set like that during
                  // transformations, especially when a content of a few block elements were removed. For example:
                  //
                  // {} is the transformed range, [] is the removed range.
          Severity: Minor
          Found in src/model/range.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 getDifference has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              getDifference( otherRange ) {
                  const ranges = [];
          
                  if ( this.isIntersecting( otherRange ) ) {
                      // Ranges intersect.
          Severity: Minor
          Found in src/model/range.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

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

              getMinimalFlatRanges() {
                  const ranges = [];
                  const diffAt = this.start.getCommonPath( this.end ).length;
          
                  const pos = Position._createAt( this.start );
          Severity: Minor
          Found in src/model/range.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

              getIntersection( otherRange ) {
                  if ( this.isIntersecting( otherRange ) ) {
                      // Ranges intersect, so a common range will be returned.
                      // At most, it will be same as this range.
                      let commonRangeStart = this.start;
          Severity: Major
          Found in src/model/range.js and 1 other location - About 4 hrs to fix
          src/view/range.js on lines 286..310

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

          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

              containsRange( otherRange, loose = false ) {
                  if ( otherRange.isCollapsed ) {
                      loose = false;
                  }
          
          
          Severity: Major
          Found in src/model/range.js and 1 other location - About 4 hrs to fix
          src/view/range.js on lines 198..207

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

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

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

                  if ( this.isIntersecting( otherRange ) ) {
                      // Ranges intersect.
          
                      if ( this.containsPosition( otherRange.start ) ) {
                          // Given range start is inside this range. This means that we have to
          Severity: Major
          Found in src/model/range.js and 1 other location - About 3 hrs to fix
          src/view/range.js on lines 243..260

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

          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

              * getItems( options = {} ) {
                  options.boundaries = this;
                  options.ignoreElementEnd = true;
          
                  const treeWalker = new TreeWalker( options );
          Severity: Major
          Found in src/model/range.js and 1 other location - About 1 hr to fix
          src/view/range.js on lines 400..409

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

          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

              * getPositions( options = {} ) {
                  options.boundaries = this;
          
                  const treeWalker = new TreeWalker( options );
          
          
          Severity: Major
          Found in src/model/range.js and 1 other location - About 1 hr to fix
          src/view/range.js on lines 424..434

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

          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

                      for ( let i = refIndex - 1; true; i++ ) {
                          if ( ranges[ i ].end.isEqual( result.start ) ) {
                              result.start = Position._createAt( ranges[ i ].start );
                          } else {
                              // If ranges are not starting/ending at the same position there is no point in looking further.
          Severity: Major
          Found in src/model/range.js and 1 other location - About 1 hr to fix
          src/model/range.js on lines 960..967

          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

                  for ( let i = refIndex + 1; i < ranges.length; i++ ) {
                      if ( ranges[ i ].start.isEqual( result.end ) ) {
                          result.end = Position._createAt( ranges[ i ].end );
                      } else {
                          // If ranges are not starting/ending at the same position there is no point in looking further.
          Severity: Major
          Found in src/model/range.js and 1 other location - About 1 hr to fix
          src/model/range.js on lines 948..955

          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

              static _createFromPositionAndShift( position, shift ) {
                  const start = position;
                  const end = position.getShiftedBy( shift );
          
                  return shift > 0 ? new this( start, end ) : new this( end, start );
          Severity: Major
          Found in src/model/range.js and 1 other location - About 1 hr to fix
          src/view/range.js on lines 493..498

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

              isIntersecting( otherRange ) {
                  return this.start.isBefore( otherRange.end ) && this.end.isAfter( otherRange.start );
              }
          Severity: Major
          Found in src/model/range.js and 2 other locations - About 50 mins to fix
          src/model/range.js on lines 170..172
          src/view/range.js on lines 461..463

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

          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

              isEqual( otherRange ) {
                  return this.start.isEqual( otherRange.start ) && this.end.isEqual( otherRange.end );
              }
          Severity: Major
          Found in src/model/range.js and 2 other locations - About 50 mins to fix
          src/model/range.js on lines 180..182
          src/view/range.js on lines 461..463

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

          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