taye/interact.js

View on GitHub
packages/actions/drop/index.ts

Summary

Maintainability
F
3 days
Test Coverage

File index.ts has 374 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Interactable from '@interactjs/core/Interactable'
import InteractEvent from '@interactjs/core/InteractEvent'
import { Scope } from '@interactjs/core/scope'
import * as utils from '@interactjs/utils'
import drag from '../drag'
Severity: Minor
Found in packages/actions/drop/index.ts - About 5 hrs to fix

    Function dropzoneMethod has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

    function dropzoneMethod (interactable: Interact.Interactable, options?: Interact.DropzoneOptions | boolean) {
      if (utils.is.object(options)) {
        interactable.options.drop.enabled = options.enabled !== false
    
        if (options.listeners) {
    Severity: Minor
    Found in packages/actions/drop/index.ts - About 4 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 install has 81 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function install (scope: Scope) {
      const {
        actions,
        /** @lends module:interact */
        interact,
    Severity: Major
    Found in packages/actions/drop/index.ts - About 3 hrs to fix

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

      function collectDrops ({ interactables }, draggableElement) {
        const drops = []
      
        // collect all dropzones and their elements which qualify for a drop
        for (const dropzone of interactables.list) {
      Severity: Minor
      Found in packages/actions/drop/index.ts - 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 getDropEvents has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function getDropEvents (interaction: Interact.Interaction, _pointerEvent, dragEvent) {
        const { dropState } = interaction
        const dropEvents = {
          enter     : null,
          leave     : null,
      Severity: Minor
      Found in packages/actions/drop/index.ts - About 1 hr to fix

        Function dropzoneMethod has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function dropzoneMethod (interactable: Interact.Interactable, options?: Interact.DropzoneOptions | boolean) {
          if (utils.is.object(options)) {
            interactable.options.drop.enabled = options.enabled !== false
        
            if (options.listeners) {
        Severity: Minor
        Found in packages/actions/drop/index.ts - About 1 hr to fix

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

          function dropCheckMethod (
            interactable: Interact.Interactable,
            dragEvent: InteractEvent,
            event: Interact.PointerEventType,
            draggable: Interact.Interactable,
          Severity: Minor
          Found in packages/actions/drop/index.ts - About 1 hr to fix

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

            function getDropEvents (interaction: Interact.Interaction, _pointerEvent, dragEvent) {
              const { dropState } = interaction
              const dropEvents = {
                enter     : null,
                leave     : null,
            Severity: Minor
            Found in packages/actions/drop/index.ts - 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 dropCheckMethod has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            function dropCheckMethod (
              interactable: Interact.Interactable,
              dragEvent: InteractEvent,
              event: Interact.PointerEventType,
              draggable: Interact.Interactable,
            Severity: Minor
            Found in packages/actions/drop/index.ts - 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 dropCheck has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              Interactable.prototype.dropCheck = function (this: Interact.Interactable, dragEvent, event, draggable, draggableElement, dropElement, rect) {
            Severity: Major
            Found in packages/actions/drop/index.ts - About 50 mins to fix

              Function dropCheckMethod has 7 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                interactable: Interact.Interactable,
                dragEvent: InteractEvent,
                event: Interact.PointerEventType,
                draggable: Interact.Interactable,
                draggableElement: Element,
              Severity: Major
              Found in packages/actions/drop/index.ts - About 50 mins to fix

                Consider simplifying this complex logical expression.
                Open

                    if ((utils.is.element(accept) && accept !== draggableElement) ||
                        (utils.is.string(accept) &&
                        !utils.dom.matchesSelector(draggableElement, accept)) ||
                        (utils.is.func(accept) && !accept({ dropzone, draggableElement }))) {
                      continue
                Severity: Major
                Found in packages/actions/drop/index.ts - About 40 mins to fix

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

                    if (dragEvent.type === 'dragstart') {
                      dropEvents.activate = new DropEvent(dropState, dragEvent, 'dropactivate')
                  
                      dropEvents.activate.target   = null
                      dropEvents.activate.dropzone = null
                  Severity: Major
                  Found in packages/actions/drop/index.ts and 1 other location - About 1 hr to fix
                  packages/actions/drop/index.ts on lines 338..343

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

                  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 (dragEvent.type === 'dragend') {
                      dropEvents.deactivate = new DropEvent(dropState, dragEvent, 'dropdeactivate')
                  
                      dropEvents.deactivate.target   = null
                      dropEvents.deactivate.dropzone = null
                  Severity: Major
                  Found in packages/actions/drop/index.ts and 1 other location - About 1 hr to fix
                  packages/actions/drop/index.ts on lines 332..337

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

                  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 (dragEvent.type === 'dragend' && dropState.cur.dropzone) {
                      dropEvents.drop = new DropEvent(dropState, dragEvent, 'drop')
                  
                      dragEvent.dropzone = dropState.cur.dropzone
                      dragEvent.relatedTarget = dropState.cur.element
                  Severity: Major
                  Found in packages/actions/drop/index.ts and 1 other location - About 1 hr to fix
                  packages/actions/drop/index.ts on lines 358..363

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

                  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 (dropState.cur.dropzone) {
                        dropEvents.enter = new DropEvent(dropState, dragEvent, 'dragenter')
                  
                        dragEvent.dragEnter = dropState.cur.element
                        dragEvent.dropzone = dropState.cur.dropzone
                  Severity: Major
                  Found in packages/actions/drop/index.ts and 1 other location - About 1 hr to fix
                  packages/actions/drop/index.ts on lines 366..371

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

                  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

                                            Math.max(0, Math.min(rect.bottom, dragRect.bottom) - Math.max(rect.top, dragRect.top)))
                  Severity: Minor
                  Found in packages/actions/drop/index.ts and 1 other location - About 40 mins to fix
                  packages/actions/drop/index.ts on lines 529..529

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

                  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

                      const overlapArea  = (Math.max(0, Math.min(rect.right, dragRect.right) - Math.max(rect.left, dragRect.left)) *
                  Severity: Minor
                  Found in packages/actions/drop/index.ts and 1 other location - About 40 mins to fix
                  packages/actions/drop/index.ts on lines 530..530

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

                  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