discourse/discourse

View on GitHub

Showing 1,539 of 1,848 total issues

File reviewable.rb has 429 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require_dependency 'enum'
require_dependency 'reviewable/actions'
require_dependency 'reviewable/conversation'
require_dependency 'reviewable/editable_fields'
require_dependency 'reviewable/perform_result'
Severity: Minor
Found in app/models/reviewable.rb - About 6 hrs to fix

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

      def self.create_for(upload, width, height, opts = {})
        return unless width > 0 && height > 0
        return if upload.try(:sha1).blank?
    
        # no extension so try to guess it
    Severity: Minor
    Found in app/models/optimized_image.rb - About 6 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

    Method filter_allowed_tags has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.filter_allowed_tags(query, guardian, opts = {})
        selected_tag_ids = opts[:selected_tags] ? Tag.where_name(opts[:selected_tags]).pluck(:id) : []
    
        if !opts[:for_topic] && !selected_tag_ids.empty?
          query = query.where('tags.id NOT IN (?)', selected_tag_ids)
    Severity: Minor
    Found in lib/discourse_tagging.rb - About 6 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

    Method start_element has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
    Open

      def start_element(name, attributes = [])
        case name
        when "img"
          attributes = Hash[*attributes.flatten]
    
    
    Severity: Minor
    Found in lib/excerpt_parser.rb - About 6 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

    File site_setting_extension.rb has 419 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require_dependency 'site_settings/deprecated_settings'
    require_dependency 'site_settings/type_supervisor'
    require_dependency 'site_settings/defaults_provider'
    require_dependency 'site_settings/db_provider'
    
    
    Severity: Minor
    Found in lib/site_setting_extension.rb - About 6 hrs to fix

      File theme_field.rb has 415 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      require_dependency 'theme_settings_parser'
      require_dependency 'theme_translation_parser'
      require_dependency 'theme_javascript_compiler'
      
      class ThemeField < ActiveRecord::Base
      Severity: Minor
      Found in app/models/theme_field.rb - About 5 hrs to fix

        Method recover has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
        Open

          def recover(posts = Post)
            posts.have_uploads.find_each do |post|
        
              begin
                analyzer = PostAnalyzer.new(post.raw, post.topic_id)
        Severity: Minor
        Found in lib/upload_recovery.rb - About 5 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

        File post_creator.rb has 412 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        require_dependency 'rate_limiter'
        require_dependency 'topic_creator'
        require_dependency 'post_jobs_enqueuer'
        require_dependency 'distributed_mutex'
        require_dependency 'has_errors'
        Severity: Minor
        Found in lib/post_creator.rb - About 5 hrs to fix

          File new_user_narrative.rb has 408 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          require 'distributed_mutex'
          
          module DiscourseNarrativeBot
            class NewUserNarrative < Base
              I18N_KEY = "discourse_narrative_bot.new_user_narrative".freeze

            Method download has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.download(url,
                                max_file_size:,
                                tmp_file_name:,
                                follow_redirect: false,
                                read_timeout: 5,
            Severity: Minor
            Found in lib/file_helper.rb - About 5 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

            Method process_internal has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
            Open

                def process_internal
                  handle_bounce if is_bounce?
                  raise NoSenderDetectedError if @from_email.blank?
                  raise FromReplyByAddressError if is_from_reply_by_email_address?
                  raise ScreenedEmailError if ScreenedEmail.should_block?(@from_email)
            Severity: Minor
            Found in lib/email/receiver.rb - About 5 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

            File 006_badges.rb has 404 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            require 'badge_queries'
            
            BadgeGrouping.seed do |g|
              g.id = BadgeGrouping::GettingStarted
              g.name = "Getting Started"
            Severity: Minor
            Found in db/fixtures/006_badges.rb - About 5 hrs to fix

              Class Theme has 42 methods (exceeds 20 allowed). Consider refactoring.
              Open

              class Theme < ActiveRecord::Base
              
                @cache = DistributedCache.new('theme')
              
                belongs_to :user
              Severity: Minor
              Found in app/models/theme.rb - About 5 hrs to fix

                Class TopicViewSerializer has 42 methods (exceeds 20 allowed). Consider refactoring.
                Open

                class TopicViewSerializer < ApplicationSerializer
                  include PostStreamSerializerMixin
                  include SuggestedTopicsMixin
                  include TopicTagsMixin
                  include ApplicationHelper
                Severity: Minor
                Found in app/serializers/topic_view_serializer.rb - About 5 hrs to fix

                  File application_helper.rb has 399 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  require 'current_user'
                  require 'canonical_url'
                  require_dependency 'guardian'
                  require_dependency 'unread'
                  require_dependency 'age_words'
                  Severity: Minor
                  Found in app/helpers/application_helper.rb - About 5 hrs to fix

                    File plugin.rb has 396 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    register_asset "stylesheets/common/poll.scss"
                    register_asset "stylesheets/common/poll-ui-builder.scss"
                    register_asset "stylesheets/desktop/poll.scss", :desktop
                    register_asset "stylesheets/mobile/poll.scss", :mobile
                    
                    
                    Severity: Minor
                    Found in plugins/poll/plugin.rb - About 5 hrs to fix

                      Class PostAlerter has 41 methods (exceeds 20 allowed). Consider refactoring.
                      Open

                      class PostAlerter
                        def self.post_created(post, opts = {})
                          PostAlerter.new(opts).after_save_post(post, true)
                          post
                        end
                      Severity: Minor
                      Found in app/services/post_alerter.rb - About 5 hrs to fix

                        Class Search has 41 methods (exceeds 20 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: Minor
                        Found in lib/search.rb - About 5 hrs to fix

                          File theme.rb has 395 lines of code (exceeds 250 allowed). Consider refactoring.
                          Open

                          require_dependency 'distributed_cache'
                          require_dependency 'stylesheet/compiler'
                          require_dependency 'stylesheet/manager'
                          require_dependency 'theme_settings_parser'
                          require_dependency 'theme_settings_manager'
                          Severity: Minor
                          Found in app/models/theme.rb - About 5 hrs to fix

                            Method update has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
                            Open

                                def self.update(post, polls)
                                  ::Poll.transaction do
                                    has_changed = false
                                    edit_window = SiteSetting.poll_edit_window_mins
                            
                            
                            Severity: Minor
                            Found in plugins/poll/lib/polls_updater.rb - About 5 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

                            Severity
                            Category
                            Status
                            Source
                            Language