superdesk/superdesk-client-core

View on GitHub
scripts/core/editor3/components/Editor3Component.tsx

Summary

Maintainability
F
4 days
Test Coverage

File Editor3Component.tsx has 549 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import React from 'react';
import ReactDOM from 'react-dom';
import {
    Editor,
    RichUtils,
Severity: Major
Found in scripts/core/editor3/components/Editor3Component.tsx - About 1 day to fix

    Function render has 141 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        render() {
            const {
                readOnly,
                locked,
                showToolbar,
    Severity: Major
    Found in scripts/core/editor3/components/Editor3Component.tsx - About 5 hrs to fix

      Function handleKeyCommand has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

          handleKeyCommand(command) {
              const author = getCurrentAuthor();
              const {editorState, onChange, singleLine, suggestingMode} = this.props;
              const {
                  onCreateSplitParagraphSuggestion,
      Severity: Minor
      Found in scripts/core/editor3/components/Editor3Component.tsx - About 3 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 handleKeyCommand has 82 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          handleKeyCommand(command) {
              const author = getCurrentAuthor();
              const {editorState, onChange, singleLine, suggestingMode} = this.props;
              const {
                  onCreateSplitParagraphSuggestion,
      Severity: Major
      Found in scripts/core/editor3/components/Editor3Component.tsx - About 3 hrs to fix

        Function keyBindingFn has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            keyBindingFn(e) {
                const {key, shiftKey, ctrlKey, metaKey} = e;
                const selectionState = this.props.editorState.getSelection();
                const modifierKey = isMacOS() ? metaKey : ctrlKey;
        
        
        Severity: Minor
        Found in scripts/core/editor3/components/Editor3Component.tsx - 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 keyBindingFn has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            keyBindingFn(e) {
                const {key, shiftKey, ctrlKey, metaKey} = e;
                const selectionState = this.props.editorState.getSelection();
                const modifierKey = isMacOS() ? metaKey : ctrlKey;
        
        
        Severity: Minor
        Found in scripts/core/editor3/components/Editor3Component.tsx - About 1 hr to fix

          Function handleBeforeInput has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              handleBeforeInput(chars: string, editorState: EditorState) {
                  this.setState({contentChangesAfterLastFocus: this.state.contentChangesAfterLastFocus + 1});
          
                  const author = getCurrentAuthor();
                  const {onChange, suggestingMode, onCreateAddSuggestion} = this.props;
          Severity: Minor
          Found in scripts/core/editor3/components/Editor3Component.tsx - About 1 hr to fix

            Function canDropMedia has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

            export function canDropMedia(e, editorConfig): undefined | boolean {
                // apply restrictions only if it is something other than text(IArticle object, image file) being dragged
                if ((e?.originalEvent?.dataTransfer?.types ?? []).some((type) => type !== 'text/plain' && type !== 'text/html')) {
                    const {editorFormat, readOnly, singleLine} = editorConfig;
                    const supportsMedia = !readOnly && !singleLine && editorFormat.includes('media');
            Severity: Minor
            Found in scripts/core/editor3/components/Editor3Component.tsx - 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 render has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                render() {
                    const {
                        readOnly,
                        locked,
                        showToolbar,
            Severity: Minor
            Found in scripts/core/editor3/components/Editor3Component.tsx - 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 handleBeforeInput has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                handleBeforeInput(chars: string, editorState: EditorState) {
                    this.setState({contentChangesAfterLastFocus: this.state.contentChangesAfterLastFocus + 1});
            
                    const author = getCurrentAuthor();
                    const {onChange, suggestingMode, onCreateAddSuggestion} = this.props;
            Severity: Minor
            Found in scripts/core/editor3/components/Editor3Component.tsx - 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

            Avoid too many return statements within this function.
            Open

                                return 'handled';
            Severity: Major
            Found in scripts/core/editor3/components/Editor3Component.tsx - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return 'not-handled';
              Severity: Major
              Found in scripts/core/editor3/components/Editor3Component.tsx - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                return 'handled';
                Severity: Major
                Found in scripts/core/editor3/components/Editor3Component.tsx - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return getDefaultKeyBinding(e);
                  Severity: Major
                  Found in scripts/core/editor3/components/Editor3Component.tsx - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return 'handled';
                    Severity: Major
                    Found in scripts/core/editor3/components/Editor3Component.tsx - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return '';
                      Severity: Major
                      Found in scripts/core/editor3/components/Editor3Component.tsx - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                return 'not-handled';
                        Severity: Major
                        Found in scripts/core/editor3/components/Editor3Component.tsx - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                          return 'handled';
                          Severity: Major
                          Found in scripts/core/editor3/components/Editor3Component.tsx - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                            return 'handled';
                            Severity: Major
                            Found in scripts/core/editor3/components/Editor3Component.tsx - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                          return 'handled';
                              Severity: Major
                              Found in scripts/core/editor3/components/Editor3Component.tsx - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                                return 'delete';
                                Severity: Major
                                Found in scripts/core/editor3/components/Editor3Component.tsx - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                                      return 'handled';
                                  Severity: Major
                                  Found in scripts/core/editor3/components/Editor3Component.tsx - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                                return 'not-handled';
                                    Severity: Major
                                    Found in scripts/core/editor3/components/Editor3Component.tsx - About 30 mins to fix

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

                                              const {
                                                  readOnly,
                                                  locked,
                                                  showToolbar,
                                                  onChange,
                                      Severity: Minor
                                      Found in scripts/core/editor3/components/Editor3Component.tsx and 1 other location - About 50 mins to fix
                                      scripts/core/ui/components/Form/Checkbox.tsx on lines 26..35

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

                                      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