silentrob/superscript

View on GitHub

Showing 67 of 92 total issues

Function sortTriggerSet has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
Open

const sortTriggerSet = function sortTriggerSet(gambits) {
  let gambit;
  let cnt;
  let inherits;

Severity: Minor
Found in src/bot/db/sort.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 importData has 149 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const importData = function importData(chatSystem, data, callback) {
  if (!data.version || data.version < MIN_SUPPORTED_SCRIPT_VERSION) {
    return callback(`Error: Your script has version ${data.version} but the minimum supported version is ${MIN_SUPPORTED_SCRIPT_VERSION}.\nPlease either re-parse your file with a supported parser version, or update SuperScript.`);
  }

Severity: Major
Found in src/bot/db/import.js - About 5 hrs to fix

    Function createUserModel has 127 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const createUserModel = function createUserModel(db, factSystem, logger) {
      const userSchema = mongoose.Schema({
        id: String,
        currentTopic: { type: String, default: 'random' },
        pendingTopic: String,
    Severity: Major
    Found in src/bot/db/models/user.js - About 5 hrs to fix

      File processTags.js has 348 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      // TODO: Fix this documentation, options is incorrect
      /**
       * Parse the reply for additional tags, this is called once we have a reply candidate filtered out.
       *
       * @param {Object} replyObj - The Reply Object
      Severity: Minor
      Found in src/bot/processTags.js - About 4 hrs to fix

        Function letterLookup has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
        Open

        const letterLookup = function letterLookup(cb) {
          let reply = '';
        
          const lastWord = this.message.lemWords.slice(-1)[0];
          debug('--LastWord', lastWord);
        Severity: Minor
        Found in src/plugins/alpha.js - About 3 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 sortTriggerSet has 84 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const sortTriggerSet = function sortTriggerSet(gambits) {
          let gambit;
          let cnt;
          let inherits;
        
        
        Severity: Major
        Found in src/bot/db/sort.js - About 3 hrs to fix

          Function createTopicModel has 73 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          const createTopicModel = function createTopicModel(db) {
            const topicSchema = new mongoose.Schema({
              name: { type: String, index: true, unique: true },
          
              system: { type: Boolean, default: false },
          Severity: Major
          Found in src/bot/db/models/topic.js - About 2 hrs to fix

            Function afterHandle has 62 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            const afterHandle = function afterHandle(matches) {
              debug.verbose(`Set of matches: ${matches}`);
            
              const debugAll = [];
              let props = {};
            Severity: Major
            Found in src/bot/getReply/index.js - About 2 hrs to fix

              Function createGambitModel has 59 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              const createGambitModel = function createGambitModel(db, factSystem) {
                const gambitSchema = new mongoose.Schema({
                  id: { type: String, index: true, default: Utils.genId() },
              
                  // This is the input string that generates a rule,
              Severity: Major
              Found in src/bot/db/models/gambit.js - About 2 hrs to fix

                Function topicItorHandle has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                Open

                const topicItorHandle = async function topicItorHandle(topicData, messageObject, options) {
                  const system = options.system;
                
                  if (topicData.type === 'TOPIC') {
                    const topic = await system.chatSystem.Topic.findById(topicData.id, '_id name filter gambits')
                Severity: Minor
                Found in src/bot/getReply/index.js - About 2 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 _reply has 52 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  _reply(messageString, options, callback) {
                    const system = {
                      // Pass in the topic if it has been set
                      topicName: options.topicName || null,
                      plugins: this.plugins,
                Severity: Major
                Found in src/bot/index.js - About 2 hrs to fix

                  Function matchItorHandle has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  const matchItorHandle = async function matchItorHandle(match, message, options) {
                    const system = options.system;
                    options.message = message;
                  
                    debug.verbose('Match itor: ', match.gambit);
                  Severity: Minor
                  Found in src/bot/getReply/index.js - About 2 hrs to fix

                    Function processTag has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    const processTag = async function processTag(tag, replyObj, options) {
                      if (typeof tag === 'string') {
                        return tag;
                      }
                    
                    
                    Severity: Minor
                    Found in src/bot/processTags.js - About 1 hr to fix

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

                      export const findPendingTopicsForUser = async function findPendingTopicsForUser(user, message, chatSystem, conversationTimeout) {
                        const allTopics = await chatSystem.Topic.find({}).lean().exec();
                      
                        const tfidf = new TfIdf();
                      
                      
                      Severity: Minor
                      Found in src/bot/getReply/getPendingTopics.js - About 1 hr to fix

                        Function findPendingTopicsForUser has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                        Open

                        export const findPendingTopicsForUser = async function findPendingTopicsForUser(user, message, chatSystem, conversationTimeout) {
                          const allTopics = await chatSystem.Topic.find({}).lean().exec();
                        
                          const tfidf = new TfIdf();
                        
                        
                        Severity: Minor
                        Found in src/bot/getReply/getPendingTopics.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 findMatches has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                        Open

                        const findMatches = async function findMatches(pendingTopics, messageObject, options) {
                          debug.verbose(`Found pending topics/conversations: ${JSON.stringify(pendingTopics)}`);
                        
                          const replies = [];
                          let stopSearching = false;
                        Severity: Minor
                        Found in src/bot/getReply/index.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 updateHistory has 47 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          userSchema.methods.updateHistory = function (message, reply, cb) {
                            if (!_.isNull(message)) {
                              this.lastMessageSentAt = Date.now();
                            }
                        
                        
                        Severity: Minor
                        Found in src/bot/db/models/user.js - About 1 hr to fix

                          Function topicItorHandle has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          const topicItorHandle = async function topicItorHandle(topicData, messageObject, options) {
                            const system = options.system;
                          
                            if (topicData.type === 'TOPIC') {
                              const topic = await system.chatSystem.Topic.findById(topicData.id, '_id name filter gambits')
                          Severity: Minor
                          Found in src/bot/getReply/index.js - About 1 hr to fix

                            Function customFunction has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            const customFunction = async function customFunction(functionName, functionArgs, replyObj, options) {
                              const plugins = options.system.plugins;
                              // Important to create a new scope object otherwise we could leak data
                              const scope = _.merge({}, options.system.scope);
                              scope.extraScope = options.system.extraScope;
                            Severity: Minor
                            Found in src/bot/reply/customFunction.js - About 1 hr to fix

                              Function receiveData has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                              const receiveData = function receiveData(slack, bot, data) {
                                // Fetch the user who sent the message;
                                const user = data._client.users[data.user];
                                let channel;
                                const messageData = data.toJSON();
                              Severity: Minor
                              Found in clients/slack.js - About 1 hr to fix
                                Severity
                                Category
                                Status
                                Source
                                Language