silentrob/superscript

View on GitHub

Showing 92 of 92 total issues

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

const walkGambitParent = async function walkGambitParent(gambitId, chatSystem) {
  const gambitIds = [];
  try {
    const gambit = await chatSystem.Gambit.findById(gambitId, '_id parent')
      .populate('parent')
Severity: Major
Found in src/bot/getReply/helpers.js and 1 other location - About 7 hrs to fix
src/bot/getReply/helpers.js on lines 212..232

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

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 walkReplyParent = async function walkReplyParent(replyId, chatSystem) {
  const replyIds = [];
  try {
    const reply = await chatSystem.Reply.findById(replyId, '_id parent')
      .populate('parent')
Severity: Major
Found in src/bot/getReply/helpers.js and 1 other location - About 7 hrs to fix
src/bot/getReply/helpers.js on lines 190..210

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

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

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

  gambitSchema.methods.addReply = function (replyData, callback) {
    if (!replyData) {
      return callback('No data');
    }

Severity: Major
Found in src/bot/db/models/gambit.js and 1 other location - About 6 hrs to fix
src/bot/db/models/topic.js on lines 35..51

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

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

  topicSchema.methods.createGambit = function (gambitData, callback) {
    if (!gambitData) {
      return callback('No data');
    }

Severity: Major
Found in src/bot/db/models/topic.js and 1 other location - About 6 hrs to fix
src/bot/db/models/gambit.js on lines 79..95

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

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

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

      memory.db.get({ subject: key, predicate: userId }, (err, results) => {
        if (!_.isEmpty(results)) {
          memory.db.del(results[0], () => {
            memory.db.put({ subject: key, predicate: userId, object: value }, () => {
              cb(null, '');
    Severity: Major
    Found in src/plugins/user.js and 1 other location - About 5 hrs to fix
    src/plugins/user.js on lines 87..99

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

    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

      memory.db.get({ subject, predicate, object }, (err, results) => {
        if (!_.isEmpty(results)) {
          memory.db.del(results[0], () => {
            memory.db.put({ subject, predicate, object }, () => {
              cb(null, '');
    Severity: Major
    Found in src/plugins/user.js and 1 other location - About 5 hrs to fix
    src/plugins/user.js on lines 18..30

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

    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

    exports.getTimeOfDay = function getTimeOfDay(cb) {
      const date = new Date();
      const rounded = new Date(Math.round(date.getTime() / COEFF) * COEFF);
      const time = moment(rounded).format('H');
      let tod;
    Severity: Major
    Found in src/plugins/time.js and 1 other location - About 5 hrs to fix
    src/plugins/time.js on lines 46..60

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

    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

    exports.getGreetingTimeOfDay = function getGreetingTimeOfDay(cb) {
      const date = new Date();
      const rounded = new Date(Math.round(date.getTime() / COEFF) * COEFF);
      const time = moment(rounded).format('H');
      let tod;
    Severity: Major
    Found in src/plugins/time.js and 1 other location - About 5 hrs to fix
    src/plugins/time.js on lines 62..76

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

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

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

              } else if (gambit.input.indexOf('[') > -1) {
                // Optionals included.
                cnt = Utils.wordCount(gambit.input);
                debug(`Has optionals with ${cnt} words.`);
                if (!track[inherits].option[cnt]) {
        Severity: Major
        Found in src/bot/db/sort.js and 1 other location - About 3 hrs to fix
        src/bot/db/sort.js on lines 90..98

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

        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

              } else {
                // Totally atomic.
                cnt = Utils.wordCount(gambit.input);
                debug(`Totally atomic trigger and ${cnt} words.`);
                if (!track[inherits].atomic[cnt]) {
        Severity: Major
        Found in src/bot/db/sort.js and 1 other location - About 3 hrs to fix
        src/bot/db/sort.js on lines 82..90

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

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

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

                      db.model(modelNames.gambit).byTenant(this.getTenantId()).remove({ _id: gambitId }, (err) => {
                        if (err) {
                          debug.error(err);
                        }
            
            
            Severity: Major
            Found in src/bot/db/models/topic.js and 1 other location - About 2 hrs to fix
            src/bot/db/models/gambit.js on lines 102..110

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

            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

                  db.model(modelNames.reply).byTenant(this.getTenantId()).remove({ _id: replyId }, (err) => {
                    if (err) {
                      console.log(err);
                    }
            
            
            Severity: Major
            Found in src/bot/db/models/gambit.js and 1 other location - About 2 hrs to fix
            src/bot/db/models/topic.js on lines 83..91

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

            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 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
              Severity
              Category
              Status
              Source
              Language