discourse/discourse

View on GitHub

Showing 1,474 of 1,778 total issues

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

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

class AdminDashboardData
  include StatsCacheable

  # kept for backward compatibility
  GLOBAL_REPORTS ||= []
Severity: Minor
Found in app/models/admin_dashboard_data.rb - About 5 hrs to fix

    Class UsersController has 39 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Admin::UsersController < Admin::AdminController
    
      before_action :fetch_user, only: [:suspend,
                                        :unsuspend,
                                        :log_out,
    Severity: Minor
    Found in app/controllers/admin/users_controller.rb - About 5 hrs to fix

      File theme_field.rb has 379 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 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

        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

          File theme.rb has 377 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

            File session_controller.rb has 377 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 5 hrs to fix

              Method posts_query has 123 lines of code (exceeds 25 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: Major
              Found in lib/search.rb - About 4 hrs to fix

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

                  def self.migrate_to_new_scheme(limit = nil)
                    problems = []
                
                    if SiteSetting.migrate_to_new_scheme
                      max_file_size_kb = [SiteSetting.max_image_size_kb, SiteSetting.max_attachment_size_kb].max.kilobytes
                Severity: Minor
                Found in app/models/upload.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 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 index has a Cognitive Complexity of 33 (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 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 filter_allowed_tags has a Cognitive Complexity of 33 (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 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

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

                    def select_body
                      text = nil
                      html = nil
                      text_content_type = nil
                
                
                Severity: Minor
                Found in lib/email/receiver.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

                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

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

                  class PostCreator
                    include HasErrors
                  
                    attr_reader :opts
                  
                  
                  Severity: Minor
                  Found in lib/post_creator.rb - About 4 hrs to fix

                    File pretty_text.rb has 368 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

                      Method input has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def input(input, user, post: nil, topic_id: nil, skip: false)
                            new_post = nil
                            @post = post
                            @topic_id = topic_id
                            @skip = skip
                      Severity: Minor
                      Found in plugins/discourse-narrative-bot/lib/discourse_narrative_bot/base.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 index has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def index
                          raise Discourse::InvalidAccess.new(:enable_user_directory) unless SiteSetting.enable_user_directory?
                      
                          period = params.require(:period)
                          period_type = DirectoryItem.period_types[period.to_sym]
                      Severity: Minor
                      Found in app/controllers/directory_items_controller.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

                      Severity
                      Category
                      Status
                      Source
                      Language