ckeditor/ckeditor5-engine

View on GitHub
src/model/writer.js

Summary

Maintainability
F
5 days
Test Coverage

File writer.js has 543 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/writer.js - About 1 day to fix

    Writer has 44 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export default class Writer {
        /**
         * Creates a writer instance.
         *
         * **Note:** It is not recommended to use it directly. Use {@link module:engine/model/model~Model#change `Model#change()`} or
    Severity: Minor
    Found in src/model/writer.js - About 6 hrs to fix

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

          insert( item, itemOrPosition, offset = 0 ) {
              this._assertWriterUsedCorrectly();
      
              if ( item instanceof Text && item.data == '' ) {
                  return;
      Severity: Minor
      Found in src/model/writer.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 insert has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          insert( item, itemOrPosition, offset = 0 ) {
              this._assertWriterUsedCorrectly();
      
              if ( item instanceof Text && item.data == '' ) {
                  return;
      Severity: Minor
      Found in src/model/writer.js - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

                    if ( type === 'move' ) {
                        isAffected =
                            positionOrRange.containsPosition( markerRange.start ) ||
                            positionOrRange.start.isEqual( markerRange.start ) ||
                            positionOrRange.containsPosition( markerRange.end ) ||
        Severity: Critical
        Found in src/model/writer.js - About 1 hr to fix

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

              updateMarker( markerOrName, options ) {
                  this._assertWriterUsedCorrectly();
          
                  const markerName = typeof markerOrName == 'string' ? markerOrName : markerOrName.name;
                  const currentMarker = this.model.markers.get( markerName );
          Severity: Minor
          Found in src/model/writer.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 updateMarker has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              updateMarker( markerOrName, options ) {
                  this._assertWriterUsedCorrectly();
          
                  const markerName = typeof markerOrName == 'string' ? markerOrName : markerOrName.name;
                  const currentMarker = this.model.markers.get( markerName );
          Severity: Minor
          Found in src/model/writer.js - About 1 hr to fix

            Function split has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                split( position, limitElement ) {
                    this._assertWriterUsedCorrectly();
            
                    let splitElement = position.parent;
            
            
            Severity: Minor
            Found in src/model/writer.js - About 1 hr to fix

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

              function setAttributeOnRange( writer, key, value, range ) {
                  const model = writer.model;
                  const doc = model.document;
              
                  // Position of the last split, the beginning of the new range.
              Severity: Minor
              Found in src/model/writer.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 setAttributeOnItem has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

              function setAttributeOnItem( writer, key, value, item ) {
                  const model = writer.model;
                  const doc = model.document;
                  const previousValue = item.getAttribute( key );
                  let range, operation;
              Severity: Minor
              Found in src/model/writer.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 setAttributeOnRange has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function setAttributeOnRange( writer, key, value, range ) {
                  const model = writer.model;
                  const doc = model.document;
              
                  // Position of the last split, the beginning of the new range.
              Severity: Minor
              Found in src/model/writer.js - About 1 hr to fix

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

                    _addOperationForAffectedMarkers( type, positionOrRange ) {
                        for ( const marker of this.model.markers ) {
                            if ( !marker.managedUsingOperations ) {
                                continue;
                            }
                Severity: Minor
                Found in src/model/writer.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 split has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                    split( position, limitElement ) {
                        this._assertWriterUsedCorrectly();
                
                        let splitElement = position.parent;
                
                
                Severity: Minor
                Found in src/model/writer.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 applyMarkerOperation has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                function applyMarkerOperation( writer, name, oldRange, newRange, affectsData ) {
                Severity: Minor
                Found in src/model/writer.js - About 35 mins to fix

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

                      clearAttributes( itemOrRange ) {
                          this._assertWriterUsedCorrectly();
                  
                          const removeAttributesFromItem = item => {
                              for ( const attribute of item.getAttributeKeys() ) {
                  Severity: Minor
                  Found in src/model/writer.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 addMarker has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      addMarker( name, options ) {
                          this._assertWriterUsedCorrectly();
                  
                          if ( !options || typeof options.usingOperation != 'boolean' ) {
                              /**
                  Severity: Minor
                  Found in src/model/writer.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

                      insertText( text, attributes, itemOrPosition, offset ) {
                          if ( attributes instanceof DocumentFragment || attributes instanceof Element || attributes instanceof Position ) {
                              this.insert( this.createText( text ), attributes, itemOrPosition );
                          } else {
                              this.insert( this.createText( text, attributes ), itemOrPosition, offset );
                  Severity: Major
                  Found in src/model/writer.js and 1 other location - About 2 hrs to fix
                  src/model/writer.js on lines 288..294

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

                  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

                      insertElement( name, attributes, itemOrPosition, offset ) {
                          if ( attributes instanceof DocumentFragment || attributes instanceof Element || attributes instanceof Position ) {
                              this.insert( this.createElement( name ), attributes, itemOrPosition );
                          } else {
                              this.insert( this.createElement( name, attributes ), itemOrPosition, offset );
                  Severity: Major
                  Found in src/model/writer.js and 1 other location - About 2 hrs to fix
                  src/model/writer.js on lines 256..262

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

                  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

                      appendText( text, attributes, parent ) {
                          if ( attributes instanceof DocumentFragment || attributes instanceof Element ) {
                              this.insert( this.createText( text ), attributes, 'end' );
                          } else {
                              this.insert( this.createText( text, attributes ), parent, 'end' );
                  Severity: Major
                  Found in src/model/writer.js and 1 other location - About 2 hrs to fix
                  src/model/writer.js on lines 343..349

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

                  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

                      appendElement( name, attributes, parent ) {
                          if ( attributes instanceof DocumentFragment || attributes instanceof Element ) {
                              this.insert( this.createElement( name ), attributes, 'end' );
                          } else {
                              this.insert( this.createElement( name, attributes ), parent, 'end' );
                  Severity: Major
                  Found in src/model/writer.js and 1 other location - About 2 hrs to fix
                  src/model/writer.js on lines 325..331

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

                  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

                                      positionOrRange.containsPosition( markerRange.start ) ||
                                      positionOrRange.start.isEqual( markerRange.start ) ||
                                      positionOrRange.containsPosition( markerRange.end ) ||
                  Severity: Minor
                  Found in src/model/writer.js and 1 other location - About 40 mins to fix
                  src/model/liverange.js on lines 211..213

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

                  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