ckeditor/ckeditor5-list

View on GitHub
src/converters.js

Summary

Maintainability
F
5 days
Test Coverage

Function modelChangePostFixer has a Cognitive Complexity of 76 (exceeds 5 allowed). Consider refactoring.
Open

export function modelChangePostFixer( model, writer ) {
    const changes = model.document.differ.getChanges();
    const itemToListHead = new Map();

    let applied = false;
Severity: Minor
Found in src/converters.js - About 1 day 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

File converters.js has 461 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/converters.js - About 7 hrs to fix

    Function modelChangePostFixer has 109 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function modelChangePostFixer( model, writer ) {
        const changes = model.document.differ.getChanges();
        const itemToListHead = new Map();
    
        let applied = false;
    Severity: Major
    Found in src/converters.js - About 4 hrs to fix

      Function modelViewSplitOnInsert has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

      export function modelViewSplitOnInsert( evt, data, conversionApi ) {
          if ( data.item.name != 'listItem' ) {
              let viewPosition = conversionApi.mapper.toViewPosition( data.range.start );
      
              const viewWriter = conversionApi.writer;
      Severity: Minor
      Found in src/converters.js - About 3 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 cleanListItem has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

      export function cleanListItem( evt, data, conversionApi ) {
          if ( conversionApi.consumable.test( data.viewItem, { name: true } ) ) {
              if ( data.viewItem.childCount === 0 ) {
                  return;
              }
      Severity: Minor
      Found in src/converters.js - About 3 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 modelIndentPasteFixer has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

      export function modelIndentPasteFixer( evt, [ content, selectable ] ) {
          // Check whether inserted content starts from a `listItem`. If it does not, it means that there are some other
          // elements before it and there is no need to fix indents, because even if we insert that content into a list,
          // that list will be broken.
          // Note: we also need to handle singular elements because inserting item with indent 0 into 0,1,[],2
      Severity: Minor
      Found in src/converters.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 viewToModelListItemChildrenConverter has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      function viewToModelListItemChildrenConverter( listItemModel, viewChildren, conversionApi ) {
          const { writer, schema } = conversionApi;
      
          // A position after the last inserted `listItem`.
          let nextPosition = writer.createPositionAfter( listItemModel );
      Severity: Minor
      Found in src/converters.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 modelViewSplitOnInsert has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function modelViewSplitOnInsert( evt, data, conversionApi ) {
          if ( data.item.name != 'listItem' ) {
              let viewPosition = conversionApi.mapper.toViewPosition( data.range.start );
      
              const viewWriter = conversionApi.writer;
      Severity: Minor
      Found in src/converters.js - About 1 hr to fix

        Function viewToModelPosition has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function viewToModelPosition( model ) {
            return ( evt, data ) => {
                const viewPos = data.viewPosition;
                const viewParent = viewPos.parent;
                const mapper = data.mapper;
        Severity: Minor
        Found in src/converters.js - About 1 hr to fix

          Function hoistNestedLists has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function hoistNestedLists( nextIndent, modelRemoveStartPosition, viewRemoveStartPosition, viewRemovedItem, conversionApi, model ) {
              // Find correct previous model list item element.
              // The element has to have either same or smaller indent than given reference indent.
              // This will be the model element which will get nested items (if it has smaller indent) or sibling items (if it has same indent).
              // Keep in mind that such element might not be found, if removed item was the first item.
          Severity: Minor
          Found in src/converters.js - About 1 hr to fix

            Function viewModelConverter has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            export function viewModelConverter( evt, data, conversionApi ) {
                if ( conversionApi.consumable.consume( data.viewItem, { name: true } ) ) {
                    const writer = conversionApi.writer;
            
                    // 1. Create `listItem` model element.
            Severity: Minor
            Found in src/converters.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 hoistNestedLists has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            function hoistNestedLists( nextIndent, modelRemoveStartPosition, viewRemoveStartPosition, viewRemovedItem, conversionApi, model ) {
            Severity: Minor
            Found in src/converters.js - About 45 mins to fix

              Function getIndent has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              function getIndent( listItem ) {
                  let indent = 0;
              
                  let parent = listItem.parent;
              
              
              Severity: Minor
              Found in src/converters.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

              Avoid deeply nested control flow statements.
              Open

                                  if ( mergePos && mergePos.parent == previousList ) {
                                      viewPosition.offset--;
                                  }
              Severity: Major
              Found in src/converters.js - About 45 mins to fix

                Function hoistNestedLists has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                function hoistNestedLists( nextIndent, modelRemoveStartPosition, viewRemoveStartPosition, viewRemovedItem, conversionApi, model ) {
                    // Find correct previous model list item element.
                    // The element has to have either same or smaller indent than given reference indent.
                    // This will be the model element which will get nested items (if it has smaller indent) or sibling items (if it has same indent).
                    // Keep in mind that such element might not be found, if removed item was the first item.
                Severity: Minor
                Found in src/converters.js - About 35 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 cleanList has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                export function cleanList( evt, data, conversionApi ) {
                    if ( conversionApi.consumable.test( data.viewItem, { name: true } ) ) {
                        // Caching children because when we start removing them iterating fails.
                        const children = Array.from( data.viewItem.getChildren() );
                
                
                Severity: Minor
                Found in src/converters.js - About 35 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 3 locations. Consider refactoring.
                Open

                        if ( !consumable.test( data.item, 'insert' ) ||
                            !consumable.test( data.item, 'attribute:listType' ) ||
                            !consumable.test( data.item, 'attribute:listIndent' )
                        ) {
                            return;
                Severity: Major
                Found in src/converters.js and 2 other locations - About 1 hr to fix
                src/todolistconverters.js on lines 31..36
                src/todolistconverters.js on lines 75..80

                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