BookStackApp/BookStack

View on GitHub
resources/js/wysiwyg-tinymce/plugins-details.js

Summary

Maintainability
C
1 day
Test Coverage

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

function register(editor) {
    editor.ui.registry.addIcon('details', '<svg width="24" height="24"><path d="M8.2 9a.5.5 0 0 0-.4.8l4 5.6a.5.5 0 0 0 .8 0l4-5.6a.5.5 0 0 0-.4-.8ZM20.122 18.151h-16c-.964 0-.934 2.7 0 2.7h16c1.139 0 1.173-2.7 0-2.7zM20.122 3.042h-16c-.964 0-.934 2.7 0 2.7h16c1.139 0 1.173-2.7 0-2.7z"/></svg>');
    editor.ui.registry.addIcon('togglefold', '<svg height="24"  width="24"><path d="M8.12 19.3c.39.39 1.02.39 1.41 0L12 16.83l2.47 2.47c.39.39 1.02.39 1.41 0 .39-.39.39-1.02 0-1.41l-3.17-3.17c-.39-.39-1.02-.39-1.41 0l-3.17 3.17c-.4.38-.4 1.02-.01 1.41zm7.76-14.6c-.39-.39-1.02-.39-1.41 0L12 7.17 9.53 4.7c-.39-.39-1.02-.39-1.41 0-.39.39-.39 1.03 0 1.42l3.17 3.17c.39.39 1.02.39 1.41 0l3.17-3.17c.4-.39.4-1.03.01-1.42z"/></svg>');
    editor.ui.registry.addIcon('togglelabel', '<svg height="18" width="18" viewBox="0 0 24 24"><path d="M21.41,11.41l-8.83-8.83C12.21,2.21,11.7,2,11.17,2H4C2.9,2,2,2.9,2,4v7.17c0,0.53,0.21,1.04,0.59,1.41l8.83,8.83 c0.78,0.78,2.05,0.78,2.83,0l7.17-7.17C22.2,13.46,22.2,12.2,21.41,11.41z M6.5,8C5.67,8,5,7.33,5,6.5S5.67,5,6.5,5S8,5.67,8,6.5 S7.33,8,6.5,8z"/></svg>');

Severity: Major
Found in resources/js/wysiwyg-tinymce/plugins-details.js - About 2 hrs to fix

    Function detailsDialog has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function detailsDialog(editor) {
        return {
            title: 'Edit collapsible block',
            body: {
                type: 'panel',
    Severity: Minor
    Found in resources/js/wysiwyg-tinymce/plugins-details.js - About 1 hr to fix

      Function ensureDetailsWrappedInEditable has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      function ensureDetailsWrappedInEditable(detailsEl) {
          unwrapDetailsEditable(detailsEl);
      
          detailsEl.attr('contenteditable', 'false');
          const rootWrap = window.tinymce.html.Node.create('doc-root', {contenteditable: 'true'});
      Severity: Minor
      Found in resources/js/wysiwyg-tinymce/plugins-details.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

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

          editor.ui.registry.addContextToolbar('details', {
              predicate(node) {
                  return node.nodeName.toLowerCase() === 'details';
              },
              items: 'editdetials toggledetails removedetails',
      Severity: Major
      Found in resources/js/wysiwyg-tinymce/plugins-details.js and 1 other location - About 1 hr to fix
      resources/js/wysiwyg-tinymce/plugin-codeeditor.js on lines 249..256

      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('details', {
              icon: 'details',
              tooltip: 'Insert collapsible block',
              onAction() {
                  editor.execCommand('InsertDetailsBlock');
      Severity: Major
      Found in resources/js/wysiwyg-tinymce/plugins-details.js and 3 other locations - About 45 mins to fix
      resources/js/wysiwyg-tinymce/plugin-codeeditor.js on lines 161..167
      resources/js/wysiwyg-tinymce/plugin-codeeditor.js on lines 169..175
      resources/js/wysiwyg-tinymce/plugins-customhr.js on lines 12..18

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

          editor.ui.registry.addButton('removedetails', {
              icon: 'table-delete-table',
              tooltip: 'Unwrap',
              onAction() {
                  unwrapDetailsInSelection(editor);
      Severity: Minor
      Found in resources/js/wysiwyg-tinymce/plugins-details.js and 1 other location - About 35 mins to fix
      resources/js/wysiwyg-tinymce/plugins-details.js on lines 196..202

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

      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

          editor.ui.registry.addButton('editdetials', {
              icon: 'togglelabel',
              tooltip: 'Edit label',
              onAction() {
                  showDetailLabelEditWindow(editor);
      Severity: Minor
      Found in resources/js/wysiwyg-tinymce/plugins-details.js and 1 other location - About 35 mins to fix
      resources/js/wysiwyg-tinymce/plugins-details.js on lines 188..194

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

      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