lazycoder9/project-lvl2-s13

View on GitHub

Showing 13 of 13 total issues

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

test('JSON Differ', () => {
  const config1 = '__tests__/fixtures/1.json';
  const config2 = '__tests__/fixtures/2.json';

  const actual = differ(config1, config2);
Severity: Major
Found in __tests__/differ-test.js and 1 other location - About 1 hr to fix
__tests__/differ-test.js on lines 53..67

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

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

test('INI Differ', () => {
  const config1 = '__tests__/fixtures/1.ini';
  const config2 = '__tests__/fixtures/2.ini';

  const actual = differ(config1, config2);
Severity: Major
Found in __tests__/differ-test.js and 1 other location - About 1 hr to fix
__tests__/differ-test.js on lines 3..35

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

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

const compareValues = (value1, value2) => {
  if (value1 === value2) {
    return {
      type: 'unchanged',
      data: value1,
Severity: Minor
Found in src/differ.js - About 1 hr to fix

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

    const parseCreated = (name, data, level) => chalk.green(`${tab(level)}${name}: ${dataCheck(data, level)}`);
    Severity: Minor
    Found in src/formatters/objFormat.js and 1 other location - About 35 mins to fix
    src/formatters/objFormat.js on lines 22..22

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

    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

    const parseDeleted = (name, data, level) => chalk.red(`${tab(level)}${name}: ${dataCheck(data, level)}`);
    Severity: Minor
    Found in src/formatters/objFormat.js and 1 other location - About 35 mins to fix
    src/formatters/objFormat.js on lines 20..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 47.

    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

    Avoid too many return statements within this function.
    Open

      return {
        type: 'updated',
        data: [value2, value1],
      };
    Severity: Major
    Found in src/differ.js - About 30 mins to fix

      'iterDiffObject' was used before it was defined.
      Open

      ${data.map(e => iterDiffObject(e, level + 1))}
      Severity: Minor
      Found in src/formatters/objFormat.js by eslint

      Disallow Early Use (no-use-before-define)

      In JavaScript, prior to ES6, variable and function declarations are hoisted to the top of a scope, so it's possible to use identifiers before their formal declarations in code. This can be confusing and some believe it is best to always declare variables and functions before using them.

      In ES6, block-level bindings (let and const) introduce a "temporal dead zone" where a ReferenceError will be thrown with any attempt to access the variable before its declaration.

      Rule Details

      This rule will warn when it encounters a reference to an identifier that has not yet been declared.

      Examples of incorrect code for this rule:

      /*eslint no-use-before-define: "error"*/
      /*eslint-env es6*/
      
      alert(a);
      var a = 10;
      
      f();
      function f() {}
      
      function g() {
          return b;
      }
      var b = 1;
      
      // With blockBindings: true
      {
          alert(c);
          let c = 1;
      }

      Examples of correct code for this rule:

      /*eslint no-use-before-define: "error"*/
      /*eslint-env es6*/
      
      var a;
      a = 10;
      alert(a);
      
      function f() {}
      f(1);
      
      var b = 1;
      function g() {
          return b;
      }
      
      // With blockBindings: true
      {
          let C;
          c++;
      }

      Options

      {
          "no-use-before-define": ["error", { "functions": true, "classes": true }]
      }
      • functions (boolean) - The flag which shows whether or not this rule checks function declarations. If this is true, this rule warns every reference to a function before the function declaration. Otherwise, ignores those references. Function declarations are hoisted, so it's safe. Default is true.
      • classes (boolean) - The flag which shows whether or not this rule checks class declarations of upper scopes. If this is true, this rule warns every reference to a class before the class declaration. Otherwise, ignores those references if the declaration is in upper function scopes. Class declarations are not hoisted, so it might be danger. Default is true.
      • variables (boolean) - This flag determines whether or not the rule checks variable declarations in upper scopes. If this is true, the rule warns every reference to a variable before the variable declaration. Otherwise, the rule ignores a reference if the declaration is in an upper scope, while still reporting the reference if it's in the same scope as the declaration. Default is true.

      This rule accepts "nofunc" string as an option. "nofunc" is the same as { "functions": false, "classes": true }.

      functions

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

      /*eslint no-use-before-define: ["error", { "functions": false }]*/
      
      f();
      function f() {}

      classes

      Examples of incorrect code for the { "classes": false } option:

      /*eslint no-use-before-define: ["error", { "classes": false }]*/
      /*eslint-env es6*/
      
      new A();
      class A {
      }

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

      /*eslint no-use-before-define: ["error", { "classes": false }]*/
      /*eslint-env es6*/
      
      function foo() {
          return new A();
      }
      
      class A {
      }

      variables

      Examples of incorrect code for the { "variables": false } option:

      /*eslint no-use-before-define: ["error", { "variables": false }]*/
      
      console.log(foo);
      var foo = 1;

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

      /*eslint no-use-before-define: ["error", { "variables": false }]*/
      
      function baz() {
          console.log(foo);
      }
      
      var foo = 1;

      Source: http://eslint.org/docs/rules/

      'compareValues' was used before it was defined.
      Open

          const { type, data } = compareValues(obj1[key], obj2[key]);
      Severity: Minor
      Found in src/differ.js by eslint

      Disallow Early Use (no-use-before-define)

      In JavaScript, prior to ES6, variable and function declarations are hoisted to the top of a scope, so it's possible to use identifiers before their formal declarations in code. This can be confusing and some believe it is best to always declare variables and functions before using them.

      In ES6, block-level bindings (let and const) introduce a "temporal dead zone" where a ReferenceError will be thrown with any attempt to access the variable before its declaration.

      Rule Details

      This rule will warn when it encounters a reference to an identifier that has not yet been declared.

      Examples of incorrect code for this rule:

      /*eslint no-use-before-define: "error"*/
      /*eslint-env es6*/
      
      alert(a);
      var a = 10;
      
      f();
      function f() {}
      
      function g() {
          return b;
      }
      var b = 1;
      
      // With blockBindings: true
      {
          alert(c);
          let c = 1;
      }

      Examples of correct code for this rule:

      /*eslint no-use-before-define: "error"*/
      /*eslint-env es6*/
      
      var a;
      a = 10;
      alert(a);
      
      function f() {}
      f(1);
      
      var b = 1;
      function g() {
          return b;
      }
      
      // With blockBindings: true
      {
          let C;
          c++;
      }

      Options

      {
          "no-use-before-define": ["error", { "functions": true, "classes": true }]
      }
      • functions (boolean) - The flag which shows whether or not this rule checks function declarations. If this is true, this rule warns every reference to a function before the function declaration. Otherwise, ignores those references. Function declarations are hoisted, so it's safe. Default is true.
      • classes (boolean) - The flag which shows whether or not this rule checks class declarations of upper scopes. If this is true, this rule warns every reference to a class before the class declaration. Otherwise, ignores those references if the declaration is in upper function scopes. Class declarations are not hoisted, so it might be danger. Default is true.
      • variables (boolean) - This flag determines whether or not the rule checks variable declarations in upper scopes. If this is true, the rule warns every reference to a variable before the variable declaration. Otherwise, the rule ignores a reference if the declaration is in an upper scope, while still reporting the reference if it's in the same scope as the declaration. Default is true.

      This rule accepts "nofunc" string as an option. "nofunc" is the same as { "functions": false, "classes": true }.

      functions

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

      /*eslint no-use-before-define: ["error", { "functions": false }]*/
      
      f();
      function f() {}

      classes

      Examples of incorrect code for the { "classes": false } option:

      /*eslint no-use-before-define: ["error", { "classes": false }]*/
      /*eslint-env es6*/
      
      new A();
      class A {
      }

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

      /*eslint no-use-before-define: ["error", { "classes": false }]*/
      /*eslint-env es6*/
      
      function foo() {
          return new A();
      }
      
      class A {
      }

      variables

      Examples of incorrect code for the { "variables": false } option:

      /*eslint no-use-before-define: ["error", { "variables": false }]*/
      
      console.log(foo);
      var foo = 1;

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

      /*eslint no-use-before-define: ["error", { "variables": false }]*/
      
      function baz() {
          console.log(foo);
      }
      
      var foo = 1;

      Source: http://eslint.org/docs/rules/

      Unexpected function expression.
      Open

        .action(function (firstConfig, secondConfig) {
      Severity: Minor
      Found in src/bin/gendiff.js by eslint

      Suggest using arrow functions as callbacks. (prefer-arrow-callback)

      Arrow functions are suited to callbacks, because:

      • this keywords in arrow functions bind to the upper scope's.
      • The notation of the arrow function is shorter than function expression's.

      Rule Details

      This rule is aimed to flag usage of function expressions in an argument list.

      The following patterns are considered problems:

      /*eslint prefer-arrow-callback: "error"*/
      
      foo(function(a) { return a; });
      foo(function() { return this.a; }.bind(this));

      The following patterns are not considered problems:

      /*eslint prefer-arrow-callback: "error"*/
      /*eslint-env es6*/
      
      foo(a => a);
      foo(function*() { yield; });
      
      // this is not a callback.
      var foo = function foo(a) { return a; };
      
      // using `this` without `.bind(this)`.
      foo(function() { return this.a; });
      
      // recursively.
      foo(function bar(n) { return n && n + bar(n - 1); });

      Options

      This rule takes one optional argument, an object which is an options object.

      allowNamedFunctions

      This is a boolean option and it is false by default. When set to true, the rule doesn't warn on named functions used as callbacks.

      Examples of correct code for the { "allowNamedFunctions": true } option:

      /*eslint prefer-arrow-callback: ["error", { "allowNamedFunctions": true }]*/
      
      foo(function bar() {});

      allowUnboundThis

      This is a boolean option and it is true by default. When set to false, this option allows the use of this without restriction and checks for dynamically assigned this values such as when using Array.prototype.map with a context argument. Normally, the rule will flag the use of this whenever a function does not use bind() to specify the value of this constantly.

      Examples of incorrect code for the { "allowUnboundThis": false } option:

      /*eslint prefer-arrow-callback: ["error", { "allowUnboundThis": false }]*/
      /*eslint-env es6*/
      
      foo(function() { this.a; });
      
      foo(function() { (() => this); });
      
      someArray.map(function (itm) { return this.doSomething(itm); }, someObject);

      When Not To Use It

      This rule should not be used in ES3/5 environments.

      In ES2015 (ES6) or later, if you don't want to be notified about function expressions in an argument list, you can safely disable this rule. Source: http://eslint.org/docs/rules/

      Arrow function used ambiguously with a conditional expression.
      Open

      const parentCheck = parent => typeof parent !== 'number' ? `${parent}.` : '';
      Severity: Minor
      Found in src/formatters/plainFormat.js by eslint

      Disallow arrow functions where they could be confused with comparisons (no-confusing-arrow)

      Arrow functions (=>) are similar in syntax to some comparison operators (>, <, <=, and >=). This rule warns against using the arrow function syntax in places where it could be confused with a comparison operator. Even if the arguments of the arrow function are wrapped with parens, this rule still warns about it unless allowParens is set to true.

      Here's an example where the usage of => could be confusing:

      // The intent is not clear
      var x = a => 1 ? 2 : 3;
      // Did the author mean this
      var x = function (a) { return 1 ? 2 : 3 };
      // Or this
      var x = a <= 1 ? 2 : 3;

      Rule Details

      Examples of incorrect code for this rule:

      /*eslint no-confusing-arrow: "error"*/
      /*eslint-env es6*/
      
      var x = a => 1 ? 2 : 3;
      var x = (a) => 1 ? 2 : 3;
      var x = (a) => (1 ? 2 : 3);

      Examples of correct code for this rule:

      /*eslint no-confusing-arrow: "error"*/
      /*eslint-env es6*/
      
      var x = a => { return 1 ? 2 : 3; };
      var x = (a) => { return 1 ? 2 : 3; };

      Options

      This rule accepts a single options argument with the following defaults:

      {
          "rules": {
              "no-confusing-arrow": ["error", {"allowParens": false}]
          }
      }

      allowParens is a boolean setting that can be true or false:

      1. true relaxes the rule and accepts parenthesis as a valid "confusion-preventing" syntax.
      2. false warns even if the expression is wrapped in parenthesis

      Examples of correct code for this rule with the {"allowParens": true} option:

      /*eslint no-confusing-arrow: ["error", {"allowParens": true}]*/
      /*eslint-env es6*/
      var x = a => (1 ? 2 : 3);
      var x = (a) => (1 ? 2 : 3);

      Related Rules

      Unexpected console statement.
      Open

          console.log(differ(firstConfig, secondConfig, program.format));
      Severity: Minor
      Found in src/bin/gendiff.js by eslint

      disallow the use of console (no-console)

      In JavaScript that is designed to be executed in the browser, it's considered a best practice to avoid using methods on console. Such messages are considered to be for debugging purposes and therefore not suitable to ship to the client. In general, calls using console should be stripped before being pushed to production.

      console.log("Made it here.");
      console.error("That shouldn't have happened.");

      Rule Details

      This rule disallows calls to methods of the console object.

      Examples of incorrect code for this rule:

      /*eslint no-console: "error"*/
      
      console.log("Log a debug level message.");
      console.warn("Log a warn level message.");
      console.error("Log an error level message.");

      Examples of correct code for this rule:

      /*eslint no-console: "error"*/
      
      // custom console
      Console.log("Hello world!");

      Options

      This rule has an object option for exceptions:

      • "allow" has an array of strings which are allowed methods of the console object

      Examples of additional correct code for this rule with a sample { "allow": ["warn", "error"] } option:

      /*eslint no-console: ["error", { allow: ["warn", "error"] }] */
      
      console.warn("Log a warn level message.");
      console.error("Log an error level message.");

      When Not To Use It

      If you're using Node.js, however, console is used to output information to the user and so is not strictly used for debugging purposes. If you are developing for Node.js then you most likely do not want this rule enabled.

      Related Rules

      Unexpected unnamed function.
      Open

        .action(function (firstConfig, secondConfig) {
      Severity: Minor
      Found in src/bin/gendiff.js by eslint

      Require or disallow named function expressions (func-names)

      A pattern that's becoming more common is to give function expressions names to aid in debugging. For example:

      Foo.prototype.bar = function bar() {};

      Adding the second bar in the above example is optional. If you leave off the function name then when the function throws an exception you are likely to get something similar to anonymous function in the stack trace. If you provide the optional name for a function expression then you will get the name of the function expression in the stack trace.

      Rule Details

      This rule can enforce or disallow the use of named function expressions.

      Options

      This rule has a string option:

      • "always" (default) requires function expressions to have a name
      • "as-needed" requires function expressions to have a name, if the name cannot be assigned automatically in an ES6 environment
      • "never" disallows named function expressions, except in recursive functions, where a name is needed

      always

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

      /*eslint func-names: ["error", "always"]*/
      
      Foo.prototype.bar = function() {};
      
      (function() {
          // ...
      }())

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

      /*eslint func-names: ["error", "always"]*/
      
      Foo.prototype.bar = function bar() {};
      
      (function bar() {
          // ...
      }())

      as-needed

      ECMAScript 6 introduced a name property on all functions. The value of name is determined by evaluating the code around the function to see if a name can be inferred. For example, a function assigned to a variable will automatically have a name property equal to the name of the variable. The value of name is then used in stack traces for easier debugging.

      Examples of incorrect code for this rule with the default "as-needed" option:

      /*eslint func-names: ["error", "as-needed"]*/
      
      Foo.prototype.bar = function() {};
      
      (function() {
          // ...
      }())

      Examples of correct code for this rule with the default "as-needed" option:

      /*eslint func-names: ["error", "as-needed"]*/
      
      var bar = function() {};
      
      (function bar() {
          // ...
      }())

      never

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

      /*eslint func-names: ["error", "never"]*/
      
      Foo.prototype.bar = function bar() {};
      
      (function bar() {
          // ...
      }())

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

      /*eslint func-names: ["error", "never"]*/
      
      Foo.prototype.bar = function() {};
      
      (function() {
          // ...
      }())

      Further Reading

      Compatibility

      'iterDiffObject' was used before it was defined.
      Open

      const parseObject = (name, data) => data.map(e => `${iterDiffObject(e, name)}`);
      Severity: Minor
      Found in src/formatters/plainFormat.js by eslint

      Disallow Early Use (no-use-before-define)

      In JavaScript, prior to ES6, variable and function declarations are hoisted to the top of a scope, so it's possible to use identifiers before their formal declarations in code. This can be confusing and some believe it is best to always declare variables and functions before using them.

      In ES6, block-level bindings (let and const) introduce a "temporal dead zone" where a ReferenceError will be thrown with any attempt to access the variable before its declaration.

      Rule Details

      This rule will warn when it encounters a reference to an identifier that has not yet been declared.

      Examples of incorrect code for this rule:

      /*eslint no-use-before-define: "error"*/
      /*eslint-env es6*/
      
      alert(a);
      var a = 10;
      
      f();
      function f() {}
      
      function g() {
          return b;
      }
      var b = 1;
      
      // With blockBindings: true
      {
          alert(c);
          let c = 1;
      }

      Examples of correct code for this rule:

      /*eslint no-use-before-define: "error"*/
      /*eslint-env es6*/
      
      var a;
      a = 10;
      alert(a);
      
      function f() {}
      f(1);
      
      var b = 1;
      function g() {
          return b;
      }
      
      // With blockBindings: true
      {
          let C;
          c++;
      }

      Options

      {
          "no-use-before-define": ["error", { "functions": true, "classes": true }]
      }
      • functions (boolean) - The flag which shows whether or not this rule checks function declarations. If this is true, this rule warns every reference to a function before the function declaration. Otherwise, ignores those references. Function declarations are hoisted, so it's safe. Default is true.
      • classes (boolean) - The flag which shows whether or not this rule checks class declarations of upper scopes. If this is true, this rule warns every reference to a class before the class declaration. Otherwise, ignores those references if the declaration is in upper function scopes. Class declarations are not hoisted, so it might be danger. Default is true.
      • variables (boolean) - This flag determines whether or not the rule checks variable declarations in upper scopes. If this is true, the rule warns every reference to a variable before the variable declaration. Otherwise, the rule ignores a reference if the declaration is in an upper scope, while still reporting the reference if it's in the same scope as the declaration. Default is true.

      This rule accepts "nofunc" string as an option. "nofunc" is the same as { "functions": false, "classes": true }.

      functions

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

      /*eslint no-use-before-define: ["error", { "functions": false }]*/
      
      f();
      function f() {}

      classes

      Examples of incorrect code for the { "classes": false } option:

      /*eslint no-use-before-define: ["error", { "classes": false }]*/
      /*eslint-env es6*/
      
      new A();
      class A {
      }

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

      /*eslint no-use-before-define: ["error", { "classes": false }]*/
      /*eslint-env es6*/
      
      function foo() {
          return new A();
      }
      
      class A {
      }

      variables

      Examples of incorrect code for the { "variables": false } option:

      /*eslint no-use-before-define: ["error", { "variables": false }]*/
      
      console.log(foo);
      var foo = 1;

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

      /*eslint no-use-before-define: ["error", { "variables": false }]*/
      
      function baz() {
          console.log(foo);
      }
      
      var foo = 1;

      Source: http://eslint.org/docs/rules/

      Severity
      Category
      Status
      Source
      Language