discourse/discourse

View on GitHub

Showing 1,498 of 1,804 total issues

Class PostSerializer has 75 methods (exceeds 20 allowed). Consider refactoring.
Open

class PostSerializer < BasicPostSerializer

  # To pass in additional information we might need
  INSTANCE_VARS ||= [
    :topic_view,
Severity: Major
Found in app/serializers/post_serializer.rb - About 1 day to fix

    File application_controller.rb has 624 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'current_user'
    require_dependency 'canonical_url'
    require_dependency 'discourse'
    require_dependency 'custom_renderer'
    require_dependency 'archetype'
    Severity: Major
    Found in app/controllers/application_controller.rb - About 1 day to fix

      Method send_notification_email has a Cognitive Complexity of 69 (exceeds 5 allowed). Consider refactoring.
      Open

        def send_notification_email(opts)
          post = opts[:post]
          title = opts[:title]
      
          allow_reply_by_email = opts[:allow_reply_by_email]
      Severity: Minor
      Found in app/mailers/user_notifications.rb - About 1 day 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 posts_controller.rb has 618 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      require_dependency 'new_post_manager'
      require_dependency 'post_creator'
      require_dependency 'post_action_destroyer'
      require_dependency 'post_destroyer'
      require_dependency 'post_merger'
      Severity: Major
      Found in app/controllers/posts_controller.rb - About 1 day to fix

        Class Instance has 72 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class Plugin::Instance
        
          attr_accessor :path, :metadata
          attr_reader :admin_route
        
        
        Severity: Major
        Found in lib/plugin/instance.rb - About 1 day to fix

          Method post_process_oneboxes has a Cognitive Complexity of 67 (exceeds 5 allowed). Consider refactoring.
          Open

            def post_process_oneboxes
              limit = SiteSetting.max_oneboxes_per_post
              oneboxes = {}
              inlineOneboxes = {}
          
          
          Severity: Minor
          Found in lib/cooked_post_processor.rb - About 1 day 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

          Method destroy has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring.
          Open

            def destroy(user, opts = {})
              raise Discourse::InvalidParameters.new('user is nil') unless user && user.is_a?(User)
              raise PostsExistError if !opts[:delete_posts] && user.posts.count != 0
              @guardian.ensure_can_delete_user!(user)
          
          
          Severity: Minor
          Found in app/services/user_destroyer.rb - About 1 day 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 group.rb has 598 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          require_dependency 'enum'
          
          class Group < ActiveRecord::Base
            include HasCustomFields
            include AnonCacheInvalidator
          Severity: Major
          Found in app/models/group.rb - About 1 day to fix

            Class TopicView has 68 methods (exceeds 20 allowed). Consider refactoring.
            Open

            class TopicView
              MEGA_TOPIC_POSTS_COUNT = 10000
            
              attr_reader(
                :topic,
            Severity: Major
            Found in lib/topic_view.rb - About 1 day to fix

              File user_notifications.rb has 583 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              require_dependency 'markdown_linker'
              require_dependency 'email/message_builder'
              require_dependency 'age_words'
              require_dependency 'rtl'
              require_dependency 'discourse_ip_info'
              Severity: Major
              Found in app/mailers/user_notifications.rb - About 1 day to fix

                Method password_reset has a Cognitive Complexity of 63 (exceeds 5 allowed). Consider refactoring.
                Open

                  def password_reset
                    expires_now
                
                    token = params[:token]
                
                
                Severity: Minor
                Found in app/controllers/users_controller.rb - About 1 day 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 topic_view.rb has 579 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                require_dependency 'guardian'
                require_dependency 'topic_query'
                require_dependency 'filter_best_posts'
                require_dependency 'gaps'
                
                
                Severity: Major
                Found in lib/topic_view.rb - About 1 day to fix

                  File track_selector_spec.rb has 571 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  require 'rails_helper'
                  
                  describe DiscourseNarrativeBot::TrackSelector do
                    let(:user) { Fabricate(:user) }
                    let(:discobot_user) { User.find(-2) }

                    Method send has a Cognitive Complexity of 61 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def send
                          bypass_disable = BYPASS_DISABLE_TYPES.include?(@email_type.to_s)
                    
                          if SiteSetting.disable_emails == "yes" && !bypass_disable
                            return
                    Severity: Minor
                    Found in lib/email/sender.rb - About 1 day 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

                    Method show has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def show
                        if request.referer
                          flash["referer"] ||= request.referer[0..255]
                        end
                    
                    
                    Severity: Minor
                    Found in app/controllers/topics_controller.rb - About 1 day 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

                    Method build has 232 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        def build
                          return @wizard unless SiteSetting.wizard_enabled? && @wizard.user.try(:staff?)
                    
                          @wizard.append_step('locale') do |step|
                            step.banner = "welcome.png"
                    Severity: Major
                    Found in lib/wizard/builder.rb - About 1 day to fix

                      File staff_action_logger.rb has 552 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      require_dependency 'staff_message_format'
                      
                      # Responsible for logging the actions of admins and moderators.
                      class StaffActionLogger
                      
                      
                      Severity: Major
                      Found in app/services/staff_action_logger.rb - About 1 day to fix

                        File post_alerter.rb has 542 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        require_dependency 'distributed_mutex'
                        require_dependency 'user_action_manager'
                        
                        class PostAlerter
                          def self.post_created(post, opts = {})
                        Severity: Major
                        Found in app/services/post_alerter.rb - About 1 day to fix

                          Class Guardian has 62 methods (exceeds 20 allowed). Consider refactoring.
                          Open

                          class Guardian
                            include EnsureMagic
                            include CategoryGuardian
                            include PostGuardian
                            include TopicGuardian
                          Severity: Major
                          Found in lib/guardian.rb - About 1 day to fix

                            Class ApplicationController has 61 methods (exceeds 20 allowed). Consider refactoring.
                            Open

                            class ApplicationController < ActionController::Base
                              include CurrentUser
                              include CanonicalURL::ControllerExtensions
                              include JsonError
                              include GlobalPath
                            Severity: Major
                            Found in app/controllers/application_controller.rb - About 1 day to fix
                              Severity
                              Category
                              Status
                              Source
                              Language