rubyforgood/casa

View on GitHub

Showing 45 of 100 total issues

File notifier.test.js has 743 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* eslint-env jest */
import { escape } from 'lodash'

require('jest')
const { Notifier, Notification } = require('../src/notifier.js')
Severity: Major
Found in app/javascript/__tests__/notifier.test.js - About 1 day to fix

    File dashboard.js has 433 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /* global alert */
    /* global $ */
    const { Notifier } = require('./notifier')
    let pageNotifier
    
    
    Severity: Minor
    Found in app/javascript/src/dashboard.js - About 6 hrs to fix

      File patch_notes.js has 352 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      const { Notifier } = require('../notifier')
      const TypeChecker = require('../type_checker')
      const patchNotePath = window.location.pathname
      const patchNoteFormBeforeEditData = {}
      const patchNoteFunctions = {} // A hack to be able to alphabetize functions
      Severity: Minor
      Found in app/javascript/src/all_casa_admin/patch_notes.js - About 4 hrs to fix

        File validated_form.test.js has 327 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        /* eslint-env jest */
        require('jest')
        
        const { Notifier } = require('../src/notifier.js')
        const { NonDrivingContactMediumWarning } = require('../src/validated_form.js')
        Severity: Minor
        Found in app/javascript/__tests__/validated_form.test.js - About 3 hrs to fix

          Class ApplicationPolicy has 26 methods (exceeds 20 allowed). Consider refactoring.
          Open

          class ApplicationPolicy
            class Scope
              attr_reader :user, :scope
          
              def initialize(user, scope)
          Severity: Minor
          Found in app/policies/application_policy.rb - About 3 hrs to fix

            Class CasaCaseDecorator has 24 methods (exceeds 20 allowed). Consider refactoring.
            Open

            class CasaCaseDecorator < Draper::Decorator
              include ActionView::Helpers::DateHelper
            
              delegate_all
            
            
            Severity: Minor
            Found in app/decorators/casa_case_decorator.rb - About 2 hrs to fix

              Class CaseContactDecorator has 22 methods (exceeds 20 allowed). Consider refactoring.
              Open

              class CaseContactDecorator < Draper::Decorator
                delegate_all
              
                NOTES_CHARACTER_LIMIT = 100
              
              
              Severity: Minor
              Found in app/decorators/case_contact_decorator.rb - About 2 hrs to fix

                Class CaseContact has 21 methods (exceeds 20 allowed). Consider refactoring.
                Open

                class CaseContact < ApplicationRecord
                  include ByOrganizationScope
                  acts_as_paranoid
                
                  attr_accessor :duration_hours
                Severity: Minor
                Found in app/models/case_contact.rb - About 2 hrs to fix

                  Method initialize has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def initialize(form:, hour_value:, minute_value:)
                      @form = form
                  
                      if hour_value.is_a?(String)
                        begin
                  Severity: Minor
                  Found in app/components/form/hour_minute_duration_component.rb - 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 createChart has 52 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function createChart (chartElement, dataset) {
                    const ctx = chartElement.getContext('2d')
                  
                    return new Chart(ctx, {
                      type: 'bubble',
                  Severity: Major
                  Found in app/javascript/src/display_app_metric.js - About 2 hrs to fix

                    Function addAndCreate has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      addAndCreate (e) {
                        this.add(e)
                        const items = this.element.querySelectorAll(this.wrapperSelectorValue)
                        const addedItem = items[items.length - 1]
                        // childIndex will be 0,1,... for items at page load, timestamps for items added to form.
                    Severity: Minor
                    Found in app/javascript/controllers/casa_nested_form_controller.js - About 1 hr to fix

                      Method save has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        def save
                          authorize CasaCase, :save_emancipation?
                          params.permit(:casa_case_id, :check_item_action)
                      
                          begin
                      Severity: Minor
                      Found in app/controllers/emancipations_controller.rb - About 1 hr to fix

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

                        patchNoteFunctions.onSavePatchNote = function () {
                          const patchNoteForm = $(this).parents('.card-body')
                          const patchNoteFormInputs = patchNoteFunctions.getPatchNoteFormInputs(patchNoteForm)
                        
                          if ($(this).parent().siblings('textarea').val() === '') {
                        Severity: Minor
                        Found in app/javascript/src/all_casa_admin/patch_notes.js - About 1 hr to fix

                          Method populate has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def self.populate
                              CaseContact.find_each do |case_contact|
                                # Get rid of drafts
                                unless case_contact.casa_case
                                  case_contact.destroy
                          Severity: Minor
                          Found in lib/tasks/data_post_processors/case_contact_populator.rb - 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 destroyAndRemove has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            destroyAndRemove (e) {
                              const wrapper = e.target.closest(this.wrapperSelectorValue)
                              const recordId = this.getRecordId(wrapper)
                              if (wrapper.dataset.newRecord === 'false' && (recordId.length > 0)) {
                                fetch(`${this.routeValue}/${recordId}`, {
                          Severity: Minor
                          Found in app/javascript/controllers/casa_nested_form_controller.js - About 1 hr to fix

                            Method initialize has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                              def initialize(form:, hour_value:, minute_value:)
                                @form = form
                            
                                if hour_value.is_a?(String)
                                  begin
                            Severity: Minor
                            Found in app/components/form/hour_minute_duration_component.rb - About 1 hr to fix

                              Function handleGenerateReport has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                              function handleGenerateReport (e) {
                                e.preventDefault()
                              
                                const formData = Object.fromEntries(new FormData(e.currentTarget.form))
                              
                              
                              Severity: Minor
                              Found in app/javascript/src/casa_case.js - About 1 hr to fix

                                Function createMultiSelectWithOptionGroups has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                  createMultiSelectWithOptionGroups () {
                                    const optionTemplate = this.optionTarget.innerHTML
                                    const itemTemplate = this.itemTarget.innerHTML
                                    const placeholder = `Select or search ${this.placeholderTermValue}`
                                
                                
                                Severity: Minor
                                Found in app/javascript/controllers/multiple_select_controller.js - About 1 hr to fix

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

                                          render: (data, type, row, meta) => {
                                            const noContactVolunteers = Number(row.no_attempt_for_two_weeks)
                                            const transitionAgedCaseVolunteers = Number(row.transitions_volunteers)
                                            const activeContactVolunteers = Number(row.volunteer_assignments) - noContactVolunteers
                                            const activeContactElement = activeContactVolunteers
                                  Severity: Minor
                                  Found in app/javascript/src/dashboard.js - About 1 hr to fix

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

                                      submitForm () {
                                        fetch(this.formTarget.action, {
                                          method: 'POST',
                                          headers: { Accept: 'application/json' },
                                          body: new FormData(this.formTarget)
                                    Severity: Minor
                                    Found in app/javascript/controllers/autosave_controller.js - About 1 hr to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language