BookStackApp/BookStack

View on GitHub

Showing 1,485 of 1,485 total issues

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

    test('AutoLinkNode.createDOM() sanitizes javascript: URLs', async () => {
      const {editor} = testEnv;

      await editor.update(() => {
        // eslint-disable-next-line no-script-url
resources/js/wysiwyg/lexical/link/__tests__/unit/LexicalLinkNode.test.ts on lines 221..231

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

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 (
          anchor.key === key &&
          anchor.type === 'text' &&
          anchor.offset > textSize &&
          anchor.offset <= nextTextSize
Severity: Major
Found in resources/js/wysiwyg/lexical/core/nodes/LexicalTextNode.ts and 1 other location - About 2 hrs to fix
resources/js/wysiwyg/lexical/core/nodes/LexicalTextNode.ts on lines 1018..1027

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

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 moveNativeSelectionBackward has 61 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function moveNativeSelectionBackward() {
  const domSelection = window.getSelection()!;
  let anchorNode = domSelection.anchorNode!;
  let anchorOffset = domSelection.anchorOffset!;

Severity: Major
Found in resources/js/wysiwyg/lexical/selection/__tests__/utils/index.ts - About 2 hrs to fix

    File web.php has 268 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    use BookStack\Access\Controllers as AccessControllers;
    use BookStack\Activity\Controllers as ActivityControllers;
    use BookStack\Api\ApiDocsController;
    Severity: Minor
    Found in routes/web.php - About 2 hrs to fix

      File LexicalListNode.test.ts has 268 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      /**
       * Copyright (c) Meta Platforms, Inc. and affiliates.
       *
       * This source code is licensed under the MIT license found in the
       * LICENSE file in the root directory of this source tree.

        Function formatTextUsingMatchPositions has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function formatTextUsingMatchPositions(array $matchPositions, string $originalText, int $targetLength): string
            {
                $maxEnd = mb_strlen($originalText);
                $fetchAll = ($targetLength === 0);
                $contextLength = ($fetchAll ? 0 : 32);
        Severity: Minor
        Found in app/Search/SearchResultsFormatter.php - 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 updateDOM has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

            updateDOM(prevNode: ImageNode, dom: HTMLElement) {
                if (prevNode.__src !== this.__src) {
                    dom.setAttribute('src', this.__src);
                }
        
        
        Severity: Minor
        Found in resources/js/wysiwyg/nodes/image.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 $appendNodesToJSON has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

        function $appendNodesToJSON(
          editor: LexicalEditor,
          selection: BaseSelection | null,
          currentNode: LexicalNode,
          targetArray: Array<BaseSerializedNode> = [],
        Severity: Minor
        Found in resources/js/wysiwyg/lexical/clipboard/clipboard.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 getWordsFromString has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

          const getWordsFromString = function (string: string): Array<Segment> {
            const segments: Segment[] = [];
            let wordString = '';
            let nonWordString = '';
            let i;
        Severity: Minor
        Found in resources/js/wysiwyg/lexical/selection/__tests__/utils/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 $handleOutdent has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

        export function $handleOutdent(listItemNode: ListItemNode): void {
          // go through each node and decide where to move it.
        
          if (isNestedListNode(listItemNode)) {
            return;
        Severity: Minor
        Found in resources/js/wysiwyg/lexical/list/formatList.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 $wrapInlineNodes has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

        function $wrapInlineNodes(nodes: LexicalNode[]) {
          // We temporarily insert the topLevelNodes into an arbitrary ElementNode,
          // since insertAfter does not work on nodes that have no parent (TO-DO: fix that).
          const virtualRoot = $createParagraphNode();
        
        
        Severity: Minor
        Found in resources/js/wysiwyg/lexical/core/LexicalSelection.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 setupListeners has 60 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            setupListeners() {
                // Filter tab click
                onSelect(this.filterTabs, e => {
                    this.resetAll();
                    this.filter = e.target.dataset.filter;
        Severity: Major
        Found in resources/js/components/image-manager.js - About 2 hrs to fix

          Function $convertTableCellNodeElement has 59 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function $convertTableCellNodeElement(
              domNode: Node,
          ): DOMConversionOutput {
              const domNode_ = domNode as HTMLTableCellElement;
              const nodeName = domNode.nodeName.toLowerCase();
          Severity: Major
          Found in resources/js/wysiwyg/nodes/custom-table-cell.ts - About 2 hrs to fix

            Function getTextContent has 59 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              getTextContent(): string {
                const nodes = this.getNodes();
                if (nodes.length === 0) {
                  return '';
                }
            Severity: Major
            Found in resources/js/wysiwyg/lexical/core/LexicalSelection.ts - About 2 hrs to fix

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

                static importJSON(
                  serializedNode: SerializedTestSegmentedNode,
                ): TestSegmentedNode {
                  const node = $createTestSegmentedNode(serializedNode.text);
                  node.setFormat(serializedNode.format);
              Severity: Major
              Found in resources/js/wysiwyg/lexical/core/__tests__/utils/index.ts and 1 other location - About 2 hrs to fix
              resources/js/wysiwyg/lexical/core/nodes/LexicalTextNode.ts on lines 609..616

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

              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

                  test('space separated', async () => {
                    const element = document.createElement('div');
                    addClassNamesToElement(element, 'a b c');
              
                    expect(element.className).toEqual('a b c');
              resources/js/wysiwyg/lexical/utils/__tests__/unit/LexicalElementHelpers.test.ts on lines 16..25

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

              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

                  test('basic', async () => {
                    const element = document.createElement('div');
                    addClassNamesToElement(element, 'test-class');
              
                    expect(element.className).toEqual('test-class');
              resources/js/wysiwyg/lexical/utils/__tests__/unit/LexicalElementHelpers.test.ts on lines 54..63

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

              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 importJSON(serializedNode: SerializedTextNode): TextNode {
                  const node = $createTextNode(serializedNode.text);
                  node.setFormat(serializedNode.format);
                  node.setDetail(serializedNode.detail);
                  node.setMode(serializedNode.mode);
              Severity: Major
              Found in resources/js/wysiwyg/lexical/core/nodes/LexicalTextNode.ts and 1 other location - About 2 hrs to fix
              resources/js/wysiwyg/lexical/core/__tests__/utils/index.ts on lines 286..295

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

              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 watchMarkerMouseDrags has 58 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected watchMarkerMouseDrags(wrapper: HTMLElement) {
                      const _this = this;
                      let markerStart: number = 0;
                      let markerProp: 'left' | 'top' = 'left';
              
              
              Severity: Major
              Found in resources/js/wysiwyg/ui/framework/helpers/table-resizer.ts - About 2 hrs to fix

                Function $appendNodesToHTML has 58 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function $appendNodesToHTML(
                  editor: LexicalEditor,
                  currentNode: LexicalNode,
                  parentElement: HTMLElement | DocumentFragment,
                  selection: BaseSelection | null = null,
                Severity: Major
                Found in resources/js/wysiwyg/lexical/html/index.ts - About 2 hrs to fix
                  Severity
                  Category
                  Status
                  Source
                  Language