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.
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')
}
- Read upRead up
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')
}
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'
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,
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) {
- Read upRead up
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
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) {
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)
- Read upRead up
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++) {
- Read upRead up
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', {
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) {
- Read upRead up
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++]
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
- Read upRead up
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:
- Read upRead up
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++]
Avoid deeply nested control flow statements. Open
if (-op1 > op2) {
minl = op2
op1 = op1 + op2
op2 = ops2[i2++]
} else if (-op1 === op2) {
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) {
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 === '') {
- Read upRead up
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
}
- Read upRead up
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"