ckeditor/ckeditor5-engine

View on GitHub
src/model/schema.js

Summary

Maintainability
D
3 days
Test Coverage

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

    Schema has 28 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export default class Schema {
        /**
         * Creates schema instance.
         */
        constructor() {
    Severity: Minor
    Found in src/model/schema.js - About 3 hrs to fix

      Function checkAttributeInSelection has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          checkAttributeInSelection( selection, attribute ) {
              if ( selection.isCollapsed ) {
                  const firstPosition = selection.getFirstPosition();
                  const context = [
                      ...firstPosition.getAncestors(),
      Severity: Minor
      Found in src/model/schema.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 combineWalkers has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      function* combineWalkers( backward, forward ) {
          let done = false;
      
          while ( !done ) {
              done = true;
      Severity: Minor
      Found in src/model/schema.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 getNearestSelectionRange has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          getNearestSelectionRange( position, direction = 'both' ) {
              // Return collapsed range if provided position is valid.
              if ( this.checkChild( position, '$text' ) ) {
                  return new Range( position );
              }
      Severity: Minor
      Found in src/model/schema.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 getNearestSelectionRange has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          getNearestSelectionRange( position, direction = 'both' ) {
              // Return collapsed range if provided position is valid.
              if ( this.checkChild( position, '$text' ) ) {
                  return new Range( position );
              }
      Severity: Minor
      Found in src/model/schema.js - About 1 hr to fix

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

        function compileInheritPropertiesFrom( compiledDefinitions, itemName ) {
            const item = compiledDefinitions[ itemName ];
        
            for ( const inheritPropertiesOfItem of item.inheritTypesFrom ) {
                const inheritFrom = compiledDefinitions[ inheritPropertiesOfItem ];
        Severity: Minor
        Found in src/model/schema.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 _getValidRangesForRange has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            * _getValidRangesForRange( range, attribute ) {
                let start = range.start;
                let end = range.start;
        
                for ( const item of range.getItems( { shallow: true } ) ) {
        Severity: Minor
        Found in src/model/schema.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 checkMerge has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            checkMerge( positionOrBaseElement, elementToMerge = null ) {
                if ( positionOrBaseElement instanceof Position ) {
                    const nodeBefore = positionOrBaseElement.nodeBefore;
                    const nodeAfter = positionOrBaseElement.nodeAfter;
        
        
        Severity: Minor
        Found in src/model/schema.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 removeDisallowedAttributes has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            removeDisallowedAttributes( nodes, writer ) {
                for ( const node of nodes ) {
                    // When node is a `Text` it has no children, so just filter it out.
                    if ( node.is( 'text' ) ) {
                        removeDisallowedAttributeFromNode( this, node, writer );
        Severity: Minor
        Found in src/model/schema.js - About 45 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 getLimitElement has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            getLimitElement( selectionOrRangeOrPosition ) {
                let element;
        
                if ( selectionOrRangeOrPosition instanceof Position ) {
                    element = selectionOrRangeOrPosition.parent;
        Severity: Minor
        Found in src/model/schema.js - About 45 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 _checkContextMatch has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            _checkContextMatch( def, context, contextItemIndex = context.length - 1 ) {
                const contextItem = context.getItem( contextItemIndex );
        
                if ( def.allowIn.includes( contextItem.name ) ) {
                    if ( contextItemIndex == 0 ) {
        Severity: Minor
        Found in src/model/schema.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

                if ( backward ) {
                    const step = backward.next();
        
                    if ( !step.done ) {
                        done = false;
        Severity: Major
        Found in src/model/schema.js and 1 other location - About 1 hr to fix
        src/model/schema.js on lines 1607..1617

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

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

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

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

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

        Refactorings

        Further Reading

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

                if ( forward ) {
                    const step = forward.next();
        
                    if ( !step.done ) {
                        done = false;
        Severity: Major
        Found in src/model/schema.js and 1 other location - About 1 hr to fix
        src/model/schema.js on lines 1595..1605

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

        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