discourse/discourse

View on GitHub

Showing 1,669 of 1,992 total issues

Method prepare_lines has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def prepare_lines
    previous_line = nil

    @plaintext.each_line do |text|
      text.chomp!
Severity: Minor
Found in lib/plain_text_to_markdown.rb - About 35 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 update_topic has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def update_topic
    Topic.transaction do
      PostRevisor.tracked_topic_fields.each do |f, cb|
        if !@topic_changes.errored? && @fields.has_key?(f)
          cb.call(@topic_changes, @fields[f])
Severity: Minor
Found in lib/post_revisor.rb - About 35 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 validate_each has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def validate_each(record, attribute, value)
    old_errors = record.errors[attribute].size

    # look for any duplicates at all
    super
Severity: Minor
Found in lib/validators/unique_among_validator.rb - About 35 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 description has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def description
      time_left =
        if @available_in <= 3
          I18n.t("rate_limiter.short_time")
        elsif @available_in < 1.minute.to_i
Severity: Minor
Found in lib/rate_limiter/limit_exceeded.rb - About 35 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 new_posts has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def new_posts
    return 0 if @topic_user.highest_seen_post_number.blank?
    return 0 if do_not_notify?(@topic_user.notification_level)

    highest_post_number = @guardian.is_staff? ? @topic.highest_staff_post_number : @topic.highest_post_number
Severity: Minor
Found in lib/unread.rb - About 35 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 blurb_for has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def self.blurb_for(cooked, term = nil, blurb_length = 200)
      blurb = nil
      cooked = SearchIndexer.scrub_html_for_search(cooked)

      urls = Set.new
Severity: Minor
Found in lib/search/grouped_search_results.rb - About 35 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 enqueue_jobs has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def enqueue_jobs
    # We need to enqueue jobs after the transaction.
    # Otherwise they might begin before the data has been comitted.
    enqueue_post_alerts unless @opts[:import_mode]
    feature_topic_users unless @opts[:import_mode]
Severity: Minor
Found in lib/post_jobs_enqueuer.rb - About 35 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 call has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def call(env)

    cors_origins = @global_origins || []
    cors_origins += SiteSetting.cors_origins.split('|') if SiteSetting.cors_origins.present?
    cors_origins = cors_origins.presence
Severity: Minor
Found in config/initializers/008-rack-cors.rb - About 35 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

Avoid too many return statements within this method.
Open

      return unless message_id = message.dig("mail", "messageId").presence
Severity: Major
Found in app/jobs/regular/process_sns_notification.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

          return false unless hostname
    Severity: Major
    Found in app/jobs/regular/pull_hotlinked_images.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

              return false unless valid_number_of_options?(poll)
      Severity: Major
      Found in plugins/poll/lib/polls_validator.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                return false unless valid_multiple_choice_settings?(poll)
        Severity: Major
        Found in plugins/poll/lib/polls_validator.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                return unless bounce_type = message.dig("bounce", "bounceType").presence
          Severity: Major
          Found in app/jobs/regular/process_sns_notification.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return false
            Severity: Major
            Found in app/jobs/regular/pull_hotlinked_images.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return false unless at_least_two_options?(poll)
              Severity: Major
              Found in plugins/poll/lib/polls_validator.rb - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                      return unless Aws::SNS::MessageVerifier.new.authentic?(raw)
                Severity: Major
                Found in app/jobs/regular/process_sns_notification.rb - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                        return {
                          reason: I18n.t('redirected_to_top_reasons.new_user'),
                          period: period
                        }
                  Severity: Major
                  Found in app/models/user_option.rb - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return skip_message(SkippedEmailLog.reason_types[:exceeded_bounces_limit])
                    Severity: Major
                    Found in app/jobs/regular/user_email.rb - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return skip_message(SkippedEmailLog.reason_types[:user_email_seen_recently])
                      Severity: Major
                      Found in app/jobs/regular/user_email.rb - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                  return SkippedEmailLog.reason_types[:user_email_already_read]
                        Severity: Major
                        Found in app/jobs/regular/user_email.rb - About 30 mins to fix
                          Severity
                          Category
                          Status
                          Source
                          Language