BookStackApp/BookStack

View on GitHub
resources/js/wysiwyg/plugin-codeeditor.js

Summary

Maintainability
D
1 day
Test Coverage

Function register has 89 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function register(editor) {
    editor.ui.registry.addIcon('codeblock', '<svg width="24" height="24"><path d="M4 3h16c.6 0 1 .4 1 1v16c0 .6-.4 1-1 1H4a1 1 0 0 1-1-1V4c0-.6.4-1 1-1Zm1 2v14h14V5Z"/><path d="M11.103 15.423c.277.277.277.738 0 .922a.692.692 0 0 1-1.106 0l-4.057-3.78a.738.738 0 0 1 0-1.107l4.057-3.872c.276-.277.83-.277 1.106 0a.724.724 0 0 1 0 1.014L7.6 12.012ZM12.897 8.577c-.245-.312-.2-.675.08-.955.28-.281.727-.27 1.027.033l4.057 3.78a.738.738 0 0 1 0 1.107l-4.057 3.872c-.277.277-.83.277-1.107 0a.724.724 0 0 1 0-1.014l3.504-3.412z"/></svg>');

    editor.ui.registry.addButton('codeeditor', {
        tooltip: 'Insert code block',
Severity: Major
Found in resources/js/wysiwyg/plugin-codeeditor.js - About 3 hrs to fix

    Function defineCodeBlockCustomElement has 84 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function defineCodeBlockCustomElement(editor) {
        const doc = editor.getDoc();
        const win = doc.defaultView;
    
        class CodeBlockElement extends win.HTMLElement {
    Severity: Major
    Found in resources/js/wysiwyg/plugin-codeeditor.js - About 3 hrs to fix

      Function defineCodeBlockCustomElement has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

      function defineCodeBlockCustomElement(editor) {
          const doc = editor.getDoc();
          const win = doc.defaultView;
      
          class CodeBlockElement extends win.HTMLElement {
      Severity: Minor
      Found in resources/js/wysiwyg/plugin-codeeditor.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 showPopup has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      function showPopup(editor, code, language, direction, callback) {
      Severity: Minor
      Found in resources/js/wysiwyg/plugin-codeeditor.js - About 35 mins to fix

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

            editor.ui.registry.addContextToolbar('codeeditor', {
                predicate(node) {
                    return node.nodeName.toLowerCase() === 'code-block';
                },
                items: 'editcodeeditor',
        Severity: Major
        Found in resources/js/wysiwyg/plugin-codeeditor.js and 1 other location - About 1 hr to fix
        resources/js/wysiwyg/plugins-details.js on lines 245..252

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

        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 4 locations. Consider refactoring.
        Open

            editor.ui.registry.addButton('codeeditor', {
                tooltip: 'Insert code block',
                icon: 'codeblock',
                onAction() {
                    editor.execCommand('codeeditor');
        Severity: Major
        Found in resources/js/wysiwyg/plugin-codeeditor.js and 3 other locations - About 45 mins to fix
        resources/js/wysiwyg/plugin-codeeditor.js on lines 169..175
        resources/js/wysiwyg/plugins-customhr.js on lines 12..18
        resources/js/wysiwyg/plugins-details.js on lines 180..186

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

        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 4 locations. Consider refactoring.
        Open

            editor.ui.registry.addButton('editcodeeditor', {
                tooltip: 'Edit code block',
                icon: 'edit-block',
                onAction() {
                    editor.execCommand('codeeditor');
        Severity: Major
        Found in resources/js/wysiwyg/plugin-codeeditor.js and 3 other locations - About 45 mins to fix
        resources/js/wysiwyg/plugin-codeeditor.js on lines 161..167
        resources/js/wysiwyg/plugins-customhr.js on lines 12..18
        resources/js/wysiwyg/plugins-details.js on lines 180..186

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

        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