Dignifiedquire/ShareJS

View on GitHub

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'

Severity: Major
Found in lib/client/doc.js - About 1 day to fix

    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
    //
    Severity: Minor
    Found in lib/server/session.js - About 7 hrs to fix

      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)
      Severity: Major
      Found in lib/client/types/json-api.js and 1 other location - About 7 hrs to fix
      lib/client/types/json-api.js on lines 371..379

      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

      Further Reading

      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)
      Severity: Major
      Found in lib/client/types/json-api.js and 1 other location - About 7 hrs to fix
      lib/client/types/json-api.js on lines 380..388

      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

      Further Reading

      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);
      Severity: Major
      Found in lib/server/session.js - About 6 hrs to fix

        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
            }
        Severity: Minor
        Found in lib/client/query.js - About 4 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 _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);
        Severity: Minor
        Found in lib/server/session.js - About 4 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

        Doc has 35 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class Doc extends EventEmitter {
          constructor(connection, collection, name) {
            super()
        
            this.connection = connection
        Severity: Minor
        Found in lib/client/doc.js - About 4 hrs to fix

          Function handleMessage has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
          Open

            handleMessage(msg) {
              const {
                // action
                a,
                // collection name
          Severity: Minor
          Found in lib/client/connection.js - About 4 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

          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'
          Severity: Minor
          Found in lib/client/types/json-api.js - About 3 hrs to fix

            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
            Severity: Minor
            Found in lib/client/doc.js - 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 _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(
            Severity: Minor
            Found in lib/client/doc.js - 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 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) {
            Severity: Major
            Found in lib/server/rest.js - About 3 hrs to fix

              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'
              
              
              Severity: Minor
              Found in lib/client/connection.js - About 2 hrs to fix

                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') {
                Severity: Minor
                Found in lib/server/session.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 _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(
                Severity: Major
                Found in lib/client/doc.js - About 2 hrs to fix

                  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
                      }
                  Severity: Major
                  Found in lib/client/query.js - About 2 hrs to fix

                    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');
                    
                    
                    
                    Severity: Minor
                    Found in lib/server/useragent.js - About 2 hrs to fix

                      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
                      Severity: Minor
                      Found in lib/client/connection.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 _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) {
                      Severity: Major
                      Found in lib/client/types/json-api.js - About 2 hrs to fix
                        Severity
                        Category
                        Status
                        Source
                        Language