HansHammel/watchmen

View on GitHub

Showing 1,086 of 1,086 total issues

Function 'getUptime' has a complexity of 7.
Open

function getUptime (service, outages, currentOutage, since) {
Severity: Minor
Found in lib/reporter.js by eslint

Limit Cyclomatic Complexity (complexity)

Cyclomatic complexity measures the number of linearly independent paths through a program's source code. This rule allows setting a cyclomatic complexity threshold.

function a(x) {
    if (true) {
        return x; // 1st path
    } else if (false) {
        return x+1; // 2nd path
    } else {
        return 4; // 3rd path
    }
}

Rule Details

This rule is aimed at reducing code complexity by capping the amount of cyclomatic complexity allowed in a program. As such, it will warn when the cyclomatic complexity crosses the configured threshold (default is 20).

Examples of incorrect code for a maximum of 2:

/*eslint complexity: ["error", 2]*/

function a(x) {
    if (true) {
        return x;
    } else if (false) {
        return x+1;
    } else {
        return 4; // 3rd path
    }
}

Examples of correct code for a maximum of 2:

/*eslint complexity: ["error", 2]*/

function a(x) {
    if (true) {
        return x;
    } else {
        return 4;
    }
}

Options

Optionally, you may specify a max object property:

"complexity": ["error", 2]

is equivalent to

"complexity": ["error", { "max": 2 }]

Deprecated: the object property maximum is deprecated. Please use the property max instead.

When Not To Use It

If you can't determine an appropriate complexity limit for your code, then it's best to disable this rule.

Further Reading

Related Rules

  • [max-depth](max-depth.md)
  • [max-len](max-len.md)
  • [max-nested-callbacks](max-nested-callbacks.md)
  • [max-params](max-params.md)
  • [max-statements](max-statements.md) Source: http://eslint.org/docs/rules/

Function getRoutes has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports.getRoutes = function (storage){

  if (!storage) {
    throw new Error('storage needed');
  }
Severity: Minor
Found in webserver/routes/api-report-route.js - About 1 hr to fix

    Function exports has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    exports = module.exports = (function () {
    
      function isServiceRestrictedToEmail(service, email) {
        if (!service) {
          return false;
    Severity: Minor
    Found in lib/service-access-filter.js - About 1 hr to fix

      Function render has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        Charting.render = function (options) {
      
          var latencyData = parseArrayObjectsForCharting(options.latency, 't', 'l');
      
          var latencySerie = latencyData.data;
      Severity: Minor
      Found in webserver/public/js/charting/charting.js - About 1 hr to fix

        Function getLatencySince has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        StorageRedis.prototype.getLatencySince = function (service, timestamp, aggregatedBy, callback) {
          this.redis.zrevrangebyscore(service.id + ':' + LATENCY_KEY_SUFIX, '+inf', timestamp || '-inf', 'withscores', function (err, data) {
            if (err) {
              return callback(err);
            }
        Severity: Minor
        Found in lib/storage/providers/redis.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 exports has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        exports = module.exports = (function(){
        
          function validateOptionalInt(service, errors, field, options) {
            if (service[field]){
              validateInt(service, errors, field, options);
        Severity: Minor
        Found in lib/service-validator.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 getGeneralServiceInfo has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function getGeneralServiceInfo(service, storage, callback) {
        
          storage.getCurrentOutage(service, function(err, currentOutage){
            if (err) {
              return callback(err);
        Severity: Minor
        Found in lib/reporter.js - About 1 hr to fix

          Function configureApp has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              configureApp : function (app){
          
                passport.use(new GoogleStrategy({
                    clientID: config.auth.GOOGLE_CLIENT_ID,
                    clientSecret: config.auth.GOOGLE_CLIENT_SECRET,
          Severity: Minor
          Found in webserver/routes/web-auth-route.js - About 1 hr to fix

            Function getUptime has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function getUptime (service, outages, currentOutage, since) {
            
              var totalDownTime = 0;
              var now = +new Date();
              
            Severity: Minor
            Found in lib/reporter.js - About 1 hr to fix

              Function exports has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              exports = module.exports = function(storage){
                if (!storage) {
                  throw new Error('storage is required');
                }
              
              
              Severity: Minor
              Found in webserver/app.js - About 1 hr to fix

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

                function parseLatencyDataFromZset(zset) {
                  var list = [];
                  var currentObj;
                  var accLatency = 0;
                  for (var i = 0; i < zset.length; i++) {
                Severity: Minor
                Found in lib/storage/providers/redis.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 getRoutes has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                exports = module.exports.getRoutes = function (){
                
                  var PREFIX_PING_PLUGIN = 'watchmen-ping-';
                
                  var router = express.Router();
                Severity: Minor
                Found in webserver/routes/api-ping-plugins-route.js - About 1 hr to fix

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

                  run(program, function (err) {
                    if (err) {
                      console.error(err);
                    }
                    else {
                  Severity: Major
                  Found in scripts/show-services.js and 1 other location - About 1 hr to fix
                  scripts/report-service.js on lines 50..58

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

                  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

                  run(program, function (err) {
                    if (err) {
                      console.error(err);
                    }
                    else {
                  Severity: Major
                  Found in scripts/report-service.js and 1 other location - About 1 hr to fix
                  scripts/show-services.js on lines 23..31

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

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

                      function enableUI() {
                          var i,
                              el,
                              ithSorter = function ithSorter(i) {
                                  var col = cols[i];
                  Severity: Minor
                  Found in coverage/lcov-report/sorter.js - About 1 hr to fix

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

                    exports = module.exports = (function(){
                    
                      var DEFAULT_TARGET_UPTIME = 0.99;
                      var DEFAULT_TARGET_WARNING_PERCENTAGE = 0.02;
                    
                    
                    Severity: Minor
                    Found in scripts/data-load/lib/response-randomizer.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 getUptime has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                    function getUptime (service, outages, currentOutage, since) {
                    
                      var totalDownTime = 0;
                      var now = +new Date();
                      
                    Severity: Minor
                    Found in lib/reporter.js - About 45 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

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

                    StorageRedis.prototype.resetOutageFailureCount = function (service, cb) {
                      this.redis.del(service.id + ':' + FAILURE_COUNT_SUFIX, cb);
                    };
                    Severity: Minor
                    Found in lib/storage/providers/redis.js and 1 other location - About 40 mins to fix
                    lib/storage/providers/redis.js on lines 259..261

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

                    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

                    StorageRedis.prototype.increaseOutageFailureCount = function (service, cb) {
                      this.redis.incr(service.id + ':' + FAILURE_COUNT_SUFIX, cb);
                    };
                    Severity: Minor
                    Found in lib/storage/providers/redis.js and 1 other location - About 40 mins to fix
                    lib/storage/providers/redis.js on lines 255..257

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

                    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 getRoutes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                    module.exports.getRoutes = function (storage) {
                    
                      if (!storage) {
                        throw new Error('storage needed');
                      }
                    Severity: Minor
                    Found in webserver/routes/api-service-route.js - About 25 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

                    Severity
                    Category
                    Status
                    Source
                    Language