discourse/discourse

View on GitHub

Showing 3,817 of 3,817 total issues

Function strategies has a Cognitive Complexity of 115 (exceeds 5 allowed). Consider refactoring.
Open

this.workbox.strategies = (function (exports, logger_mjs, assert_mjs, cacheNames_mjs, cacheWrapper_mjs, fetchWrapper_mjs, getFriendlyURL_mjs, WorkboxError_mjs) {
  'use strict';

  try {
    self['workbox:strategies:4.3.1'] && _();
Severity: Minor
Found in public/javascripts/workbox/workbox-strategies.dev.js - About 2 days 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 search.rb has 914 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Search
  DIACRITICS ||= /([\u0300-\u036f]|[\u1AB0-\u1AFF]|[\u1DC0-\u1DFF]|[\u20D0-\u20FF])/

  cattr_accessor :preloaded_topic_custom_fields
  self.preloaded_topic_custom_fields = Set.new
Severity: Major
Found in lib/search.rb - About 2 days to fix

    File d-editor.js has 891 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import I18n from "I18n";
    import { debounce, later, next, schedule, scheduleOnce } from "@ember/runloop";
    import { inject as service } from "@ember/service";
    import Component from "@ember/component";
    /*global Mousetrap:true */
    Severity: Major
    Found in app/assets/javascripts/discourse/app/components/d-editor.js - About 2 days to fix

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

      import { getURLWithCDN } from "discourse-common/lib/get-url";
      import getURL from "discourse-common/lib/get-url";
      import I18n from "I18n";
      import { A } from "@ember/array";
      import { isEmpty } from "@ember/utils";
      Severity: Major
      Found in app/assets/javascripts/discourse/app/models/user.js - About 2 days to fix

        Class Topic has 112 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class Topic < ActiveRecord::Base
          class UserExists < StandardError; end
          include ActionView::Helpers::SanitizeHelper
          include RateLimiter::OnCreateRecord
          include HasCustomFields
        Severity: Major
        Found in app/models/topic.rb - About 2 days to fix

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

                      if (result0 !== null) {
                        if (input.substr(pos, 6) === "select") {
                          result1 = "select";
                          pos += 6;
                        } else {
          Severity: Major
          Found in lib/javascripts/messageformat.js and 2 other locations - About 2 days to fix
          lib/javascripts/messageformat.js on lines 423..480
          lib/javascripts/messageformat.js on lines 658..715

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 381.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

                    if (result0 !== null) {
                      if (input.substr(pos, 6) === "offset") {
                        result1 = "offset";
                        pos += 6;
                      } else {
          Severity: Major
          Found in lib/javascripts/messageformat.js and 2 other locations - About 2 days to fix
          lib/javascripts/messageformat.js on lines 423..480
          lib/javascripts/messageformat.js on lines 497..554

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 381.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

                    if (result0 !== null) {
                      if (input.substr(pos, 6) === "plural") {
                        result1 = "plural";
                        pos += 6;
                      } else {
          Severity: Major
          Found in lib/javascripts/messageformat.js and 2 other locations - About 2 days to fix
          lib/javascripts/messageformat.js on lines 497..554
          lib/javascripts/messageformat.js on lines 658..715

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 381.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          File topic_query.rb has 869 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

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

            File topics_controller.rb has 862 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

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

              File post.rb has 854 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              require 'archetype'
              require 'digest/sha1'
              
              class Post < ActiveRecord::Base
                include RateLimiter::OnCreateRecord
              Severity: Major
              Found in app/models/post.rb - About 2 days to fix

                File select-kit.js has 848 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                import I18n from "I18n";
                import EmberObject, { computed, get } from "@ember/object";
                import { guidFor } from "@ember/object/internals";
                import Component from "@ember/component";
                import deprecated from "discourse-common/lib/deprecated";
                Severity: Major
                Found in app/assets/javascripts/select-kit/addon/components/select-kit.js - About 2 days to fix

                  File post-stream.js has 835 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  import I18n from "I18n";
                  import { get } from "@ember/object";
                  import { isEmpty } from "@ember/utils";
                  import { or, not, and } from "@ember/object/computed";
                  import { ajax } from "discourse/lib/ajax";
                  Severity: Major
                  Found in app/assets/javascripts/discourse/app/models/post-stream.js - About 2 days to fix

                    File composer-editor.js has 816 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    import getURL from "discourse-common/lib/get-url";
                    import I18n from "I18n";
                    import { debounce, later, next, schedule, throttle } from "@ember/runloop";
                    import Component from "@ember/component";
                    import userSearch from "discourse/lib/user-search";
                    Severity: Major
                    Found in app/assets/javascripts/discourse/app/components/composer-editor.js - About 1 day to fix

                      Method build has a Cognitive Complexity of 90 (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 create_for has a Cognitive Complexity of 90 (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 posts_query has a Cognitive Complexity of 88 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def posts_query(limit, type_filter: nil, aggregate_search: false)
                          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

                      File group.rb has 749 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      require 'net/imap'
                      
                      class Group < ActiveRecord::Base
                        # TODO(2021-05-26): remove
                        self.ignored_columns = %w{
                      Severity: Major
                      Found in app/models/group.rb - About 1 day to fix

                        Function routing has a Cognitive Complexity of 87 (exceeds 5 allowed). Consider refactoring.
                        Open

                        this.workbox.routing = (function (exports, assert_mjs, logger_mjs, cacheNames_mjs, WorkboxError_mjs, getFriendlyURL_mjs) {
                          'use strict';
                        
                          try {
                            self['workbox:routing:4.3.1'] && _();
                        Severity: Minor
                        Found in public/javascripts/workbox/workbox-routing.dev.js - 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

                        Severity
                        Category
                        Status
                        Source
                        Language