discourse/discourse

View on GitHub

Showing 1,430 of 1,732 total issues

Method show_in_site has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

  def show_in_site(hostname)

    username = params[:username].to_s
    return render_blank unless user = User.find_by(username_lower: username.downcase)

Severity: Minor
Found in app/controllers/user_avatars_controller.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 digest has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

  def digest(user, opts = {})
    build_summary_for(user)
    min_date = opts[:since] || user.last_emailed_at || user.last_seen_at || 1.month.ago

    # Fetch some topics and posts to show
Severity: Minor
Found in app/mailers/user_notifications.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 tag_topic_by_names has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

  def self.tag_topic_by_names(topic, guardian, tag_names_arg, append: false)
    if guardian.can_tag?(topic)
      tag_names = DiscourseTagging.tags_for_saving(tag_names_arg, guardian) || []

      old_tag_names = topic.tags.pluck(:name) || []
Severity: Minor
Found in lib/discourse_tagging.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 build_short_edit_script has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

  def build_short_edit_script(shortest_path)
    ses = []
    x, y = 1, 1
    px, py = 0, 0
    i = shortest_path.length - 1
Severity: Minor
Found in lib/onpdiff.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 plugin.rb has 384 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 Search has 39 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Search
      INDEX_VERSION = 2.freeze
      DIACRITICS ||= /([\u0300-\u036f]|[\u1AB0-\u1AFF]|[\u1DC0-\u1DFF]|[\u20D0-\u20FF])/
    
      def self.per_facet
    Severity: Minor
    Found in lib/search.rb - About 5 hrs to fix

      Method index has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.index(obj, force: false)
          return if @disabled
      
          category_name = nil
          tag_names = nil
      Severity: Minor
      Found in app/services/search_indexer.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 html_for has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.html_for(category, opts = nil)
          opts = opts || {}
      
          # If there is no category, bail
          return "" if category.blank?
      Severity: Minor
      Found in lib/category_badge.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 send has 127 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def send
            return if SiteSetting.disable_emails == "yes" && @email_type.to_s != "admin_login"
      
            return if ActionMailer::Base::NullMail === @message
            return if ActionMailer::Base::NullMail === (@message.message rescue nil)
      Severity: Major
      Found in lib/email/sender.rb - About 5 hrs to fix

        File topic_user.rb has 377 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        require_dependency 'notification_levels'
        
        class TopicUser < ActiveRecord::Base
          belongs_to :user
          belongs_to :topic
        Severity: Minor
        Found in app/models/topic_user.rb - About 5 hrs to fix

          Class AdminDashboardData has 38 methods (exceeds 20 allowed). Consider refactoring.
          Open

          class AdminDashboardData
            include StatsCacheable
          
            GLOBAL_REPORTS ||= [
              'visits',
          Severity: Minor
          Found in app/models/admin_dashboard_data.rb - About 5 hrs to fix

            Class CurrentUserSerializer has 38 methods (exceeds 20 allowed). Consider refactoring.
            Open

            class CurrentUserSerializer < BasicUserSerializer
            
              attributes :name,
                         :unread_notifications,
                         :unread_private_messages,
            Severity: Minor
            Found in app/serializers/current_user_serializer.rb - About 5 hrs to fix

              Method flagged_posts_report has 124 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def self.flagged_posts_report(current_user, opts = nil)
                  opts ||= {}
                  offset = opts[:offset] || 0
                  per_page = opts[:per_page] || 25
              
              
              Severity: Major
              Found in lib/flag_query.rb - About 4 hrs to fix

                Method change_external_attributes_and_override has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
                Open

                  def change_external_attributes_and_override(sso_record, user)
                    if SiteSetting.sso_overrides_email && user.email != Email.downcase(email)
                      user.email = email
                      user.active = false if require_activation
                    end
                Severity: Minor
                Found in app/models/discourse_single_sign_on.rb - About 4 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 initialize has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
                Open

                    def initialize(to, opts = nil)
                      @to = to
                      @opts = opts || {}
                
                      @template_args = {
                Severity: Minor
                Found in lib/email/message_builder.rb - About 4 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 pretty_text.rb has 369 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                require 'mini_racer'
                require 'nokogiri'
                require 'erb'
                require_dependency 'url_helper'
                require_dependency 'excerpt_parser'
                Severity: Minor
                Found in lib/pretty_text.rb - About 4 hrs to fix

                  Class TrustLevel3Requirements has 37 methods (exceeds 20 allowed). Consider refactoring.
                  Open

                  class TrustLevel3Requirements
                  
                    class PenaltyCounts
                      attr_reader :silenced, :suspended
                  
                  
                  Severity: Minor
                  Found in app/models/trust_level3_requirements.rb - About 4 hrs to fix

                    File theme.rb has 368 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 4 hrs to fix

                      File user_serializer.rb has 367 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      class UserSerializer < BasicUserSerializer
                      
                        attr_accessor :omit_stats,
                                      :topic_post_count
                      
                      
                      Severity: Minor
                      Found in app/serializers/user_serializer.rb - About 4 hrs to fix

                        File session_controller.rb has 366 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        require_dependency 'rate_limiter'
                        require_dependency 'single_sign_on'
                        require_dependency 'single_sign_on_provider'
                        require_dependency 'url_helper'
                        
                        
                        Severity: Minor
                        Found in app/controllers/session_controller.rb - About 4 hrs to fix
                          Severity
                          Category
                          Status
                          Source
                          Language