thredded/thredded

View on GitHub

Showing 21 of 70 total issues

File database_seeder.rb has 374 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'factory_bot'
require_relative '../../spec/support/features/fake_content'

# rubocop:disable HandleExceptions
begin
Severity: Minor
Found in lib/thredded/database_seeder.rb - About 5 hrs to fix

    Class DatabaseSeeder has 26 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class DatabaseSeeder # rubocop:disable Metrics/ClassLength
        module LogTime
          def self.included(base)
            base.extend ClassMethods
          end
    Severity: Minor
    Found in lib/thredded/database_seeder.rb - About 3 hrs to fix

      Method parse_names has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def parse_names(text) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
            result = []
            current = +''
            in_name = in_quoted = false
            text.each_char do |char|
      Severity: Minor
      Found in app/forms/thredded/private_topic_form.rb - About 2 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 show has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def show # rubocop:disable Metrics/MethodLength
            @messageboard = Thredded::Messageboard.first
            fail Thredded::Errors::DatabaseEmpty unless @messageboard
            @user = if thredded_current_user.thredded_anonymous?
                      Thredded.user_class.new(id: 1334, name: 'joe', email: 'joe@example.com')
      Severity: Minor
      Found in app/controllers/thredded/theme_previews_controller.rb - About 1 hr to fix

        Method time_ago has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def time_ago(datetime, default: '-', html_options: {})
              return content_tag :time, default if datetime.nil?
              html_options = html_options.dup
              is_current_year = datetime.year == Time.current.year
              if datetime > 4.days.ago
        Severity: Minor
        Found in app/helpers/thredded/application_helper.rb - 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

        Method create has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              log_method_time def create(count: (1..1), topics: seeder.topics) # rubocop:disable Metrics/MethodLength
                log "Creating #{count} additional posts in each topic..."
                topics.flat_map do |topic|
                  last_post_at = random_duration(0..256.hours).ago
                  posts_count = (count.min + rand(count.max + 1))
        Severity: Minor
        Found in lib/thredded/database_seeder.rb - About 1 hr to fix

          Method grouped has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def self.grouped( # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
                messageboards_scope, user: Thredded::NullUser.new, with_unread_topics_counts: !user.thredded_anonymous?
              )
                scope = messageboards_scope.preload(last_topic: [:last_user])
                  .eager_load(:group)
          Severity: Minor
          Found in app/view_models/thredded/messageboard_group_view.rb - About 1 hr to fix

            Method parse_names has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def parse_names(text) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
                  result = []
                  current = +''
                  in_name = in_quoted = false
                  text.each_char do |char|
            Severity: Minor
            Found in app/forms/thredded/private_topic_form.rb - About 1 hr to fix

              Method create has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                    log_method_time def create(count: 1)
                      log "Creating #{count} private topics..."
                      Array.new(count) do
                        started_by_first_user = [true, false].sample
                        user = started_by_first_user ? seeder.first_user : seeder.users[1..-1].sample
              Severity: Minor
              Found in lib/thredded/database_seeder.rb - About 55 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 render_collection_to_strings_with_cache has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def render_collection_to_strings_with_cache( # rubocop:disable Metrics/ParameterLists
                    view_context, collection:, partial:, expires_in:, render_threads: self.class.render_threads, locals: {}, **opts
                  )
                    template = @lookup_context.find_template(partial, [], true, locals, {})
                    collection = collection.to_a
              Severity: Minor
              Found in lib/thredded/collection_to_strings_with_cache_renderer.rb - About 55 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 save has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def save
                    return false unless valid?
                    Thredded::UserPreference.transaction do
                      user_preference.save!
              
              
              Severity: Minor
              Found in app/forms/thredded/user_preferences_form.rb - About 55 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 run! has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def run!(post:, moderation_state:, moderator:)
                    Thredded::Post.transaction do
                      post_moderation_record = Thredded::PostModerationRecord.record!(
                        moderator: moderator,
                        post: post,
              Severity: Minor
              Found in app/commands/thredded/moderate_post.rb - About 45 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 find_placeholder_end has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                      def find_placeholder_end(sibling)
                        children = []
                        placeholder_end = nil
                        loop do
                          sibling = sibling.next_sibling
              Severity: Minor
              Found in lib/thredded/html_pipeline/spoiler_tag_filter.rb - About 45 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 8 (exceeds 5 allowed). Consider refactoring.
              Open

                    def call
                      doc.css('a').each do |element|
                        url = element['href'].to_s
                        next unless url.present? && url == element.content && on_its_own_line?(element)
                        onebox_html = render_onebox_with_cache(url)
              Severity: Minor
              Found in lib/thredded/html_pipeline/onebox_filter.rb - About 45 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 grouped has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def self.grouped( # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
                    messageboards_scope, user: Thredded::NullUser.new, with_unread_topics_counts: !user.thredded_anonymous?
                  )
                    scope = messageboards_scope.preload(last_topic: [:last_user])
                      .eager_load(:group)
              Severity: Minor
              Found in app/view_models/thredded/messageboard_group_view.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 restore has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                    def restore(from = dump_file)
                      case adapter
                      when /postgres/i
                        cmd = [
                          'pg_restore --verbose --clean --no-owner --no-acl',
              Severity: Minor
              Found in lib/thredded/db_tools.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 6 (exceeds 5 allowed). Consider refactoring.
              Open

                    def call
                      doc.css('.thredded--post--content--spoiler--summary').each do |node|
                        node.content = I18n.t('thredded.posts.spoiler_summary_for_email')
                      end
                      doc.css('.thredded--post--content--spoiler--contents img').each do |img|
              Severity: Minor
              Found in lib/thredded/email_transformer/spoiler.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 pluck has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def pluck(*column_names)
                    super(*column_names.map do |n|
                      if n.is_a?(Arel::Node)
                        Arel.sql(n.to_sql)
                      elsif n.is_a?(Arel::Attributes::Attribute)
              Severity: Minor
              Found in lib/thredded/arel_compat.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 validate_notifier has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def self.validate_notifier(notifier)
                    unless notifier.respond_to?(:key) && /^[a-z_]+$/.match(notifier.key)
                      fail "Notifier problem: #{notifier.class.name} must respond to #key with a snake_case string"
                    end
                    %i[human_name new_post new_private_post].each do |m|
              Severity: Minor
              Found in lib/thredded/base_notifier.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 auto_follow_and_notify has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def auto_follow_and_notify
                    return unless user
                    # need to do this in-process so that it appears to them immediately
                    if first_post_in_topic? ? Thredded.auto_follow_when_creating_topic : Thredded.auto_follow_when_posting_in_topic
                      UserTopicFollow.create_unless_exists(user.id, postable_id, :posted)
              Severity: Minor
              Found in app/models/thredded/post.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