discourse/discourse

View on GitHub

Showing 1,137 of 1,669 total issues

Method extract_from has a Cognitive Complexity of 86 (exceeds 5 allowed). Consider refactoring.
Open

  def self.extract_from(post)
    return if post.blank? || post.whisper?

    added_urls = []
    reflected_ids = []
Severity: Minor
Found in app/models/topic_link.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 to_html has a Cognitive Complexity of 85 (exceeds 5 allowed). Consider refactoring.
Open

  def to_html
    do_quotes = do_backticks = do_dashes = do_ellipses = nil

    if @options.include?(0)
      # Do nothing.
Severity: Minor
Found in lib/html_prettify.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 create_for has a Cognitive Complexity of 85 (exceeds 5 allowed). Consider refactoring.
Open

  def create_for(user_id)
    if filesize <= 0
      @upload.errors.add(:base, I18n.t("upload.empty"))
      return @upload
    end
Severity: Minor
Found in lib/upload_creator.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 default_results has a Cognitive Complexity of 83 (exceeds 5 allowed). Consider refactoring.
Open

  def default_results(options = {})
    options.reverse_merge!(@options)
    options.reverse_merge!(per_page: per_page_setting)

    # Whether to return visible topics
Severity: Minor
Found in lib/topic_query.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 build has a Cognitive Complexity of 75 (exceeds 5 allowed). Consider refactoring.
Open

    def build
      return @wizard unless SiteSetting.wizard_enabled? && @wizard.user.try(:staff?)

      @wizard.append_step('locale') do |step|
        step.banner = "welcome.png"
Severity: Minor
Found in lib/wizard/builder.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 posts_query has a Cognitive Complexity of 72 (exceeds 5 allowed). Consider refactoring.
Open

  def posts_query(limit, opts = nil)
    opts ||= {}
    posts = Post.where(post_type: Topic.visible_post_types(@guardian.user))
      .joins(:post_search_data, :topic)
      .joins("LEFT JOIN categories ON categories.id = topics.category_id")
Severity: Minor
Found in lib/search.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 destroy has a Cognitive Complexity of 70 (exceeds 5 allowed). Consider refactoring.
Open

  def destroy(user, opts = {})
    raise Discourse::InvalidParameters.new('user is nil') unless user && user.is_a?(User)
    raise PostsExistError if !opts[:delete_posts] && user.posts.count != 0
    @guardian.ensure_can_delete_user!(user)

Severity: Minor
Found in app/services/user_destroyer.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 send_notification_email has a Cognitive Complexity of 69 (exceeds 5 allowed). Consider refactoring.
Open

  def send_notification_email(opts)
    post = opts[:post]
    title = opts[:title]

    allow_reply_by_email = opts[:allow_reply_by_email]
Severity: Minor
Found in app/mailers/user_notifications.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 password_reset has a Cognitive Complexity of 63 (exceeds 5 allowed). Consider refactoring.
Open

  def password_reset
    expires_now

    token = params[:token]

Severity: Minor
Found in app/controllers/users_controller.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 show has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring.
Open

  def show
    if request.referer
      flash["referer"] ||= request.referer[0..255]
    end

Severity: Minor
Found in app/controllers/topics_controller.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 send has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
Open

    def send
      return if SiteSetting.disable_emails == "yes" && @email_type.to_s != "admin_login"

      return if ActionMailer::Base::NullMail === @message
      return if ActionMailer::Base::NullMail === (@message.message rescue nil)
Severity: Minor
Found in lib/email/sender.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 backfill has a Cognitive Complexity of 55 (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

File post_action.rb has 500 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require_dependency 'rate_limiter'
require_dependency 'system_message'

class PostAction < ActiveRecord::Base
  class AlreadyActed < StandardError; end
Severity: Minor
Found in app/models/post_action.rb - About 1 day to fix

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

      def post_process_oneboxes
        Oneboxer.apply(@doc) do |url|
          @has_oneboxes = true
          Oneboxer.onebox(url,
            invalidate_oneboxes: !!@opts[:invalidate_oneboxes],
    Severity: Minor
    Found in lib/cooked_post_processor.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 resolve has a Cognitive Complexity of 51 (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 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 instance.rb has 494 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'digest/sha1'
    require 'fileutils'
    require_dependency 'plugin/metadata'
    require_dependency 'auth'
    
    
    Severity: Minor
    Found in lib/plugin/instance.rb - About 7 hrs to fix

      File discourse.rb has 492 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: Minor
      Found in lib/discourse.rb - About 7 hrs to fix

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

            def execute(args)
              return unless SiteSetting.download_remote_images_to_local?
        
              post_id = args[:post_id]
              raise Discourse::InvalidParameters.new(:post_id) unless post_id.present?
        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

        Severity
        Category
        Status
        Source
        Language