nponiros/sync_server

View on GitHub

Showing 43 of 43 total issues

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

      return this.store.find(query, { _id: 0, rev: 0 }).sort({ rev: 1 }).exec((err, result) => {
        if (err) {
          reject(err);
        } else {
          // See comment in add method
Severity: Major
Found in lib/db_connectors/NeDB/changes_table.js and 1 other location - About 6 hrs to fix
lib/db_connectors/NeDB/changes_table.js on lines 94..108

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

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

      return this.store.find(query, { _id: 0, source: 0 }).sort({ rev: 1 }).exec((err, result) => {
        if (err) {
          reject(err);
        } else {
          // See comment in add method
Severity: Major
Found in lib/db_connectors/NeDB/changes_table.js and 1 other location - About 6 hrs to fix
lib/db_connectors/NeDB/changes_table.js on lines 64..78

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

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

  function getID() {
    function s4() {
      return Math.floor((1 + Math.random()) * 0x10000)
          .toString(16)
          .substring(1);
Severity: Major
Found in samples/ajax/index.js and 1 other location - About 4 hrs to fix
samples/socket/index.js on lines 11..20

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

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

  function getID() {
    function s4() {
      return Math.floor((1 + Math.random()) * 0x10000)
          .toString(16)
          .substring(1);
Severity: Major
Found in samples/socket/index.js and 1 other location - About 4 hrs to fix
samples/ajax/index.js on lines 10..19

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

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 initSocketHandler has 105 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function initSocketHandler(db, logger, opts, currentDBRevision) {
  // connID to callback
  const subscriptions = new Map();
  const connToClientIdentity = new Map();
  const clientIDToRevision = new Map();
Severity: Major
Found in lib/sync/socket_handler.js - About 4 hrs to fix

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

    function handleInitialization(conn, socketHandler, request) {
      socketHandler
        .handleInitialization(conn.id, request)
        .then(({ succeeded, data }) => {
          const type = { type: succeeded ? 'clientIdentity' : 'error' };
    Severity: Major
    Found in lib/server/socket/handlers.js and 1 other location - About 2 hrs to fix
    lib/server/socket/handlers.js on lines 32..39

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

    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

    function handleClientChanges(conn, socketHandler, request) {
      socketHandler
        .handleClientChanges(conn.id, request)
        .then(({ succeeded, data }) => {
          const type = { type: succeeded ? 'ack' : 'error' };
    Severity: Major
    Found in lib/server/socket/handlers.js and 1 other location - About 2 hrs to fix
    lib/server/socket/handlers.js on lines 23..30

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

    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 applyClientChanges has 64 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function applyClientChanges(db, baseRevision, currentRevision, clientChanges, clientIdentity) {
      function handleCreate(change) {
        return db.addData(change.table, change.key, change.obj)
          .then(() => {
            return db.addChangesData({
    Severity: Major
    Found in lib/sync/apply_client_changes.js - About 2 hrs to fix

      Function initPollHandler has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function initPollHandler(db, logger, opts, currentDBRevision) {
        return function handler({
            baseRevision,
            changes = [],
            clientIdentity,
      Severity: Minor
      Found in lib/sync/poll_handler.js - About 1 hr to fix

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

            return db.addData(change.table, change.key, change.obj)
              .then(() => {
                return db.addChangesData({
                  rev: ++currentRevision.rev,
                  source: clientIdentity,
        Severity: Major
        Found in lib/sync/apply_client_changes.js and 1 other location - About 1 hr to fix
        lib/sync/apply_client_changes.js on lines 37..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 67.

        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

                  return db.updateData(change.table, change.key, data)
                    .then(() => {
                      return db.addChangesData({
                        rev: ++currentRevision.rev,
                        source: clientIdentity,
        Severity: Major
        Found in lib/sync/apply_client_changes.js and 1 other location - About 1 hr to fix
        lib/sync/apply_client_changes.js on lines 19..29

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

        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 resolveConflicts has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        module.exports = function resolveConflicts(clientChanges, serverChangeSet) {
          const resolved = [];
          clientChanges
            .forEach((clientChange) => {
              const id = `${clientChange.table}:${clientChange.key}`;
        Severity: Minor
        Found in lib/sync/resolve_conflicts.js - About 1 hr to fix

          Function setByKeyPath has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

          module.exports = function setByKeyPath(obj, keyPath, value) {
            if (!obj || typeof keyPath !== 'string') {
              return;
            }
            const period = keyPath.indexOf('.');
          Severity: Minor
          Found in lib/sync/set_key_path.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 sync has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            function sync() {
              const dataToSend = {
                baseRevision,
                changes,
                clientIdentity,
          Severity: Minor
          Found in samples/ajax/index.js - About 1 hr to fix

            Function getServerChanges has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function getServerChanges(db, syncedRevision, clientIdentity, partialsThreshold, currentDBRevision) {
              // Get all changes after syncedRevision that was not performed by the client we're talking to.
              return db.getChangesData(syncedRevision, clientIdentity)
                  // Compact changes so that multiple changes on same object are merged into a single change.
                  .then((changes) => reduceChanges(changes))
            Severity: Minor
            Found in lib/sync/get_server_changes.js - About 1 hr to fix

              Function combineUpdateAndUpdate has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              module.exports = function combineUpdateAndUpdate(prevChange, nextChange) {
                // Clone object before modifying since the earlier change in db.changes[] would otherwise be altered.
                const clonedChange = deepClone(prevChange);
                Object
                  .keys(nextChange.mods)
              Severity: Minor
              Found in lib/sync/combine_update_and_update.js - About 1 hr to fix

                Function initSocketHandler has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                function initSocketHandler(db, logger, opts, currentDBRevision) {
                  // connID to callback
                  const subscriptions = new Map();
                  const connToClientIdentity = new Map();
                  const clientIDToRevision = new Map();
                Severity: Minor
                Found in lib/sync/socket_handler.js - About 55 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 handleClientChanges has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                function handleClientChanges(db, baseRevision, nextRevision, partial, clientID, changes) {
                Severity: Minor
                Found in lib/sync/handle_client_changes.js - About 45 mins to fix

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

                    function renderList() {
                      list.innerHTML = items.map((item) => `<li>${item}</li>`).join('');
                    }
                  Severity: Minor
                  Found in samples/ajax/index.js and 1 other location - About 40 mins to fix
                  samples/socket/index.js on lines 22..24

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

                  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

                    function renderList() {
                      list.innerHTML = items.map((item) => `<li>${item}</li>`).join('');
                    }
                  Severity: Minor
                  Found in samples/socket/index.js and 1 other location - About 40 mins to fix
                  samples/ajax/index.js on lines 21..23

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

                  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

                  Severity
                  Category
                  Status
                  Source
                  Language