discourse/discourse

View on GitHub

Showing 2,973 of 3,784 total issues

Function _showLinkCounts has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  _showLinkCounts($html) {
    const linkCounts = this.attrs.linkCounts;
    if (!linkCounts) {
      return;
    }
Severity: Minor
Found in app/assets/javascripts/discourse/app/widgets/post-cooked.js - About 1 hr to fix

    Method counts_for has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.counts_for(guardian, topic, posts)
        return {} if posts.blank?
    
        # Sam: this is not tidy in AR and also happens to be a critical path
        # for topic view
    Severity: Minor
    Found in app/models/topic_link.rb - About 1 hr to fix

      Method select_avatar has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def select_avatar
          user = fetch_user_from_params
          guardian.ensure_can_edit!(user)
      
          url = params[:url]
      Severity: Minor
      Found in app/controllers/users_controller.rb - About 1 hr to fix

        Method toggle_archive_message has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def toggle_archive_message(archive)
            topic = Topic.find(params[:id].to_i)
        
            group_id = nil
        
        
        Severity: Minor
        Found in app/controllers/topics_controller.rb - About 1 hr to fix

          Method unsubscribe has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def unsubscribe
              @not_found = true
              @watched_count = nil
          
              if key = UnsubscribeKey.find_by(key: params[:key])
          Severity: Minor
          Found in app/controllers/email_controller.rb - About 1 hr to fix

            Method next has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def self.next(count, category = nil)
                key = cache_key(category)
            
                results = []
            
            
            Severity: Minor
            Found in app/services/random_topic_selector.rb - About 1 hr to fix

              Method merge_given_daily_likes has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def merge_given_daily_likes
                  sql = <<~SQL
                    INSERT INTO given_daily_likes AS g (user_id, likes_given, given_date, limit_reached)
                      SELECT
                        :target_user_id                AS user_id,
              Severity: Minor
              Found in app/services/user_merger.rb - About 1 hr to fix

                Method translate_no_override has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def translate_no_override(key, options)
                      # note we skip cache for :format and :count
                      should_raise = false
                      locale = nil
                
                
                Severity: Minor
                Found in lib/freedom_patches/translate_accelerator.rb - About 1 hr to fix

                  Method can_edit_topic? has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def can_edit_topic?(topic)
                      return false if Discourse.static_doc_topic_ids.include?(topic.id) && !is_admin?
                      return false unless can_see?(topic)
                  
                      return true if is_admin?
                  Severity: Minor
                  Found in lib/guardian/topic_guardian.rb - About 1 hr to fix

                    Method translate has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        def translate(*args)
                          execute_reload if @requires_reload
                    
                          options  = args.last.is_a?(Hash) ? args.pop.dup : {}
                          key      = args.shift
                    Severity: Minor
                    Found in lib/freedom_patches/translate_accelerator.rb - About 1 hr to fix

                      Method create_group_post has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          def create_group_post(group, user, body, elided)
                            message_ids = Email::Receiver.extract_reply_message_ids(@mail, max_message_id_count: 5)
                            post_ids = []
                      
                            incoming_emails = IncomingEmail
                      Severity: Minor
                      Found in lib/email/receiver.rb - About 1 hr to fix

                        Method html_part has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            def html_part
                              return unless html_override = @opts[:html_override]
                        
                              if @template_args[:unsubscribe_instructions].present?
                                unsubscribe_instructions = PrettyText.cook(@template_args[:unsubscribe_instructions], sanitize: false).html_safe
                        Severity: Minor
                        Found in lib/email/message_builder.rb - About 1 hr to fix

                          Method parse_from_field has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              def parse_from_field(mail = nil)
                                mail ||= @mail
                          
                                if email_log.present?
                                  email = email_log.to_address || email_log.user&.email
                          Severity: Minor
                          Found in lib/email/receiver.rb - About 1 hr to fix

                            Method create_missing_discourse_functions has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                def create_missing_discourse_functions
                                  log "Creating missing functions in the discourse_functions schema..."
                            
                                  @created_functions_for_table_columns = []
                                  all_readonly_table_columns = []
                            Severity: Minor
                            Found in lib/backup_restore/database_restorer.rb - About 1 hr to fix

                              Method inline_html has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                def inline_html
                                  i = 0
                                  inline = []
                                  while i < @block_by_block_diff.size
                                    op_code = @block_by_block_diff[i][1]
                              Severity: Minor
                              Found in lib/discourse_diff.rb - About 1 hr to fix

                                Method add_large_image_placeholder! has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                  def add_large_image_placeholder!(img)
                                    url = img["src"]
                                
                                    is_hyperlinked = is_a_hyperlink?(img)
                                
                                
                                Severity: Minor
                                Found in lib/cooked_post_processor.rb - About 1 hr to fix

                                  Method append_step has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                    def append_step(step, after: nil)
                                      return if @@excluded_steps.include?(step)
                                  
                                      step = create_step(step) if step.is_a?(String)
                                      yield step if block_given?
                                  Severity: Minor
                                  Found in lib/wizard.rb - About 1 hr to fix

                                    Method find_theme_extensions has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                        def find_theme_extensions(theme_ids)
                                          extensions = []
                                    
                                          resolved_ids = Theme.transform_ids(theme_ids)
                                    
                                    
                                    Severity: Minor
                                    Found in lib/content_security_policy/extension.rb - About 1 hr to fix

                                      Function _computeReport has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                        _computeReport() {
                                          if (!this.element || this.isDestroying || this.isDestroyed) {
                                            return;
                                          }
                                      
                                      
                                      Severity: Minor
                                      Found in app/assets/javascripts/admin/components/admin-report.js - About 1 hr 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

                                      Function sortedData has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                        sortedData(sortLabel, sortDirection, data) {
                                          data = makeArray(data);
                                      
                                          if (sortLabel) {
                                            const compare = (label, direction) => {
                                      Severity: Minor
                                      Found in app/assets/javascripts/admin/components/admin-report-table.js - About 1 hr 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