discourse/discourse

View on GitHub

Showing 1,692 of 2,021 total issues

Class User has 168 methods (exceeds 20 allowed). Consider refactoring.
Open

class User < ActiveRecord::Base
  include Searchable
  include Roleable
  include HasCustomFields
  include SecondFactorManager
Severity: Major
Found in app/models/user.rb - About 3 days to fix

    File users_controller.rb has 1224 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class UsersController < ApplicationController
    
      skip_before_action :authorize_mini_profiler, only: [:avatar]
    
      requires_login only: [
    Severity: Major
    Found in app/controllers/users_controller.rb - About 3 days to fix

      File user.rb has 1200 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      class User < ActiveRecord::Base
        include Searchable
        include Roleable
        include HasCustomFields
        include SecondFactorManager
      Severity: Major
      Found in app/models/user.rb - About 3 days to fix

        File topic.rb has 1180 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        class Topic < ActiveRecord::Base
          class UserExists < StandardError; end
          include ActionView::Helpers::SanitizeHelper
          include RateLimiter::OnCreateRecord
          include HasCustomFields
        Severity: Major
        Found in app/models/topic.rb - About 3 days to fix

          File receiver.rb has 990 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          require "digest"
          
          module Email
          
            class Receiver
          Severity: Major
          Found in lib/email/receiver.rb - About 2 days to fix

            File search.rb has 866 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            class Search
              DIACRITICS ||= /([\u0300-\u036f]|[\u1AB0-\u1AFF]|[\u1DC0-\u1DFF]|[\u20D0-\u20FF])/
            
              cattr_accessor :preloaded_topic_custom_fields
              self.preloaded_topic_custom_fields = Set.new
            Severity: Major
            Found in lib/search.rb - About 2 days to fix

              File topic_query.rb has 856 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              class TopicQuery
                PG_MAX_INT ||= 2147483647
              
                def self.validators
                  @validators ||= begin
              Severity: Major
              Found in lib/topic_query.rb - About 2 days to fix

                File topics_controller.rb has 839 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                class TopicsController < ApplicationController
                  requires_login only: [
                    :timings,
                    :destroy_timings,
                    :update,
                Severity: Major
                Found in app/controllers/topics_controller.rb - About 2 days to fix

                  Class Topic has 104 methods (exceeds 20 allowed). Consider refactoring.
                  Open

                  class Topic < ActiveRecord::Base
                    class UserExists < StandardError; end
                    include ActionView::Helpers::SanitizeHelper
                    include RateLimiter::OnCreateRecord
                    include HasCustomFields
                  Severity: Major
                  Found in app/models/topic.rb - About 2 days to fix

                    File post.rb has 832 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    require 'archetype'
                    require 'digest/sha1'
                    
                    class Post < ActiveRecord::Base
                      include RateLimiter::OnCreateRecord
                    Severity: Major
                    Found in app/models/post.rb - About 2 days to fix

                      Method create_for has a Cognitive Complexity of 91 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def create_for(user_id)
                          if filesize <= 0
                            @upload.errors.add(:base, I18n.t("upload.empty"))
                            return @upload
                          end
                      Severity: Minor
                      Found in lib/upload_creator.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 routes.rb has 755 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      require "sidekiq/web"
                      require "mini_scheduler/web"
                      
                      # The following constants have been replaced with `RouteFormat` and are deprecated.
                      USERNAME_ROUTE_FORMAT = /[%\w.\-]+?/ unless defined? USERNAME_ROUTE_FORMAT
                      Severity: Major
                      Found in config/routes.rb - About 1 day to fix

                        Method build has a Cognitive Complexity of 87 (exceeds 5 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: Minor
                        Found in lib/wizard/builder.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 new_user_narrative_spec.rb has 737 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        require 'rails_helper'
                        
                        describe DiscourseNarrativeBot::NewUserNarrative do
                          let!(:welcome_topic) { Fabricate(:topic, title: 'Welcome to Discourse') }
                          let(:discobot_user) { ::DiscourseNarrativeBot::Base.new.discobot_user }

                          Method to_html has a Cognitive Complexity of 85 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def to_html
                              do_quotes = do_backticks = do_dashes = do_ellipses = nil
                          
                              if @options.include?(0)
                                # Do nothing.
                          Severity: Minor
                          Found in lib/html_prettify.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 posts_query has a Cognitive Complexity of 82 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def posts_query(limit, opts = nil)
                              opts ||= {}
                          
                              posts = Post.where(post_type: Topic.visible_post_types(@guardian.user))
                                .joins(:post_search_data, :topic)
                          Severity: Minor
                          Found in lib/search.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 default_results has a Cognitive Complexity of 82 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def default_results(options = {})
                              options.reverse_merge!(@options)
                              options.reverse_merge!(per_page: per_page_setting)
                          
                              # Whether to return visible topics
                          Severity: Minor
                          Found in lib/topic_query.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 692 lines of code (exceeds 250 allowed). Consider refactoring.
                          Open

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

                            Class Receiver has 82 methods (exceeds 20 allowed). Consider refactoring.
                            Open

                              class Receiver
                                # If you add a new error, you need to
                                #   * add it to Email::Processor#handle_failure()
                                #   * add text to server.en.yml (parent key: "emails.incoming.errors")
                                class ProcessingError              < StandardError; end
                            Severity: Major
                            Found in lib/email/receiver.rb - About 1 day to fix

                              Class Post has 81 methods (exceeds 20 allowed). Consider refactoring.
                              Open

                              class Post < ActiveRecord::Base
                                include RateLimiter::OnCreateRecord
                                include Trashable
                                include Searchable
                                include HasCustomFields
                              Severity: Major
                              Found in app/models/post.rb - About 1 day to fix
                                Severity
                                Category
                                Status
                                Source
                                Language