rike422/operatta-js

View on GitHub

Showing 177 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

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

        if (abPrime[0].apply(b.apply(doc)) !== abPrime[1].apply(a.apply(doc))) {
          console.log('------------------------')
          console.log(doc)
          console.log(a.toString())
          console.log(b.toString())
    Severity: Major
    Found in test/src/ot/test-simple-text-operation.js and 1 other location - About 5 hrs to fix
    test/src/ot/test-simple-text-operation.js on lines 59..66

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

    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

        if (abPrime[0].apply(b.apply(doc)) !== abPrime[1].apply(a.apply(doc))) {
          console.log('------------------------')
          console.log(doc)
          console.log(a.toString())
          console.log(b.toString())
    Severity: Major
    Found in test/src/ot/test-simple-text-operation.js and 1 other location - About 5 hrs to fix
    test/src/ot/test-simple-text-operation.js on lines 40..47

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

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

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

              performUndo (fn: (op: WrappedOperation) => void) {
                this.state = UNDOING_STATE
                if (this.undoStack.length === 0) {
                  throw new Error('undo not possible')
                }
            Severity: Major
            Found in src/client/undo-manager.js and 1 other location - About 1 hr to fix
            src/client/undo-manager.js on lines 69..76

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

            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

              performRedo (fn: (op: WrappedOperation) => void) {
                this.state = REDOING_STATE
                if (this.redoStack.length === 0) {
                  throw new Error('redo not possible')
                }
            Severity: Major
            Found in src/client/undo-manager.js and 1 other location - About 1 hr to fix
            src/client/undo-manager.js on lines 59..66

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

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

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

              const setSelection = (str) => {
                _t.context.editorAdapter.value = str
                _t.context.editorAdapter.selection = Selection.createCursor(str.length)
              }
              Severity: Major
              Found in test/src/client/test-editor-client_undo_redo.js and 1 other location - About 1 hr to fix
              test/src/client/test-editor-client.js on lines 24..27

              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

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

              const setSelection = (str) => {
                _t.context.editorAdapter.value = str
                _t.context.editorAdapter.selection = Selection.createCursor(str.length)
              }
              Severity: Major
              Found in test/src/client/test-editor-client.js and 1 other location - About 1 hr to fix
              test/src/client/test-editor-client_undo_redo.js on lines 10..13

              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

                const assertOutstanding = (ratain, str) => {
                  t.truthy(editorClient.state.outstanding.equals(new TextOperation().retain(ratain).insert(str)))
                }
              Severity: Major
              Found in test/src/client/test-editor-client.js and 3 other locations - About 1 hr to fix
              test/src/client/test-client.js on lines 54..56
              test/src/client/test-client.js on lines 58..60
              test/src/client/test-editor-client.js on lines 55..57

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

              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

                const assertBuffer = (ratain, str) => {
                  t.truthy(editorClient.state.buffer.equals(new TextOperation().retain(ratain).insert(str)))
                }
              Severity: Major
              Found in test/src/client/test-editor-client.js and 3 other locations - About 1 hr to fix
              test/src/client/test-client.js on lines 54..56
              test/src/client/test-client.js on lines 58..60
              test/src/client/test-editor-client.js on lines 51..53

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

              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

                const assertBuffer = (ratain, str) => {
                  t.truthy(client.state.buffer.equals(new TextOperation().retain(ratain).insert(str)))
                }
              Severity: Major
              Found in test/src/client/test-client.js and 3 other locations - About 1 hr to fix
              test/src/client/test-client.js on lines 54..56
              test/src/client/test-editor-client.js on lines 51..53
              test/src/client/test-editor-client.js on lines 55..57

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

              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

                const assertOutstanding = (ratain, str) => {
                  t.truthy(client.state.outstanding.equals(new TextOperation().retain(ratain).insert(str)))
                }
              Severity: Major
              Found in test/src/client/test-client.js and 3 other locations - About 1 hr to fix
              test/src/client/test-client.js on lines 58..60
              test/src/client/test-editor-client.js on lines 51..53
              test/src/client/test-editor-client.js on lines 55..57

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

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

              Severity
              Category
              Status
              Source
              Language