Zimbra-Community/js-zimbra

View on GitHub
lib/utils/preauth.js

Summary

Maintainability
C
7 hrs
Test Coverage

Function createPreauth has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    createPreauth: function (options, callback) {

        LOG.debug('preauth#createPreauth called');
        LOG.debug('Validating options');

Severity: Minor
Found in lib/utils/preauth.js - About 1 hr to fix

    A function with a name starting with an uppercase letter should only be used as a constructor.
    Open

                        commonErrors.InvalidOption(
    Severity: Minor
    Found in lib/utils/preauth.js by eslint

    require constructor names to begin with a capital letter (new-cap)

    The new operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.

    var friend = new Person();

    Rule Details

    This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:

    • Array
    • Boolean
    • Date
    • Error
    • Function
    • Number
    • Object
    • RegExp
    • String
    • Symbol

    Examples of correct code for this rule:

    /*eslint new-cap: "error"*/
    
    function foo(arg) {
        return Boolean(arg);
    }

    Options

    This rule has an object option:

    • "newIsCap": true (default) requires all new operators to be called with uppercase-started functions.
    • "newIsCap": false allows new operators to be called with lowercase-started or uppercase-started functions.
    • "capIsNew": true (default) requires all uppercase-started functions to be called with new operators.
    • "capIsNew": false allows uppercase-started functions to be called without new operators.
    • "newIsCapExceptions" allows specified lowercase-started function names to be called with the new operator.
    • "newIsCapExceptionPattern" allows any lowercase-started function names that match the specified regex pattern to be called with the new operator.
    • "capIsNewExceptions" allows specified uppercase-started function names to be called without the new operator.
    • "capIsNewExceptionPattern" allows any uppercase-started function names that match the specified regex pattern to be called without the new operator.
    • "properties": true (default) enables checks on object properties
    • "properties": false disables checks on object properties

    newIsCap

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

    /*eslint new-cap: ["error", { "newIsCap": true }]*/
    
    var friend = new person();

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

    /*eslint new-cap: ["error", { "newIsCap": true }]*/
    
    var friend = new Person();

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

    /*eslint new-cap: ["error", { "newIsCap": false }]*/
    
    var friend = new person();

    capIsNew

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

    /*eslint new-cap: ["error", { "capIsNew": true }]*/
    
    var colleague = Person();

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

    /*eslint new-cap: ["error", { "capIsNew": true }]*/
    
    var colleague = new Person();

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

    /*eslint new-cap: ["error", { "capIsNew": false }]*/
    
    var colleague = Person();

    newIsCapExceptions

    Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] } option:

    /*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
    
    var events = require('events');
    
    var emitter = new events();

    newIsCapExceptionPattern

    Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." } option:

    /*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
    
    var friend = new person.acquaintance();
    var bestFriend = new person.friend();

    capIsNewExceptions

    Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] } option:

    /*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
    
    function foo(arg) {
        return Person(arg);
    }

    capIsNewExceptionPattern

    Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." } option:

    /*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
    
    var friend = person.Acquaintance();
    var bestFriend = person.Friend();

    properties

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

    /*eslint new-cap: ["error", { "properties": true }]*/
    
    var friend = new person.acquaintance();

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

    /*eslint new-cap: ["error", { "properties": true }]*/
    
    var friend = new person.Acquaintance();

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

    /*eslint new-cap: ["error", { "properties": false }]*/
    
    var friend = new person.acquaintance();

    When Not To Use It

    If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/

    A function with a name starting with an uppercase letter should only be used as a constructor.
    Open

                        commonErrors.SystemError(
    Severity: Minor
    Found in lib/utils/preauth.js by eslint

    require constructor names to begin with a capital letter (new-cap)

    The new operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.

    var friend = new Person();

    Rule Details

    This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:

    • Array
    • Boolean
    • Date
    • Error
    • Function
    • Number
    • Object
    • RegExp
    • String
    • Symbol

    Examples of correct code for this rule:

    /*eslint new-cap: "error"*/
    
    function foo(arg) {
        return Boolean(arg);
    }

    Options

    This rule has an object option:

    • "newIsCap": true (default) requires all new operators to be called with uppercase-started functions.
    • "newIsCap": false allows new operators to be called with lowercase-started or uppercase-started functions.
    • "capIsNew": true (default) requires all uppercase-started functions to be called with new operators.
    • "capIsNew": false allows uppercase-started functions to be called without new operators.
    • "newIsCapExceptions" allows specified lowercase-started function names to be called with the new operator.
    • "newIsCapExceptionPattern" allows any lowercase-started function names that match the specified regex pattern to be called with the new operator.
    • "capIsNewExceptions" allows specified uppercase-started function names to be called without the new operator.
    • "capIsNewExceptionPattern" allows any uppercase-started function names that match the specified regex pattern to be called without the new operator.
    • "properties": true (default) enables checks on object properties
    • "properties": false disables checks on object properties

    newIsCap

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

    /*eslint new-cap: ["error", { "newIsCap": true }]*/
    
    var friend = new person();

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

    /*eslint new-cap: ["error", { "newIsCap": true }]*/
    
    var friend = new Person();

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

    /*eslint new-cap: ["error", { "newIsCap": false }]*/
    
    var friend = new person();

    capIsNew

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

    /*eslint new-cap: ["error", { "capIsNew": true }]*/
    
    var colleague = Person();

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

    /*eslint new-cap: ["error", { "capIsNew": true }]*/
    
    var colleague = new Person();

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

    /*eslint new-cap: ["error", { "capIsNew": false }]*/
    
    var colleague = Person();

    newIsCapExceptions

    Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] } option:

    /*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
    
    var events = require('events');
    
    var emitter = new events();

    newIsCapExceptionPattern

    Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." } option:

    /*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
    
    var friend = new person.acquaintance();
    var bestFriend = new person.friend();

    capIsNewExceptions

    Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] } option:

    /*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
    
    function foo(arg) {
        return Person(arg);
    }

    capIsNewExceptionPattern

    Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." } option:

    /*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
    
    var friend = person.Acquaintance();
    var bestFriend = person.Friend();

    properties

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

    /*eslint new-cap: ["error", { "properties": true }]*/
    
    var friend = new person.acquaintance();

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

    /*eslint new-cap: ["error", { "properties": true }]*/
    
    var friend = new person.Acquaintance();

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

    /*eslint new-cap: ["error", { "properties": false }]*/
    
    var friend = new person.acquaintance();

    When Not To Use It

    If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/

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

            try {
    
                options = new preauthOptions.CreatePreauth().validate(options);
    
            } catch (err) {
    Severity: Major
    Found in lib/utils/preauth.js and 2 other locations - About 5 hrs to fix
    lib/api/communication.js on lines 234..270
    lib/api/request.js on lines 66..92

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

    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