fossasia/susi_kikbot

View on GitHub

Showing 4 of 4 total issues

Function askSusi has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
Open

const askSusi=function (query,cb) {
  request('https://api.susi.ai/susi/chat.json?q='+encodeURI(query), function (error, response, body) {
    var data = JSON.parse(body);
    if (!error && response.statusCode == 200) {
        message = '';
Severity: Minor
Found in susi.js - About 6 hrs 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 askSusi has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const askSusi=function (query,cb) {
  request('https://api.susi.ai/susi/chat.json?q='+encodeURI(query), function (error, response, body) {
    var data = JSON.parse(body);
    if (!error && response.statusCode == 200) {
        message = '';
Severity: Minor
Found in susi.js - About 1 hr to fix

    Avoid deeply nested control flow statements.
    Open

                    if((data.answers[0].metadata.count)>20)
                        message += 'Due to message limit, only some results are shown-:\n\n';
                    else
                        message += 'Results are shown below-:\n\n';
    Severity: Major
    Found in susi.js - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                      for(var i=0;i<(((data.answers[0].metadata.count)>20)?20:data.answers[0].metadata.count);i++){
                          for(var cN in colNames){
                              message += (colNames[cN]+' : ');
                              message += data.answers[0].data[i][cN]+', ';
                          }
      Severity: Major
      Found in susi.js - About 45 mins to fix
        Severity
        Category
        Status
        Source
        Language