nponiros/sync_server

View on GitHub
samples/ajax/index.js

Summary

Maintainability
B
6 hrs
Test Coverage

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

    'Headers' is not defined.
    Open

        const headers = new Headers();
    Severity: Minor
    Found in samples/ajax/index.js by eslint

    Disallow Undeclared Variables (no-undef)

    This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

    Rule Details

    Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

    Examples of incorrect code for this rule:

    /*eslint no-undef: "error"*/
    
    var a = someFunction();
    b = 10;

    Examples of correct code for this rule with global declaration:

    /*global someFunction b:true*/
    /*eslint no-undef: "error"*/
    
    var a = someFunction();
    b = 10;

    The b:true syntax in /*global */ indicates that assignment to b is correct.

    Examples of incorrect code for this rule with global declaration:

    /*global b*/
    /*eslint no-undef: "error"*/
    
    b = 10;

    By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

    Options

    • typeof set to true will warn for variables used inside typeof check (Default false).

    typeof

    Examples of correct code for the default { "typeof": false } option:

    /*eslint no-undef: "error"*/
    
    if (typeof UndefinedIdentifier === "undefined") {
        // do something ...
    }

    You can use this option if you want to prevent typeof check on a variable which has not been declared.

    Examples of incorrect code for the { "typeof": true } option:

    /*eslint no-undef: ["error", { "typeof": true }] */
    
    if(typeof a === "string"){}

    Examples of correct code for the { "typeof": true } option with global declaration:

    /*global a*/
    /*eslint no-undef: ["error", { "typeof": true }] */
    
    if(typeof a === "string"){}

    Environments

    For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

    browser

    Examples of correct code for this rule with browser environment:

    /*eslint no-undef: "error"*/
    /*eslint-env browser*/
    
    setTimeout(function() {
        alert("Hello");
    });

    node

    Examples of correct code for this rule with node environment:

    /*eslint no-undef: "error"*/
    /*eslint-env node*/
    
    var fs = require("fs");
    module.exports = function() {
        console.log(fs);
    };

    When Not To Use It

    If explicit declaration of global variables is not to your taste.

    Compatibility

    This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

    'fetch' is not defined.
    Open

        fetch(URL, {
    Severity: Minor
    Found in samples/ajax/index.js by eslint

    Disallow Undeclared Variables (no-undef)

    This rule can help you locate potential ReferenceErrors resulting from misspellings of variable and parameter names, or accidental implicit globals (for example, from forgetting the var keyword in a for loop initializer).

    Rule Details

    Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/ comment.

    Examples of incorrect code for this rule:

    /*eslint no-undef: "error"*/
    
    var a = someFunction();
    b = 10;

    Examples of correct code for this rule with global declaration:

    /*global someFunction b:true*/
    /*eslint no-undef: "error"*/
    
    var a = someFunction();
    b = 10;

    The b:true syntax in /*global */ indicates that assignment to b is correct.

    Examples of incorrect code for this rule with global declaration:

    /*global b*/
    /*eslint no-undef: "error"*/
    
    b = 10;

    By default, variables declared in /*global */ are read-only, therefore assignment is incorrect.

    Options

    • typeof set to true will warn for variables used inside typeof check (Default false).

    typeof

    Examples of correct code for the default { "typeof": false } option:

    /*eslint no-undef: "error"*/
    
    if (typeof UndefinedIdentifier === "undefined") {
        // do something ...
    }

    You can use this option if you want to prevent typeof check on a variable which has not been declared.

    Examples of incorrect code for the { "typeof": true } option:

    /*eslint no-undef: ["error", { "typeof": true }] */
    
    if(typeof a === "string"){}

    Examples of correct code for the { "typeof": true } option with global declaration:

    /*global a*/
    /*eslint no-undef: ["error", { "typeof": true }] */
    
    if(typeof a === "string"){}

    Environments

    For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in Specifying Environments. A few examples are given below.

    browser

    Examples of correct code for this rule with browser environment:

    /*eslint no-undef: "error"*/
    /*eslint-env browser*/
    
    setTimeout(function() {
        alert("Hello");
    });

    node

    Examples of correct code for this rule with node environment:

    /*eslint no-undef: "error"*/
    /*eslint-env node*/
    
    var fs = require("fs");
    module.exports = function() {
        console.log(fs);
    };

    When Not To Use It

    If explicit declaration of global variables is not to your taste.

    Compatibility

    This rule provides compatibility with treatment of global variables in JSHint and JSLint. Source: http://eslint.org/docs/rules/

    A space is required after '{'.
    Open

            obj: {item: input.value},
    Severity: Minor
    Found in samples/ajax/index.js by eslint

    enforce consistent spacing inside braces (object-curly-spacing)

    While formatting preferences are very personal, a number of style guides require or disallow spaces between curly braces in the following situations:

    // simple object literals
    var obj = { foo: "bar" };
    
    // nested object literals
    var obj = { foo: { zoo: "bar" } };
    
    // destructuring assignment (EcmaScript 6)
    var { x, y } = y;
    
    // import/export declarations (EcmaScript 6)
    import { foo } from "bar";
    export { foo };

    Rule Details

    This rule enforce consistent spacing inside braces of object literals, destructuring assignments, and import/export specifiers.

    Options

    This rule has two options, a string option and an object option.

    String option:

    • "never" (default) disallows spacing inside of braces
    • "always" requires spacing inside of braces (except {})

    Object option:

    • "arraysInObjects": true requires spacing inside of braces of objects beginning and/or ending with an array element (applies when the first option is set to never)
    • "arraysInObjects": false disallows spacing inside of braces of objects beginning and/or ending with an array element (applies when the first option is set to always)
    • "objectsInObjects": true requires spacing inside of braces of objects beginning and/or ending with an object element (applies when the first option is set to never)
    • "objectsInObjects": false disallows spacing inside of braces of objects beginning and/or ending with an object element (applies when the first option is set to always)

    never

    Examples of incorrect code for this rule with the default "never" option:

    /*eslint object-curly-spacing: ["error", "never"]*/
    
    var obj = { 'foo': 'bar' };
    var obj = {'foo': 'bar' };
    var obj = { baz: {'foo': 'qux'}, bar};
    var obj = {baz: { 'foo': 'qux'}, bar};
    var {x } = y;
    import { foo } from 'bar';

    Examples of correct code for this rule with the default "never" option:

    /*eslint object-curly-spacing: ["error", "never"]*/
    
    var obj = {'foo': 'bar'};
    var obj = {'foo': {'bar': 'baz'}, 'qux': 'quxx'};
    var obj = {
      'foo': 'bar'
    };
    var obj = {'foo': 'bar'
    };
    var obj = {
      'foo':'bar'};
    var obj = {};
    var {x} = y;
    import {foo} from 'bar';

    always

    Examples of incorrect code for this rule with the "always" option:

    /*eslint object-curly-spacing: ["error", "always"]*/
    
    var obj = {'foo': 'bar'};
    var obj = {'foo': 'bar' };
    var obj = { baz: {'foo': 'qux'}, bar};
    var obj = {baz: { 'foo': 'qux' }, bar};
    var obj = {'foo': 'bar'
    };
    var obj = {
      'foo':'bar'};
    var {x} = y;
    import {foo } from 'bar';

    Examples of correct code for this rule with the "always" option:

    /*eslint object-curly-spacing: ["error", "always"]*/
    
    var obj = {};
    var obj = { 'foo': 'bar' };
    var obj = { 'foo': { 'bar': 'baz' }, 'qux': 'quxx' };
    var obj = {
      'foo': 'bar'
    };
    var { x } = y;
    import { foo } from 'bar';

    arraysInObjects

    Examples of additional correct code for this rule with the "never", { "arraysInObjects": true } options:

    /*eslint object-curly-spacing: ["error", "never", { "arraysInObjects": true }]*/
    
    var obj = {"foo": [ 1, 2 ] };
    var obj = {"foo": [ "baz", "bar" ] };

    Examples of additional correct code for this rule with the "always", { "arraysInObjects": false } options:

    /*eslint object-curly-spacing: ["error", "always", { "arraysInObjects": false }]*/
    
    var obj = { "foo": [ 1, 2 ]};
    var obj = { "foo": [ "baz", "bar" ]};

    objectsInObjects

    Examples of additional correct code for this rule with the "never", { "objectsInObjects": true } options:

    /*eslint object-curly-spacing: ["error", "never", { "objectsInObjects": true }]*/
    
    var obj = {"foo": {"baz": 1, "bar": 2} };

    Examples of additional correct code for this rule with the "always", { "objectsInObjects": false } options:

    /*eslint object-curly-spacing: ["error", "always", { "objectsInObjects": false }]*/
    
    var obj = { "foo": { "baz": 1, "bar": 2 }};

    When Not To Use It

    You can turn this rule off if you are not concerned with the consistency of spacing between curly braces.

    Related Rules

    A space is required before '}'.
    Open

            obj: {item: input.value},
    Severity: Minor
    Found in samples/ajax/index.js by eslint

    enforce consistent spacing inside braces (object-curly-spacing)

    While formatting preferences are very personal, a number of style guides require or disallow spaces between curly braces in the following situations:

    // simple object literals
    var obj = { foo: "bar" };
    
    // nested object literals
    var obj = { foo: { zoo: "bar" } };
    
    // destructuring assignment (EcmaScript 6)
    var { x, y } = y;
    
    // import/export declarations (EcmaScript 6)
    import { foo } from "bar";
    export { foo };

    Rule Details

    This rule enforce consistent spacing inside braces of object literals, destructuring assignments, and import/export specifiers.

    Options

    This rule has two options, a string option and an object option.

    String option:

    • "never" (default) disallows spacing inside of braces
    • "always" requires spacing inside of braces (except {})

    Object option:

    • "arraysInObjects": true requires spacing inside of braces of objects beginning and/or ending with an array element (applies when the first option is set to never)
    • "arraysInObjects": false disallows spacing inside of braces of objects beginning and/or ending with an array element (applies when the first option is set to always)
    • "objectsInObjects": true requires spacing inside of braces of objects beginning and/or ending with an object element (applies when the first option is set to never)
    • "objectsInObjects": false disallows spacing inside of braces of objects beginning and/or ending with an object element (applies when the first option is set to always)

    never

    Examples of incorrect code for this rule with the default "never" option:

    /*eslint object-curly-spacing: ["error", "never"]*/
    
    var obj = { 'foo': 'bar' };
    var obj = {'foo': 'bar' };
    var obj = { baz: {'foo': 'qux'}, bar};
    var obj = {baz: { 'foo': 'qux'}, bar};
    var {x } = y;
    import { foo } from 'bar';

    Examples of correct code for this rule with the default "never" option:

    /*eslint object-curly-spacing: ["error", "never"]*/
    
    var obj = {'foo': 'bar'};
    var obj = {'foo': {'bar': 'baz'}, 'qux': 'quxx'};
    var obj = {
      'foo': 'bar'
    };
    var obj = {'foo': 'bar'
    };
    var obj = {
      'foo':'bar'};
    var obj = {};
    var {x} = y;
    import {foo} from 'bar';

    always

    Examples of incorrect code for this rule with the "always" option:

    /*eslint object-curly-spacing: ["error", "always"]*/
    
    var obj = {'foo': 'bar'};
    var obj = {'foo': 'bar' };
    var obj = { baz: {'foo': 'qux'}, bar};
    var obj = {baz: { 'foo': 'qux' }, bar};
    var obj = {'foo': 'bar'
    };
    var obj = {
      'foo':'bar'};
    var {x} = y;
    import {foo } from 'bar';

    Examples of correct code for this rule with the "always" option:

    /*eslint object-curly-spacing: ["error", "always"]*/
    
    var obj = {};
    var obj = { 'foo': 'bar' };
    var obj = { 'foo': { 'bar': 'baz' }, 'qux': 'quxx' };
    var obj = {
      'foo': 'bar'
    };
    var { x } = y;
    import { foo } from 'bar';

    arraysInObjects

    Examples of additional correct code for this rule with the "never", { "arraysInObjects": true } options:

    /*eslint object-curly-spacing: ["error", "never", { "arraysInObjects": true }]*/
    
    var obj = {"foo": [ 1, 2 ] };
    var obj = {"foo": [ "baz", "bar" ] };

    Examples of additional correct code for this rule with the "always", { "arraysInObjects": false } options:

    /*eslint object-curly-spacing: ["error", "always", { "arraysInObjects": false }]*/
    
    var obj = { "foo": [ 1, 2 ]};
    var obj = { "foo": [ "baz", "bar" ]};

    objectsInObjects

    Examples of additional correct code for this rule with the "never", { "objectsInObjects": true } options:

    /*eslint object-curly-spacing: ["error", "never", { "objectsInObjects": true }]*/
    
    var obj = {"foo": {"baz": 1, "bar": 2} };

    Examples of additional correct code for this rule with the "always", { "objectsInObjects": false } options:

    /*eslint object-curly-spacing: ["error", "always", { "objectsInObjects": false }]*/
    
    var obj = { "foo": { "baz": 1, "bar": 2 }};

    When Not To Use It

    You can turn this rule off if you are not concerned with the consistency of spacing between curly braces.

    Related Rules

    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

    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

    There are no issues that match your filters.

    Category
    Status