discourse/discourse

View on GitHub

Showing 1,692 of 2,021 total issues

Avoid too many return statements within this method.
Open

        return false unless SiteSetting.enable_personal_messages?
Severity: Major
Found in lib/guardian.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

        return false if user.blank?
    Severity: Major
    Found in lib/guardian.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

          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 @upload unless @upload.save
            Severity: Major
            Found in lib/upload_creator.rb - About 30 mins to fix

              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 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 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 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

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

                  def execute(args)
                    notification = args["payload"]
                    notification["url"] = UrlHelper.absolute_without_cdn(notification["post_url"])
                    notification.delete("post_url")
              
              
              Severity: Minor
              Found in app/jobs/regular/push_notification.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 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 get_screened_url_fields has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def get_screened_url_fields(screened_url)
                    screened_url_array = []
              
                    HEADER_ATTRS_FOR['screened_url'].each do |attr|
                      data =
              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 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 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 get_header has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def get_header
                    if @entity == 'user_list'
                      header_array = HEADER_ATTRS_FOR['user_list'] + HEADER_ATTRS_FOR['user_stats'] + HEADER_ATTRS_FOR['user_profile']
                      header_array.concat(HEADER_ATTRS_FOR['user_sso']) if SiteSetting.enable_sso
                      user_custom_fields = UserField.all
              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

              Severity
              Category
              Status
              Source
              Language