silentrob/superscript

View on GitHub

Showing 92 of 92 total issues

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

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

                  const topic = await system.chatSystem.Topic.findById(topicData.id, '_id name filter gambits')
                    .populate({ path: 'gambits', populate: { path: 'replies' } })
                    .lean()
                    .exec();
              Severity: Major
              Found in src/bot/getReply/index.js and 1 other location - About 1 hr to fix
              src/bot/getReply/index.js on lines 136..139

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

              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

                  const reply = await system.chatSystem.Reply.findById(topicData.id, '_id name filter gambits')
                    .populate({ path: 'gambits', populate: { path: 'replies' } })
                    .lean()
                    .exec();
              Severity: Major
              Found in src/bot/getReply/index.js and 1 other location - About 1 hr to fix
              src/bot/getReply/index.js on lines 103..106

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

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

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

                  const mongoURI = process.env.MONGO_URI
                    || process.env.MONGODB_URI
                    || program.mongoURI
                    || `mongodb://${program.host}:${program.port}/${program.mongo}`;
                  Severity: Major
                  Found in src/bin/parse.js and 1 other location - About 1 hr to fix
                  src/bin/cleanup.js on lines 15..18

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

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

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

                    const mongoURI = process.env.MONGO_URI
                      || process.env.MONGODB_URI
                      || program.mongoURI
                      || `mongodb://${program.host}:${program.port}/${program.mongo}`;
                    Severity: Major
                    Found in src/bin/cleanup.js and 1 other location - About 1 hr to fix
                    src/bin/parse.js on lines 20..23

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

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

                    const botHandle = function botHandle(err, bot) {
                      const receiveData = function receiveData(socket, bot, data) {
                        // Handle incoming messages.
                        let message = `${data}`;
                    
                    
                    Severity: Minor
                    Found in clients/telnet.js - About 1 hr to fix

                      Function letterLookup has 38 lines of code (exceeds 25 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 1 hr to fix

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

                        const eachGambitHandle = async function eachGambitHandle(gambit, message, options) {
                          const plugins = options.system.plugins;
                          const scope = options.system.scope;
                          const topic = options.topic || 'reply';
                          const chatSystem = options.system.chatSystem;
                        Severity: Minor
                        Found in src/bot/getReply/helpers.js - About 1 hr to fix

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

                          const inlineRedirect = async function inlineRedirect(triggerTarget, options) {
                            debug.verbose(`Inline redirection to: '${triggerTarget}'`);
                          
                            // if we have a special topic, reset it to the previous one
                            // in order to preserve the context for inline redirection
                          Severity: Minor
                          Found in src/bot/reply/inlineRedirect.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

                          Severity
                          Category
                          Status
                          Source
                          Language