ckeditor/ckeditor5-engine

View on GitHub

Showing 564 of 564 total issues

Function _previous has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    _previous() {
        const previousPosition = this.position;
        const position = this.position.clone();
        const parent = this._visitedParent;

Severity: Minor
Found in src/model/treewalker.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

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

Function _getPositions has 68 lines of code (exceeds 25 allowed). Consider refactoring.
Open

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

    Function _next has 67 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        _next() {
            let position = this.position.clone();
            const previousPosition = this.position;
            const parent = position.parent;
    
    
    Severity: Major
    Found in src/view/treewalker.js - About 2 hrs to fix

      Consider simplifying this complex logical expression.
      Open

              if ( !name ) {
                  return type === 'containerElement' || type === 'view:containerElement' ||
                      // From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
                      type === this.name || type === 'view:' + this.name ||
                      type === 'element' || type === 'view:element' ||
      Severity: Critical
      Found in src/view/containerelement.js - About 2 hrs to fix

        Consider simplifying this complex logical expression.
        Open

                if ( !name ) {
                    return type === 'attributeElement' || type === 'view:attributeElement' ||
                        // From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
                        type === this.name || type === 'view:' + this.name ||
                        type === 'element' || type === 'view:element' ||
        Severity: Critical
        Found in src/view/attributeelement.js - About 2 hrs to fix

          Consider simplifying this complex logical expression.
          Open

                  if ( !name ) {
                      return type === 'uiElement' || type === 'view:uiElement' ||
                          // From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
                          type === this.name || type === 'view:' + this.name ||
                          type === 'element' || type === 'view:element' ||
          Severity: Critical
          Found in src/view/uielement.js - About 2 hrs to fix

            Selection has 24 functions (exceeds 20 allowed). Consider refactoring.
            Open

            export default class Selection {
                /**
                 * Creates new selection instance.
                 *
                 * **Note**: The selection constructor is available as a factory method:
            Severity: Minor
            Found in src/view/selection.js - About 2 hrs to fix

              Consider simplifying this complex logical expression.
              Open

                      if ( !name ) {
                          return type === 'emptyElement' || type === 'view:emptyElement' ||
                              // From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
                              type === this.name || type === 'view:' + this.name ||
                              type === 'element' || type === 'view:element' ||
              Severity: Critical
              Found in src/view/emptyelement.js - About 2 hrs to fix

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

                export default class Range {
                    /**
                     * Creates a range spanning from `start` position to `end` position.
                     *
                     * **Note:** Constructor creates it's own {@link module:engine/view/position~Position} instances basing on passed values.
                Severity: Minor
                Found in src/view/range.js - About 2 hrs to fix

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

                      getLastRange() {
                          let last = null;
                  
                          for ( const range of this._ranges ) {
                              if ( !last || range.end.isAfter( last.end ) ) {
                  Severity: Major
                  Found in src/view/selection.js and 1 other location - About 2 hrs to fix
                  src/view/selection.js on lines 249..259

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

                  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

                      getFirstRange() {
                          let first = null;
                  
                          for ( const range of this._ranges ) {
                              if ( !first || range.start.isBefore( first.start ) ) {
                  Severity: Major
                  Found in src/view/selection.js and 1 other location - About 2 hrs to fix
                  src/view/selection.js on lines 268..278

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

                  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

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

                      _next() {
                          const previousPosition = this.position;
                          const position = this.position.clone();
                          const parent = this._visitedParent;
                  
                  
                  Severity: Minor
                  Found in src/model/treewalker.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 _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

                  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 addBorderRules has 64 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  export function addBorderRules( stylesProcessor ) {
                      stylesProcessor.setNormalizer( 'border', borderNormalizer );
                  
                      // Border-position shorthands.
                      stylesProcessor.setNormalizer( 'border-top', getBorderPositionNormalizer( 'top' ) );
                  Severity: Major
                  Found in src/view/styles/border.js - About 2 hrs to fix

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

                    export default class Renderer {
                        /**
                         * Creates a renderer instance.
                         *
                         * @param {module:engine/view/domconverter~DomConverter} domConverter Converter instance.
                    Severity: Minor
                    Found in src/view/renderer.js - About 2 hrs to fix

                      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

                        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

                        Severity
                        Category
                        Status
                        Source
                        Language