Showing 72 of 72 total issues
File doc.js
has 512 lines of code (exceeds 250 allowed). Consider refactoring. Open
import types from 'ottypes'
import {EventEmitter} from 'events'
import {isNoOp, tryCompose, xf} from './ops'
File session.js
has 476 lines of code (exceeds 250 allowed). Consider refactoring. Open
// This implements the network API for ShareJS.
//
// The wire protocol is speccced out here:
// https://github.com/josephg/ShareJS/wiki/Wire-Protocol
//
Similar blocks of code found in 2 locations. Consider refactoring. Open
case 'delete':
if (c.li === void 0 && c.ld !== void 0) {
cb(c.p[c.p.length - 1], c.ld)
} else if (c.oi === void 0 && c.od !== void 0) {
cb(c.p[c.p.length - 1], c.od)
- Read upRead up
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 182.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
case 'insert':
if (c.li !== void 0 && c.ld === void 0) {
cb(c.p[c.p.length - 1], c.li)
} else if (c.oi !== void 0 && c.od === void 0) {
cb(c.p[c.p.length - 1], c.oi)
- Read upRead up
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 182.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Function _handleMessage
has 153 lines of code (exceeds 25 allowed). Consider refactoring. Open
Session.prototype._handleMessage = function(req, callback) {
// First some checks of the incoming request. Error will be set to a value if a problem is found.
var error;
if ((error = this._checkRequest(req))) {
console.warn('Warning: Invalid request from ', this.agent.sessionId, req, 'Error: ', error);
Function _onMessage
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
_onMessage(msg) {
if ((msg.a === 'qfetch') !== (this.type === 'fetch')) {
if (console) console.warn('Invalid message sent to query', msg, this)
return
}
- 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 _handleMessage
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
Session.prototype._handleMessage = function(req, callback) {
// First some checks of the incoming request. Error will be set to a value if a problem is found.
var error;
if ((error = this._checkRequest(req))) {
console.warn('Warning: Invalid request from ', this.agent.sessionId, req, 'Error: ', error);
- 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
Doc
has 35 functions (exceeds 20 allowed). Consider refactoring. Open
class Doc extends EventEmitter {
constructor(connection, collection, name) {
super()
this.connection = connection
Function handleMessage
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
handleMessage(msg) {
const {
// action
a,
// collection name
- 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
File json-api.js
has 325 lines of code (exceeds 250 allowed). Consider refactoring. Open
// JSON document API for the 'json0' type.
import types from 'ottypes'
import Context from '../context'
Function _otApply
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
_otApply(opData, context) {
this.locked = true
if (opData.create) {
// If the type is currently set, it means we tried creating the document
- 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 _onMessage
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
_onMessage(msg) {
if (msg.c !== this.collection || msg.d !== this.name) {
// This should never happen - its a sanity check for bugs
// in the connection code.
throw new Error(
- 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 exports
has 82 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function(share) {
var router = new Router();
var auth = function(req, res, next) {
if (req.session && req.session.shareAgent) {
File connection.js
has 286 lines of code (exceeds 250 allowed). Consider refactoring. Open
import {EventEmitter} from 'events'
import Doc from './doc'
import Query from './query'
Function _checkRequest
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
Session.prototype._checkRequest = function(req) {
if (req.a === 'qsub' || req.a === 'qfetch' || req.a === 'qunsub') {
// Query messages need an ID property.
if (typeof req.id !== 'number') return 'Missing query ID';
} else if (req.a === 'op' || req.a === 'sub' || req.a === 'unsub' || req.a === 'fetch') {
- 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 _onMessage
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
_onMessage(msg) {
if (msg.c !== this.collection || msg.d !== this.name) {
// This should never happen - its a sanity check for bugs
// in the connection code.
throw new Error(
Function _onMessage
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
_onMessage(msg) {
if ((msg.a === 'qfetch') !== (this.type === 'fetch')) {
if (console) console.warn('Invalid message sent to query', msg, this)
return
}
File useragent.js
has 266 lines of code (exceeds 250 allowed). Consider refactoring. Open
var hat = require('hat');
var TransformStream = require('stream').Transform;
var async = require('async');
Function bindToSocket
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
bindToSocket(socket) {
if (this.socket) {
delete this.socket.onopen
delete this.socket.onclose
delete this.socket.onmessage
- 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 _onOp
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
_onOp(op) {
op.forEach(c => {
this._fixComponentPaths(c)
if (c.lm !== void 0) {