discourse/discourse

View on GitHub

Showing 1,747 of 1,747 total issues

File report.rb has 1379 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require_dependency 'topic_subtype'

class Report
  # Change this line each time report format change
  # and you want to ensure cache is reset
Severity: Major
Found in app/models/report.rb - About 3 days to fix

    Class User has 159 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 topic.rb has 1152 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      require_dependency 'slug'
      require_dependency 'avatar_lookup'
      require_dependency 'topic_view'
      require_dependency 'rate_limiter'
      require_dependency 'text_sentinel'
      Severity: Major
      Found in app/models/topic.rb - About 2 days to fix

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

        require_dependency 'jobs/base'
        require_dependency 'email'
        require_dependency 'email_token'
        require_dependency 'email_validator'
        require_dependency 'trust_level'
        Severity: Major
        Found in app/models/user.rb - About 2 days to fix

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

          require_dependency 'discourse_hub'
          require_dependency 'user_name_suggester'
          require_dependency 'rate_limiter'
          require_dependency 'wizard'
          require_dependency 'wizard/builder'
          Severity: Major
          Found in app/controllers/users_controller.rb - About 2 days to fix

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

            require "digest"
            require_dependency "new_post_manager"
            require_dependency "post_action_creator"
            require_dependency "html_to_markdown"
            require_dependency "plain_text_to_markdown"
            Severity: Major
            Found in lib/email/receiver.rb - About 2 days to fix

              Class Topic has 105 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 topic_query.rb has 800 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                require_dependency 'topic_list'
                require_dependency 'suggested_topics_builder'
                require_dependency 'topic_query_sql'
                require_dependency 'avatar_lookup'
                
                
                Severity: Major
                Found in lib/topic_query.rb - About 1 day to fix

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

                  require_dependency 'topic_view'
                  require_dependency 'promotion'
                  require_dependency 'url_helper'
                  require_dependency 'topics_bulk_action'
                  require_dependency 'discourse_event'
                  Severity: Major
                  Found in app/controllers/topics_controller.rb - About 1 day to fix

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

                    require_dependency 'search/grouped_search_results'
                    
                    class Search
                      INDEX_VERSION = 2.freeze
                      DIACRITICS ||= /([\u0300-\u036f]|[\u1AB0-\u1AFF]|[\u1DC0-\u1DFF]|[\u20D0-\u20FF])/
                    Severity: Major
                    Found in lib/search.rb - About 1 day to fix

                      File new_user_narrative_spec.rb has 734 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) { User.find(-2) }

                        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 default_results has a Cognitive Complexity of 83 (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 routes.rb has 706 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        require "sidekiq/web"
                        require "mini_scheduler/web"
                        require_dependency "admin_constraint"
                        require_dependency "staff_constraint"
                        require_dependency "homepage_constraint"
                        Severity: Major
                        Found in config/routes.rb - About 1 day to fix

                          Method create_for has a Cognitive Complexity of 81 (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 post.rb has 682 lines of code (exceeds 250 allowed). Consider refactoring.
                          Open

                          require_dependency 'pretty_text'
                          require_dependency 'rate_limiter'
                          require_dependency 'post_revisor'
                          require_dependency 'enum'
                          require_dependency 'post_analyzer'
                          Severity: Major
                          Found in app/models/post.rb - About 1 day to fix

                            Method build has a Cognitive Complexity of 75 (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

                            Method destroy has a Cognitive Complexity of 72 (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

                            Method posts_query has a Cognitive Complexity of 72 (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)
                                  .joins("LEFT JOIN categories ON categories.id = topics.category_id")
                            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

                            Class UserSerializer has 76 methods (exceeds 20 allowed). Consider refactoring.
                            Open

                            class UserSerializer < BasicUserSerializer
                            
                              attr_accessor :omit_stats,
                                            :topic_post_count
                            
                            
                            Severity: Major
                            Found in app/serializers/user_serializer.rb - About 1 day to fix
                              Severity
                              Category
                              Status
                              Source
                              Language