discourse/discourse

View on GitHub

Showing 1,474 of 1,778 total issues

File instance.rb has 529 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'digest/sha1'
require 'fileutils'
require_dependency 'plugin/metadata'
require_dependency 'auth'

Severity: Major
Found in lib/plugin/instance.rb - About 1 day to fix

    Class TopicsController has 60 methods (exceeds 20 allowed). Consider refactoring.
    Open

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

      Class StaffActionLogger has 60 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class StaffActionLogger
      
        def self.base_attrs
          [:topic_id, :post_id, :context, :subject, :ip_address, :previous_value, :new_value]
        end
      Severity: Major
      Found in app/services/staff_action_logger.rb - About 1 day to fix

        Method resolve has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
        Open

          def resolve
            if @uri && @uri.port == 80 && FinalDestination.is_https_domain?(@uri.hostname)
              @uri.scheme = "https"
              @uri = URI(@uri.to_s)
            end
        Severity: Minor
        Found in lib/final_destination.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 cooked_post_processor.rb has 517 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        require_dependency 'url_helper'
        require_dependency 'pretty_text'
        require_dependency 'quote_comparer'
        
        class CookedPostProcessor
        Severity: Major
        Found in lib/cooked_post_processor.rb - About 1 day to fix

          File advanced_user_narrative_spec.rb has 516 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          require 'rails_helper'
          
          RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
            let(:discobot_user) { User.find(-2) }
            let(:first_post) { Fabricate(:post, user: discobot_user) }

            Class Category has 58 methods (exceeds 20 allowed). Consider refactoring.
            Open

            class Category < ActiveRecord::Base
              self.ignored_columns = %w{
                uploaded_meta_id
              }
            
            
            Severity: Major
            Found in app/models/category.rb - About 1 day to fix

              Class UsersController has 58 methods (exceeds 20 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 1 day to fix

                Class TopicQuery has 58 methods (exceeds 20 allowed). Consider refactoring.
                Open

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

                  File category.rb has 513 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  require_dependency 'distributed_cache'
                  
                  class Category < ActiveRecord::Base
                    self.ignored_columns = %w{
                      uploaded_meta_id
                  Severity: Major
                  Found in app/models/category.rb - About 1 day to fix

                    File discourse.rb has 511 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    require 'cache'
                    require 'open3'
                    require_dependency 'route_format'
                    require_dependency 'plugin/instance'
                    require_dependency 'auth/default_current_user_provider'
                    Severity: Major
                    Found in lib/discourse.rb - About 1 day to fix

                      Method backfill has a Cognitive Complexity of 53 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def self.backfill(badge, opts = nil)
                          return unless SiteSetting.enable_badges
                          return unless badge.enabled
                          return unless badge.query.present?
                      
                      
                      Severity: Minor
                      Found in app/services/badge_granter.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 hijack has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def hijack(&blk)
                          controller_class = self.class
                      
                          if hijack = request.env['rack.hijack']
                      
                      
                      Severity: Minor
                      Found in lib/hijack.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 up has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def up
                          # Ensure we don't have duplicate polls
                          DB.exec <<~SQL
                            WITH duplicates AS (
                              SELECT id, row_number() OVER (PARTITION BY post_id) r
                      Severity: Minor
                      Found in plugins/poll/db/post_migrate/20180820080623_migrate_polls_data.rb - About 7 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 sso_login has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def sso_login
                          raise Discourse::NotFound.new unless SiteSetting.enable_sso
                      
                          params.require(:sso)
                          params.require(:sig)
                      Severity: Minor
                      Found in app/controllers/session_controller.rb - About 7 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 execute has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def execute(args)
                            post_id = args[:post_id]
                            raise Discourse::InvalidParameters.new(:post_id) unless post_id.present?
                      
                            post = Post.find_by(id: post_id)
                      Severity: Minor
                      Found in app/jobs/regular/pull_hotlinked_images.rb - About 7 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 create has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def create
                          params.require(:email)
                          params.permit(:user_fields)
                      
                          unless SiteSetting.allow_new_registrations
                      Severity: Minor
                      Found in app/controllers/users_controller.rb - About 7 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 groups_controller.rb has 472 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      class GroupsController < ApplicationController
                        requires_login only: [
                          :set_notifications,
                          :mentionable,
                          :messageable,
                      Severity: Minor
                      Found in app/controllers/groups_controller.rb - About 7 hrs to fix

                        Method message_for_email has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def message_for_email(user, post, type, notification, args = nil)
                              args ||= {}
                        
                              notification_type = args[:notification_type]
                              notification_data_hash = args[:notification_data_hash]
                        Severity: Minor
                        Found in app/jobs/regular/user_email.rb - About 7 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_revisor.rb has 468 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        require "edit_rate_limiter"
                        require 'post_locker'
                        
                        class PostRevisor
                        
                        
                        Severity: Minor
                        Found in lib/post_revisor.rb - About 7 hrs to fix
                          Severity
                          Category
                          Status
                          Source
                          Language