discourse/discourse

View on GitHub

Showing 1,669 of 1,992 total issues

Avoid too many return statements within this method.
Open

    return true if user.badges.where(name: title, allow_title: true).exists?
Severity: Major
Found in lib/guardian.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

          return @upload unless @upload.save
    Severity: Major
    Found in lib/upload_creator.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

            return false
      Severity: Major
      Found in lib/post_creator.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

            return true if skip_validations?
        Severity: Major
        Found in lib/post_creator.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                  return false
          Severity: Major
          Found in lib/post_creator.rb - About 30 mins to fix

            Method execute has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def execute(args)
                  raise Discourse::InvalidParameters.new(:user_id) unless args[:user_id].present?
                  raise Discourse::InvalidParameters.new(:message_type) unless args[:message_type].present?
            
                  user = User.find_by(id: args[:user_id])
            Severity: Minor
            Found in app/jobs/regular/send_system_message.rb - About 25 mins 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 publish has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.publish(type, id)
                  users = get_users(type, id)
                  serialized_users = users.map { |u| BasicUserSerializer.new(u, root: false) }
                  message = { users: serialized_users, time: Time.now.to_i }
                  messagebus_channel = get_messagebus_channel(type, id)
            Severity: Minor
            Found in plugins/discourse-presence/plugin.rb - About 25 mins 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 download has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def download(src)
                  downloaded = nil
            
                  begin
                    retries ||= 3
            Severity: Minor
            Found in app/jobs/regular/pull_hotlinked_images.rb - About 25 mins 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 track_like has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def track_like
                  post_topic_id = @post.topic_id
                  return unless valid_topic?(post_topic_id)
            
                  post_liked = PostAction.find_by(

            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_invite has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def send_invite(invite)
                  email = invite[:email]
                  groups = get_groups(invite[:groups])
                  topic = get_topic(invite[:topic_id])
            
            
            Severity: Minor
            Found in app/jobs/regular/bulk_invite.rb - About 25 mins 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 6 (exceeds 5 allowed). Consider refactoring.
            Open

                  def create!(post_id, poll)
                    close_at = begin
                      Time.zone.parse(poll["close"] || '')
                    rescue ArgumentError
                    end
            Severity: Minor
            Found in plugins/poll/plugin.rb - About 25 mins 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 generate_html has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            def generate_html(text, opts = {})
              output = "<p><span"
              output += " data-date=\"#{opts[:date]}\"" if opts[:date]
              output += " data-time=\"#{opts[:time]}\"" if opts[:time]
              output += " class=\"discourse-local-date\""
            Severity: Minor
            Found in plugins/discourse-local-dates/spec/lib/pretty_text_spec.rb - About 25 mins 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 get_groups has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_groups(group_names)
                  groups = []
            
                  if group_names
                    group_names = group_names.split(';')
            Severity: Minor
            Found in app/jobs/regular/bulk_invite.rb - About 25 mins 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 logo_group has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def logo_group(size, width, height)
                  return unless SiteSetting.site_logo_small_url.present?
            
                  begin
                    uri = URI(SiteSetting.site_logo_small_url)

            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 voters has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                  def voters(post_id, poll_name, user, opts = {})
                    post = Post.find_by(id: post_id)
                    raise Discourse::InvalidParameters.new("post_id is invalid") unless post
            
                    poll = Poll.find_by(post_id: post_id, name: poll_name)
            Severity: Minor
            Found in plugins/poll/plugin.rb - About 25 mins 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 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def execute(args)
                  return unless SiteSetting.auto_handle_queued_age.to_i > 0
            
                  Reviewable
                    .where(status: Reviewable.statuses[:pending])
            Severity: Minor
            Found in app/jobs/scheduled/auto_queue_handler.rb - About 25 mins 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 user_list_export has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def user_list_export
                  return enum_for(:user_list_export) unless block_given?
            
                  user_field_ids = UserField.pluck(:id)
            
            
            Severity: Minor
            Found in app/jobs/regular/export_csv_file.rb - About 25 mins 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 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def execute(_)
                  return if SiteSetting.invalidate_inactive_admin_email_after_days == 0
            
                  User.human_users
                    .where(admin: true)
            Severity: Minor
            Found in app/jobs/scheduled/invalidate_inactive_admins.rb - About 25 mins 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 pluralize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            I18n.pluralize = function(translation, scope, options) {
              if (typeof translation !== "object") return translation;
            
              options = this.prepareOptions(options);
              var count = options.count.toString();
            Severity: Minor
            Found in app/assets/javascripts/locales/i18n.js - About 25 mins 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 parse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.parse(line)
            
                  result = new
                  _, result.time, result.ip_address, result.url, result.user_agent,
                    result.route, result.status, result.bytes_sent, result.referer,
            Severity: Minor
            Found in plugins/discourse-nginx-performance-report/lib/log_analyzer.rb - About 25 mins 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