bra1n/judgebot

View on GitHub
modules/store.ts

Summary

Maintainability
F
3 days
Test Coverage

File store.ts has 561 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Fuse from "fuse.js";

const log = utils.getLogger("locator");
import fetch from "node-fetch";
import * as utils from "../utils.js";
Severity: Major
Found in modules/store.ts - About 1 day to fix

Function locateStores has 81 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  async locateStores(location: any): Promise<InteractionReplyOptions> {
    const count = 10; // number of "stores" to retrieve (error margin included for non-store results)
    let googleBody: any;
    try {
      const res = await fetch(
Severity: Major
Found in modules/store.ts - About 3 hrs to fix

Function generateEventsEmbed has 69 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  generateEventsEmbed(
    { Address, Organization }: any,
    response: any,
    filters: any
  ): EmbedBuilder {
Severity: Major
Found in modules/store.ts - About 2 hrs to fix

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

  async fetchStores(longitude = -180, distance = 10) {
    try {
      if (longitude > 180 - distance) {
        // fetchStores(longitude = 0, distance = 10) { // easier testing
        //     if (longitude > 20 - distance) {
Severity: Major
Found in modules/store.ts - About 2 hrs to fix

Function getEvents has 53 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  async getEvents(query: string): Promise<EmbedBuilder> {
    // check if there are filters present
    const filters: any = {};
    let parameters = query.toLowerCase().split(" ");
    if (parameters.length == 0) {
Severity: Major
Found in modules/store.ts - About 2 hrs to fix

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

  async generateStoreEmbed(
    stores: any,
    googleResult: any
  ): Promise<InteractionReplyOptions> {
    const fields: any = [];
Severity: Minor
Found in modules/store.ts - About 1 hr to fix

Function getEvents has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  async getEvents(query: string): Promise<EmbedBuilder> {
    // check if there are filters present
    const filters: any = {};
    let parameters = query.toLowerCase().split(" ");
    if (parameters.length == 0) {
Severity: Minor
Found in modules/store.ts - 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 locateStores has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  async locateStores(location: any): Promise<InteractionReplyOptions> {
    const count = 10; // number of "stores" to retrieve (error margin included for non-store results)
    let googleBody: any;
    try {
      const res = await fetch(
Severity: Minor
Found in modules/store.ts - 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 generateStoreRequestBody has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  generateStoreRequestBody(geometry: any, count = 10) {
    let requestBody = {
      count,
      filter_mass_markets: true,
      language: "en-us",
Severity: Minor
Found in modules/store.ts - About 1 hr to fix

Function generateEventsEmbed has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  generateEventsEmbed(
    { Address, Organization }: any,
    response: any,
    filters: any
  ): EmbedBuilder {
Severity: Minor
Found in modules/store.ts - About 35 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 {
        embeds: [
          await this.generateErrorEmbed(
            null,
            `Location \`${location}\` not found.`
Severity: Major
Found in modules/store.ts - About 30 mins to fix

There are no issues that match your filters.

Category
Status