discourse/discourse

View on GitHub

Showing 2,941 of 3,748 total issues

Method resolve has a Cognitive Complexity of 59 (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 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 emoji-picker.js has 544 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { inject as service } from "@ember/service";
import { throttle, debounce, schedule, later } from "@ember/runloop";
import Component from "@ember/component";
import { on, observes } from "discourse-common/utils/decorators";
import { findRawTemplate } from "discourse-common/lib/raw-templates";
Severity: Major
Found in app/assets/javascripts/discourse/app/components/emoji-picker.js - About 1 day to fix

    File search-advanced-options.js has 542 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import I18n from "I18n";
    import { debounce, scheduleOnce } from "@ember/runloop";
    import Component from "@ember/component";
    import { observes } from "discourse-common/utils/decorators";
    import { escapeExpression } from "discourse/lib/utilities";

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

        def create
          params.require(:email)
          params.require(:username)
          params.require(:invite_code) if SiteSetting.require_invite_code
          params.permit(:user_fields)
      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

      `` has 61 functions (exceeds 20 allowed). Consider refactoring.
      Open

        {
          pluginApiIdentifiers: ["select-kit"],
          layoutName: "select-kit/templates/components/select-kit",
          classNames: ["select-kit"],
          classNameBindings: [
      Severity: Major
      Found in app/assets/javascripts/select-kit/app/components/select-kit.js - About 1 day to fix

        Class TopicsController has 61 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class TopicsController < ApplicationController
          requires_login only: [
            :timings,
            :destroy_timings,
            :update,
        Severity: Major
        Found in app/controllers/topics_controller.rb - About 1 day to fix

          Class TopicQuery has 61 methods (exceeds 20 allowed). Consider refactoring.
          Open

          class TopicQuery
            PG_MAX_INT ||= 2147483647
          
            def self.validators
              @validators ||= begin
          Severity: Major
          Found in lib/topic_query.rb - About 1 day to fix

            `` has 60 functions (exceeds 20 allowed). Consider refactoring.
            Open

            export default {
              init(keyTrapper, container) {
                this.keyTrapper = keyTrapper;
                this.container = container;
                this._stopCallback();
            Severity: Major
            Found in app/assets/javascripts/discourse/app/lib/keyboard-shortcuts.js - About 1 day to fix

              PluginApi has 60 functions (exceeds 20 allowed). Consider refactoring.
              Open

              class PluginApi {
                constructor(version, container) {
                  this.version = version;
                  this.container = container;
                  this.h = h;
              Severity: Major
              Found in app/assets/javascripts/discourse/app/lib/plugin-api.js - About 1 day to fix

                File admin-user.js has 527 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                import I18n from "I18n";
                import discourseComputed from "discourse-common/utils/decorators";
                import { filter, or, gt, lt, not } from "@ember/object/computed";
                import { iconHTML } from "discourse-common/lib/icon-library";
                import { ajax } from "discourse/lib/ajax";
                Severity: Major
                Found in app/assets/javascripts/admin/models/admin-user.js - About 1 day to fix

                  Method up has a Cognitive Complexity of 55 (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 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 reviewable.rb has 522 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  class Reviewable < ActiveRecord::Base
                    class UpdateConflict < StandardError; end
                  
                    class InvalidAction < StandardError
                      def initialize(action_id, klass)
                  Severity: Major
                  Found in app/models/reviewable.rb - About 1 day to fix

                    Function default has 213 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export default function() {
                      // Error page
                      this.route("exception", { path: "/exception" });
                      this.route("exception-unknown", { path: "/404" });
                    
                    
                    Severity: Major
                    Found in app/assets/javascripts/discourse/app/routes/app-route-map.js - About 1 day to fix

                      Method update has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def update(attributes = {})
                          user_profile = user.user_profile
                          user_profile.dismissed_banner_key = attributes[:dismissed_banner_key] if attributes[:dismissed_banner_key].present?
                          unless SiteSetting.enable_sso && SiteSetting.sso_overrides_bio
                            user_profile.bio_raw = attributes.fetch(:bio_raw) { user_profile.bio_raw }
                      Severity: Minor
                      Found in app/services/user_updater.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

                      Topic has 58 functions (exceeds 20 allowed). Consider refactoring.
                      Open

                      const Topic = RestModel.extend({
                        message: null,
                        errorLoading: false,
                      
                        @discourseComputed("last_read_post_number", "highest_post_number")
                      Severity: Major
                      Found in app/assets/javascripts/discourse/app/models/topic.js - About 1 day to fix

                        Method handle_message has a Cognitive Complexity of 53 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def handle_message
                              [:state, :topic_id].each do |key|
                                raise ActionController::ParameterMissing.new(key) unless params.key?(key)
                              end
                        
                        
                        Severity: Minor
                        Found in plugins/discourse-presence/plugin.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 header.js has 503 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        import I18n from "I18n";
                        import { get } from "@ember/object";
                        import { schedule } from "@ember/runloop";
                        import { createWidget } from "discourse/widgets/widget";
                        import { iconNode } from "discourse-common/lib/icon-library";
                        Severity: Major
                        Found in app/assets/javascripts/discourse/app/widgets/header.js - About 1 day to fix

                          Function Pikaday has 198 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              Pikaday = function(options)
                              {
                                  var self = this,
                                      opts = self.config(options);
                          
                          
                          Severity: Major
                          Found in public/javascripts/pikaday.js - About 7 hrs to fix

                            Method migrate_to_new_scheme has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
                            Open

                              def self.migrate_to_new_scheme(limit: nil)
                                problems = []
                            
                                DistributedMutex.synchronize("migrate_upload_to_new_scheme") do
                                  if SiteSetting.migrate_to_new_scheme
                            Severity: Minor
                            Found in app/models/upload.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