BookStackApp/BookStack

View on GitHub

Showing 1,485 of 1,485 total issues

Function $setBlocksType has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

export function $setBlocksType(
  selection: BaseSelection | null,
  createElement: () => ElementNode,
): void {
  if (selection === null) {
Severity: Minor
Found in resources/js/wysiwyg/lexical/selection/range-selection.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 collectBuildInformation has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

function collectBuildInformation(): string {
  let compatibleEditors = 0;
  const incompatibleEditors = new Set<string>();
  const thisVersion = LexicalEditor.version;
  if (typeof window !== 'undefined') {
Severity: Minor
Found in resources/js/wysiwyg/lexical/core/LexicalUpdates.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

Method addOptionsFromString has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function addOptionsFromString(string $searchString): void
    {
        /** @var array<string, SearchOption[]> $terms */
        $terms = [
            'exacts'   => [],
Severity: Minor
Found in app/Search/SearchOptions.php - About 1 hr to fix

    Method run has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function run()
        {
            // Create an editor user
            $editorUser = User::factory()->create();
            $editorRole = Role::getRole('editor');
    Severity: Minor
    Found in database/seeders/DummyContentSeeder.php - About 1 hr to fix

      Function removeList has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function removeList(editor: LexicalEditor): void {
        editor.update(() => {
          const selection = $getSelection();
      
          if ($isRangeSelection(selection)) {
      Severity: Minor
      Found in resources/js/wysiwyg/lexical/list/formatList.ts - About 1 hr to fix

        Function setRootElement has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          setRootElement(nextRootElement: null | HTMLElement): void {
            const prevRootElement = this._rootElement;
        
            if (nextRootElement !== prevRootElement) {
              const classNames = getCachedClassNameArray(this._config.theme, 'root');
        Severity: Minor
        Found in resources/js/wysiwyg/lexical/core/LexicalEditor.ts - About 1 hr to fix

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

                  window.tinymce.init(config).then(editors => {
                      this.wysiwygEditor = editors[0];
                      setTimeout(() => this.wysiwygEditor.focus(), 50);
                  });
          Severity: Major
          Found in resources/js/components/page-comment.js and 1 other location - About 1 hr to fix
          resources/js/components/page-comments.js on lines 142..145

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

          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

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

                  window.tinymce.init(config).then(editors => {
                      this.wysiwygEditor = editors[0];
                      setTimeout(() => this.wysiwygEditor.focus(), 50);
                  });
          Severity: Major
          Found in resources/js/components/page-comments.js and 1 other location - About 1 hr to fix
          resources/js/components/page-comment.js on lines 74..77

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

          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

              open() {
                  this.toggle.classList.add('open');
                  this.toggle.setAttribute('aria-expanded', 'true');
                  slideDown(this.list, 180);
                  this.isOpen = true;
          Severity: Major
          Found in resources/js/components/chapter-contents.js and 1 other location - About 1 hr to fix
          resources/js/components/chapter-contents.js on lines 21..26

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

          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

              close() {
                  this.toggle.classList.remove('open');
                  this.toggle.setAttribute('aria-expanded', 'false');
                  slideUp(this.list, 180);
                  this.isOpen = false;
          Severity: Major
          Found in resources/js/components/chapter-contents.js and 1 other location - About 1 hr to fix
          resources/js/components/chapter-contents.js on lines 14..19

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

          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

          export function registerTaskListHandler(editor: LexicalEditor, editorContainer: HTMLElement): (() => void) {
              const handler = new TaskListHandler(editor, editorContainer);
          
              return () => {
                  handler.teardown();
          resources/js/wysiwyg/ui/framework/helpers/table-resizer.ts on lines 212..218

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

          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

          export function registerTableResizer(editor: LexicalEditor, editScrollContainer: HTMLElement): (() => void) {
              const resizer = new TableResizer(editor, editScrollContainer);
          
              return () => {
                  resizer.teardown();
          Severity: Major
          Found in resources/js/wysiwyg/ui/framework/helpers/table-resizer.ts and 1 other location - About 1 hr to fix
          resources/js/wysiwyg/ui/framework/helpers/task-list-handler.ts on lines 53..59

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

          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

          Function handleTableCellRangeEvents has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function handleTableCellRangeEvents(editor) {
              /** @var {HTMLTableCellElement[]} * */
              let selectedCells = [];
          
              editor.on('TableSelectionChange', event => {
          Severity: Minor
          Found in resources/js/wysiwyg-tinymce/fixes.js - About 1 hr to fix

            Function handleEmbedAlignmentChanges has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export function handleEmbedAlignmentChanges(editor) {
                function updateClassesForPreview(previewElem) {
                    const mediaTarget = previewElem.querySelector('iframe, video');
                    if (!mediaTarget) {
                        return;
            Severity: Minor
            Found in resources/js/wysiwyg-tinymce/fixes.js - About 1 hr to fix

              Method isSortChangePermissible has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function isSortChangePermissible(BookSortMapItem $sortMapItem, BookChild $model, ?Entity $currentParent, ?Entity $newBook, ?Entity $newChapter): bool
                  {
                      // Stop if we can't see the current parent or new book.
                      if (!$currentParent || !$newBook) {
                          return false;
              Severity: Minor
              Found in app/Entities/Tools/BookContents.php - About 1 hr to fix

                Function $getSelectionStyleValueForProperty has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export function $getSelectionStyleValueForProperty(
                  selection: RangeSelection | TableSelection,
                  styleProperty: string,
                  defaultValue = '',
                ): string {
                Severity: Minor
                Found in resources/js/wysiwyg/lexical/selection/range-selection.ts - About 1 hr to fix

                  Function select has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    select(_anchorOffset?: number, _focusOffset?: number): RangeSelection {
                      errorOnReadOnly();
                      let anchorOffset = _anchorOffset;
                      let focusOffset = _focusOffset;
                      const selection = $getSelection();
                  Severity: Minor
                  Found in resources/js/wysiwyg/lexical/core/nodes/LexicalTextNode.ts - About 1 hr to fix

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

                            editor.serializer.addNodeFilter('li', nodes => {
                                for (const node of nodes) {
                                    if (node.attributes.map.class === 'task-list-item') {
                                        serializeTaskListNode(node);
                                    }
                    Severity: Major
                    Found in resources/js/wysiwyg-tinymce/plugins-tasklist.js and 1 other location - About 1 hr to fix
                    resources/js/wysiwyg-tinymce/plugins-tasklist.js on lines 142..148

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

                    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

                        book_start: {
                            active(elem, parent) {
                                return parent || (parent === null && elem.previousElementSibling);
                            },
                            run(elem, parent, book) {
                    Severity: Major
                    Found in resources/js/components/book-sort.js and 1 other location - About 1 hr to fix
                    resources/js/components/book-sort.js on lines 113..120

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

                    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.parser.addNodeFilter('li', nodes => {
                                for (const node of nodes) {
                                    if (node.attributes.map.class === 'task-list-item') {
                                        parseTaskListNode(node);
                                    }
                    Severity: Major
                    Found in resources/js/wysiwyg-tinymce/plugins-tasklist.js and 1 other location - About 1 hr to fix
                    resources/js/wysiwyg-tinymce/plugins-tasklist.js on lines 149..155

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

                    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

                    Severity
                    Category
                    Status
                    Source
                    Language