Zimbra-Community/js-zimbra

View on GitHub
lib/api/response.js

Summary

Maintainability
B
4 hrs
Test Coverage

Function _createResponseView has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

ResponseApi.prototype._createResponseView = function () {

    LOG.debug('ResponseApi#_createResponseView called');

    if (this.options.request.isBatch()) {
Severity: Minor
Found in lib/api/response.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 _createResponseView has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

ResponseApi.prototype._createResponseView = function () {

    LOG.debug('ResponseApi#_createResponseView called');

    if (this.options.request.isBatch()) {
Severity: Minor
Found in lib/api/response.js - About 1 hr to fix

    Expected space(s) after "throw".
    Open

            throw(err);
    Severity: Minor
    Found in lib/api/response.js by eslint

    enforce consistent spacing before and after keywords (keyword-spacing)

    Keywords are syntax elements of JavaScript, such as function and if. These identifiers have special meaning to the language and so often appear in a different color in code editors. As an important part of the language, style guides often refer to the spacing that should be used around keywords. For example, you might have a style guide that says keywords should be always surrounded by spaces, which would mean if-else statements must look like this:

    if (foo) {
        // ...
    } else {
        // ...
    }

    Of course, you could also have a style guide that disallows spaces around keywords.

    Rule Details

    This rule enforces consistent spacing around keywords and keyword-like tokens: as (in module declarations), async (of async functions), await (of await expressions), break, case, catch, class, const, continue, debugger, default, delete, do, else, export, extends, finally, for, from (in module declarations), function, get (of getters), if, import, in, instanceof, let, new, of (in for-of statements), return, set (of setters), static, super, switch, this, throw, try, typeof, var, void, while, with, and yield. This rule is designed carefully not to conflict with other spacing rules: it does not apply to spacing where other rules report problems.

    Options

    This rule has an object option:

    • "before": true (default) requires at least one space before keywords
    • "before": false disallows spaces before keywords
    • "after": true (default) requires at least one space after keywords
    • "after": false disallows spaces after keywords
    • "overrides" allows overriding spacing style for specified keywords

    before

    Examples of incorrect code for this rule with the default { "before": true } option:

    /*eslint keyword-spacing: ["error", { "before": true }]*/
    
    if (foo) {
        //...
    }else if (bar) {
        //...
    }else {
        //...
    }

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

    /*eslint keyword-spacing: ["error", { "before": true }]*/
    /*eslint-env es6*/
    
    if (foo) {
        //...
    } else if (bar) {
        //...
    } else {
        //...
    }
    
    // no conflict with `array-bracket-spacing`
    let a = [this];
    let b = [function() {}];
    
    // no conflict with `arrow-spacing`
    let a = ()=> this.foo;
    
    // no conflict with `block-spacing`
    {function foo() {}}
    
    // no conflict with `comma-spacing`
    let a = [100,this.foo, this.bar];
    
    // not conflict with `computed-property-spacing`
    obj[this.foo] = 0;
    
    // no conflict with `generator-star-spacing`
    function *foo() {}
    
    // no conflict with `key-spacing`
    let obj = {
        foo:function() {}
    };
    
    // no conflict with `object-curly-spacing`
    let obj = {foo: this};
    
    // no conflict with `semi-spacing`
    let a = this;function foo() {}
    
    // no conflict with `space-in-parens`
    (function () {})();
    
    // no conflict with `space-infix-ops`
    if ("foo"in {foo: 0}) {}
    if (10+this.foo<= this.bar) {}
    
    // no conflict with `jsx-curly-spacing`
    let a = 

    Examples of incorrect code for this rule with the { "before": false } option:

    /*eslint keyword-spacing: ["error", { "before": false }]*/
    
    if (foo) {
        //...
    } else if (bar) {
        //...
    } else {
        //...
    }

    Examples of correct code for this rule with the { "before": false } option:

    /*eslint keyword-spacing: ["error", { "before": false }]*/
    
    if (foo) {
        //...
    }else if (bar) {
        //...
    }else {
        //...
    }

    after

    Examples of incorrect code for this rule with the default { "after": true } option:

    /*eslint keyword-spacing: ["error", { "after": true }]*/
    
    if(foo) {
        //...
    } else if(bar) {
        //...
    } else{
        //...
    }

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

    /*eslint keyword-spacing: ["error", { "after": true }]*/
    
    if (foo) {
        //...
    } else if (bar) {
        //...
    } else {
        //...
    }
    
    // not conflict with `array-bracket-spacing`
    let a = [this];
    
    // not conflict with `arrow-spacing`
    let a = ()=> this.foo;
    
    // not conflict with `comma-spacing`
    let a = [100, this.foo, this.bar];
    
    // not conflict with `computed-property-spacing`
    obj[this.foo] = 0;
    
    // not conflict with `generator-star-spacing`
    function* foo() {}
    
    // not conflict with `key-spacing`
    let obj = {
        foo:function() {}
    };
    
    // not conflict with `func-call-spacing`
    class A {
        constructor() {
            super();
        }
    }
    
    // not conflict with `object-curly-spacing`
    let obj = {foo: this};
    
    // not conflict with `semi-spacing`
    let a = this;function foo() {}
    
    // not conflict with `space-before-function-paren`
    function() {}
    
    // no conflict with `space-infix-ops`
    if ("foo"in{foo: 0}) {}
    if (10+this.foo<= this.bar) {}
    
    // no conflict with `space-unary-ops`
    function* foo(a) {
        return yield+a;
    }
    
    // no conflict with `yield-star-spacing`
    function* foo(a) {
        return yield* a;
    }
    
    // no conflict with `jsx-curly-spacing`
    let a = 

    Examples of incorrect code for this rule with the { "after": false } option:

    /*eslint keyword-spacing: ["error", { "after": false }]*/
    
    if (foo) {
        //...
    } else if (bar) {
        //...
    } else {
        //...
    }

    Examples of correct code for this rule with the { "after": false } option:

    /*eslint keyword-spacing: ["error", { "after": false }]*/
    
    if(foo) {
        //...
    } else if(bar) {
        //...
    } else{
        //...
    }

    overrides

    Examples of correct code for this rule with the { "overrides": { "if": { "after": false }, "for": { "after": false }, "while": { "after": false } } } option:

    /*eslint keyword-spacing: ["error", { "overrides": {
      "if": { "after": false },
      "for": { "after": false },
      "while": { "after": false }
    } }]*/
    
    if(foo) {
        //...
    } else if(bar) {
        //...
    } else {
        //...
    }
    
    for(;;);
    
    while(true) {
      //...
    }

    When Not To Use It

    If you don't want to enforce consistency on keyword spacing, then it's safe to disable this rule. Source: http://eslint.org/docs/rules/

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

        try {
    
            this.options =
                new responseOptions.Constructor().validate(constructorOptions);
    
    
    Severity: Major
    Found in lib/api/response.js and 1 other location - About 1 hr to fix
    lib/api/request.js on lines 28..41

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

    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