rike422/operatta-js

View on GitHub

Showing 36 of 177 total issues

File text-operation.js has 418 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// @flow

// Operation are essentially lists of ops. There are three types of ops:
//
// * Retain ops: Advance the cursor position by a given number of characters.
Severity: Minor
Found in src/ot/text-operation.js - About 6 hrs to fix

    Function compose has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

      compose (operation2: TextOperation): TextOperation {
        const operation1: TextOperation = this
        if (operation1.targetLength !== operation2.baseLength) {
          throw new Error('The base length of the second operation has to be the target length of the first operation')
        }
    Severity: Minor
    Found in src/ot/text-operation.js - About 5 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 compose has 91 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      compose (operation2: TextOperation): TextOperation {
        const operation1: TextOperation = this
        if (operation1.targetLength !== operation2.baseLength) {
          throw new Error('The base length of the second operation has to be the target length of the first operation')
        }
    Severity: Major
    Found in src/ot/text-operation.js - About 3 hrs to fix

      File codemirror-adapter.js has 280 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      // @flow
      import type { Editor, EditorChange, Doc } from 'codemirror'
      import TextOperation from 'ot/text-operation'
      import { rangeData } from 'types/data'
      import Selection, { Range } from 'client/selection'
      Severity: Minor
      Found in src/client/adapters/codemirror-adapter.js - About 2 hrs to fix

        Function operationFromCodeMirrorChanges has 65 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const operationFromCodeMirrorChanges = (changes: Array<EditorChange>, doc: Doc): [TextOperation, TextOperation] => {
          // Approach: Replay the changes, beginning with the most recent one, and
          // construct the operation and its inverse. We have to convert the position
          // in the pre-change coordinate system to an index. We have a method to
          // convert a position in the coordinate system after all changes to an index,
        Severity: Major
        Found in src/client/adapters/codemirror-adapter.js - About 2 hrs to fix

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

            handleResponse (data: xhrData) {
              let i: number
              const operations: Array<any> = data.operations
              for (i = 0; i < operations.length; i++) {
                if (operations[i].user === this.ownUserName) {
          Severity: Minor
          Found in src/client/connectors/ajax.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 render has 44 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            render () {
              const {
                onRedo,
                onUndo,
                onCode
          Severity: Minor
          Found in demo/components/editor-menu.js - About 1 hr to fix

            Function handleResponse has 43 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              handleResponse (data: xhrData) {
                let i: number
                const operations: Array<any> = data.operations
                for (i = 0; i < operations.length; i++) {
                  if (operations[i].user === this.ownUserName) {
            Severity: Minor
            Found in src/client/connectors/ajax.js - About 1 hr to fix

              Function hsl2hex has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

              export function hsl2hex (h: number, s: number, l: number): string {
                if (s === 0) {
                  return rgb2hex(l, l, l)
                }
                const var2: number = l < 0.5 ? l * (1 + s) : (l + s) - (s * l)
              Severity: Minor
              Found in src/common/colors.js - 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 transform has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                transform (other: TextOperation): Range {
                  function transformIndex (index: number): number {
                    let newIndex: number = index
                    const ops: Array<any> = other.ops
                    for (let i: number = 0, l: number = other.ops.length; i < l; i++) {
              Severity: Minor
              Found in src/client/selection.js - 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 addClient has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                addClient (socket: Socket) {
                  const self: EditorSocketIOServer = this
                  socket
                    .join(this.docId)
                    .emit('doc', {
              Severity: Minor
              Found in src/server/editor-socketio-server.js - About 1 hr to fix

                Function add has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                  add (operation: WrappedOperation, compose: ?boolean) {
                    if (this.state === UNDOING_STATE) {
                      this.redoStack.push(operation)
                      this.dontCompose = true
                    } else if (this.state === REDOING_STATE) {
                Severity: Minor
                Found in src/client/undo-manager.js - 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

                Avoid deeply nested control flow statements.
                Open

                      } else if (isRetain(op1) && isDelete(op2)) {
                        if (op1 > -op2) {
                          operation.delete(op2)
                          op1 = op1 + op2
                          op2 = ops2[i2++]
                Severity: Major
                Found in src/ot/text-operation.js - About 45 mins to fix

                  Function randomOperation has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                    randomOperation (str) {
                      const operation = new TextOperation()
                      let left
                      while (true) {
                        left = str.length - operation.baseLength
                  Severity: Minor
                  Found in test/helpers/test-helper.js - About 45 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

                  Function getSimpleOp has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function getSimpleOp (operation: TextOperation): ?string {
                    const ops: Array<any> = operation.ops
                    const isRetain = TextOperation.isRetain
                    switch (ops.length) {
                      case 1:
                  Severity: Minor
                  Found in src/ot/text-operation.js - About 45 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 deeply nested control flow statements.
                  Open

                        } else if (isRetain(op1) && isDelete(op2)) {
                          if (op1 > -op2) {
                            minl = -op2
                            op1 = op1 + op2
                            op2 = ops2[i2++]
                  Severity: Major
                  Found in src/ot/text-operation.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                            if (-op1 > op2) {
                              minl = op2
                              op1 = op1 + op2
                              op2 = ops2[i2++]
                            } else if (-op1 === op2) {
                    Severity: Major
                    Found in src/ot/text-operation.js - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                              if (op1.length > op2) {
                                operation.insert(op1.slice(0, op2))
                                op1 = op1.slice(op2)
                                op2 = ops2[i2++]
                              } else if (op1.length === op2) {
                      Severity: Major
                      Found in src/ot/text-operation.js - About 45 mins to fix

                        Function insert has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                          insert (str: string): this {
                            if (typeof str !== 'string') {
                              throw new Error('insert expects a string')
                            }
                            if (str === '') {
                        Severity: Minor
                        Found in src/ot/text-operation.js - About 45 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

                        Function shouldBeComposedWithInverted has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                          shouldBeComposedWithInverted (other: TextOperation): boolean {
                            if (this.isNoop() || other.isNoop()) {
                              return true
                            }
                        
                        
                        Severity: Minor
                        Found in src/ot/text-operation.js - About 35 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

                        Severity
                        Category
                        Status
                        Source
                        Language