ckeditor/ckeditor5-engine

View on GitHub
src/view/element.js

Summary

Maintainability
F
3 days
Test Coverage

Element has 34 functions (exceeds 20 allowed). Consider refactoring.
Open

export default class Element extends Node {
    /**
     * Creates a view element.
     *
     * Attributes can be passed in various formats:
Severity: Minor
Found in src/view/element.js - About 4 hrs to fix

    File element.js has 310 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/view/element.js - About 3 hrs to fix

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

          isSimilar( otherElement ) {
              if ( !( otherElement instanceof Element ) ) {
                  return false;
              }
      
      
      Severity: Minor
      Found in src/view/element.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

      Consider simplifying this complex logical expression.
      Open

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

        Function isSimilar has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            isSimilar( otherElement ) {
                if ( !( otherElement instanceof Element ) ) {
                    return false;
                }
        
        
        Severity: Minor
        Found in src/view/element.js - About 1 hr to fix

          Avoid too many return statements within this function.
          Open

                          return false;
          Severity: Major
          Found in src/view/element.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return true;
            Severity: Major
            Found in src/view/element.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return this._attrs.delete( key );
              Severity: Major
              Found in src/view/element.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                return false;
                Severity: Major
                Found in src/view/element.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                  return false;
                  Severity: Major
                  Found in src/view/element.js - About 30 mins to fix

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

                        _removeAttribute( key ) {
                            this._fireChange( 'attributes', this );
                    
                            // Remove class attribute.
                            if ( key == 'class' ) {
                    Severity: Minor
                    Found in src/view/element.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 getAttribute has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        getAttribute( key ) {
                            if ( key == 'class' ) {
                                if ( this._classes.size > 0 ) {
                                    return [ ...this._classes ].join( ' ' );
                                }
                    Severity: Minor
                    Found in src/view/element.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

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

                    function normalize( document, nodes ) {
                        // Separate condition because string is iterable.
                        if ( typeof nodes == 'string' ) {
                            return [ new Text( document, nodes ) ];
                        }
                    Severity: Major
                    Found in src/view/element.js and 1 other location - About 5 hrs to fix
                    src/view/documentfragment.js on lines 250..273

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

                    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

                        _removeChildren( index, howMany = 1 ) {
                            this._fireChange( 'children', this );
                    
                            for ( let i = index; i < index + howMany; i++ ) {
                                this._children[ i ].parent = null;
                    Severity: Major
                    Found in src/view/element.js and 1 other location - About 2 hrs to fix
                    src/view/documentfragment.js on lines 201..209

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

                    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

                        _removeStyle( property ) {
                            this._fireChange( 'attributes', this );
                    
                            property = Array.isArray( property ) ? property : [ property ];
                            property.forEach( name => this._styles.remove( name ) );
                    Severity: Major
                    Found in src/view/element.js and 2 other locations - About 2 hrs to fix
                    src/view/element.js on lines 727..732
                    src/view/element.js on lines 745..750

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

                    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

                        _addClass( className ) {
                            this._fireChange( 'attributes', this );
                    
                            className = Array.isArray( className ) ? className : [ className ];
                            className.forEach( name => this._classes.add( name ) );
                    Severity: Major
                    Found in src/view/element.js and 2 other locations - About 2 hrs to fix
                    src/view/element.js on lines 745..750
                    src/view/element.js on lines 792..797

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

                    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

                        _removeClass( className ) {
                            this._fireChange( 'attributes', this );
                    
                            className = Array.isArray( className ) ? className : [ className ];
                            className.forEach( name => this._classes.delete( name ) );
                    Severity: Major
                    Found in src/view/element.js and 2 other locations - About 2 hrs to fix
                    src/view/element.js on lines 727..732
                    src/view/element.js on lines 792..797

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

                    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

                        hasStyle( ...property ) {
                            for ( const name of property ) {
                                if ( !this._styles.has( name ) ) {
                                    return false;
                                }
                    Severity: Major
                    Found in src/view/element.js and 1 other location - About 1 hr to fix
                    src/view/element.js on lines 362..370

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

                    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

                        hasClass( ...className ) {
                            for ( const name of className ) {
                                if ( !this._classes.has( name ) ) {
                                    return false;
                                }
                    Severity: Major
                    Found in src/view/element.js and 1 other location - About 1 hr to fix
                    src/view/element.js on lines 463..471

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

                    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