michaelowens/AutoModerator

View on GitHub
src/condition.js

Summary

Maintainability
D
2 days
Test Coverage

Function matchesAgainstMessage has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

  matchesAgainstMessage(message: DiscordJS.Message) {
    // Check against user conditions first
    if ('user' in this.data) {
      if (!this.matchesAgainstUserConditions(message)) {
        console.log('user does not match')
Severity: Minor
Found in src/condition.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

File condition.js has 294 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* @flow */

import DiscordJS from 'discord.js'
import Discord from './bot/discord'
import Config from './config'
Severity: Minor
Found in src/condition.js - About 3 hrs to fix

    Function matchesAgainstUserConditions has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      matchesAgainstUserConditions(message: DiscordJS.Message) {
        if (!('user' in this.data)) {
          return true
        }
    
    
    Severity: Minor
    Found in src/condition.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 matchesAgainstMessage has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      matchesAgainstMessage(message: DiscordJS.Message) {
        // Check against user conditions first
        if ('user' in this.data) {
          if (!this.matchesAgainstUserConditions(message)) {
            console.log('user does not match')
    Severity: Minor
    Found in src/condition.js - About 1 hr to fix

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

        constructor(server: DiscordJS.Guild, values: ConditionValues) {
          this.data = values
          this.server = server
          this.modifiers = values.modifiers || []
          this.matchSuccess = true
      Severity: Minor
      Found in src/condition.js - About 1 hr to fix

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

          constructor(server: DiscordJS.Guild, values: ConditionValues) {
            this.data = values
            this.server = server
            this.modifiers = values.modifiers || []
            this.matchSuccess = true
        Severity: Minor
        Found in src/condition.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 matchesAgainstUserConditions has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          matchesAgainstUserConditions(message: DiscordJS.Message) {
            if (!('user' in this.data)) {
              return true
            }
        
        
        Severity: Minor
        Found in src/condition.js - About 1 hr to fix

          Function isValid has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            isValid() {
              try {
                this.validateKeys()
          
                // this.validateType(this.data, 'message', 'array') // could be string or array?
          Severity: Minor
          Found in src/condition.js - About 1 hr to fix

            Function validateType has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              validateType(obj: Object, key: string, expectedType: string) {
                if (!(key in obj)) {
                  return
                }
            
            
            Severity: Minor
            Found in src/condition.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

            Avoid too many return statements within this function.
            Open

                  return match === this.matchSuccess
            Severity: Major
            Found in src/condition.js - About 30 mins to fix

              There are no issues that match your filters.

              Category
              Status