getlackey/lackey-cms

View on GitHub
modules/cms/client/js/block-editor.js

Summary

Maintainability
F
3 days
Test Coverage

File block-editor.js has 443 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* eslint no-cond-assign:0, no-new:0, no-use-before-define:0, no-continue:0 */
/* jslint browser:true, node:true, esnext:true */
'use strict';
/*
    Copyright 2016 Enigma Marketing Services Limited
Severity: Minor
Found in modules/cms/client/js/block-editor.js - About 6 hrs to fix

    BlockEditor has 33 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class BlockEditor {
        constructor(path, template, block) {
            debug('Constructor', block);
    
            var self = this;
    Severity: Minor
    Found in modules/cms/client/js/block-editor.js - About 4 hrs to fix

      Function generateAbstractOutline has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static generateAbstractOutline(block, bounds) {
              var allElements = [],
                  outlines = [];
      
              block.elements.forEach(element => {
      Severity: Minor
      Found in modules/cms/client/js/block-editor.js - About 1 hr to fix

        Function _normalizeAbstract has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static _normalizeAbstract(layout) {
                var minX = Infinity,
                    maxX = -Infinity,
                    minY = Infinity,
                    scale = 1,
        Severity: Minor
        Found in modules/cms/client/js/block-editor.js - About 1 hr to fix

          Function generateAbstractBlock has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              static generateAbstractBlock(block, parentBounds) {
                  var container = top.document.createElement('figure'),
                      bounds = block.getAbsoluteBoundingRect(),
                      promise = Promise.resolve();
                  container.setAttribute('class', 'block');
          Severity: Minor
          Found in modules/cms/client/js/block-editor.js - About 1 hr to fix

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

                static _normalizeAbstract(layout) {
                    var minX = Infinity,
                        maxX = -Infinity,
                        minY = Infinity,
                        scale = 1,
            Severity: Minor
            Found in modules/cms/client/js/block-editor.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 getComments has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                static getComments(root) {
                    var foundComments = [];
                    var elementPath = [root];
            
                    while (elementPath.length > 0) {
            Severity: Minor
            Found in modules/cms/client/js/block-editor.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 startRendering has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                static startRendering() {
                    var render = () => {
                        if (BlockEditor.activeBlock) {
                            let bounds = BlockEditor.activeBlock.getAbsoluteBoundingRect();
            
            
            Severity: Minor
            Found in modules/cms/client/js/block-editor.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 (Math.abs(outline.bounds.top) < 5 &&
                               Math.abs(outline.bounds.height - bounds.height) < 5) {
                                outline.classList.add('full-height');
                            } else if (Math.abs(outline.bounds.top) < 5) {
                                outline.classList.add('at-top');
            Severity: Major
            Found in modules/cms/client/js/block-editor.js and 1 other location - About 4 hrs to fix
            modules/cms/client/js/block-editor.js on lines 476..481

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

            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 (Math.abs(outline.bounds.left) < 5 &&
                               Math.abs(outline.bounds.width - bounds.width) < 5) {
                                outline.classList.add('full-width');
                            } else if (Math.abs(outline.bounds.left) < 5) {
                                outline.classList.add('at-left');
            Severity: Major
            Found in modules/cms/client/js/block-editor.js and 1 other location - About 4 hrs to fix
            modules/cms/client/js/block-editor.js on lines 483..488

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

            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

                static updateEditButton(block, bounds) {
                    BlockEditor.updateEditButtonPosition(bounds);
            
                    if (BlockEditor.activeBlock !== block) {
                        BlockEditor.editButton.setAttribute('data-target-change', '');
            Severity: Major
            Found in modules/cms/client/js/block-editor.js and 1 other location - About 2 hrs to fix
            modules/cms/client/js/block-editor.js on lines 357..365

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

            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

                static updateOverlay(block, bounds) {
                    BlockEditor.updateOverlayBounds(bounds);
            
                    if (BlockEditor.activeBlock !== block) {
                        BlockEditor.overlay.setAttribute('data-target-change', '');
            Severity: Major
            Found in modules/cms/client/js/block-editor.js and 1 other location - About 2 hrs to fix
            modules/cms/client/js/block-editor.js on lines 321..329

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

            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 (!top.Lackey || !top.LackeyManager) {
                        debug('init - wait');
                        setTimeout(() => {
                            BlockEditor.init();
                        }, 250);
            Severity: Minor
            Found in modules/cms/client/js/block-editor.js and 1 other location - About 55 mins to fix
            modules/cms/client/js/wysiwyg.js on lines 367..373

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

            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