discourse/discourse

View on GitHub

Showing 3,817 of 3,817 total issues

Method default_results has a Cognitive Complexity of 84 (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

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

module.exports = async function() {
  return {
    useYarn: true,
    scenarios: [
      {
Severity: Major
Found in app/assets/javascripts/pretty-text/config/ember-try.js and 2 other locations - About 1 day to fix
app/assets/javascripts/discourse-common/config/ember-try.js on lines 5..89
app/assets/javascripts/select-kit/config/ember-try.js on lines 5..89

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 301.

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

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

module.exports = async function() {
  return {
    useYarn: true,
    scenarios: [
      {
Severity: Major
Found in app/assets/javascripts/select-kit/config/ember-try.js and 2 other locations - About 1 day to fix
app/assets/javascripts/discourse-common/config/ember-try.js on lines 5..89
app/assets/javascripts/pretty-text/config/ember-try.js on lines 5..89

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 301.

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

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

module.exports = async function() {
  return {
    useYarn: true,
    scenarios: [
      {
Severity: Major
Found in app/assets/javascripts/discourse-common/config/ember-try.js and 2 other locations - About 1 day to fix
app/assets/javascripts/pretty-text/config/ember-try.js on lines 5..89
app/assets/javascripts/select-kit/config/ember-try.js on lines 5..89

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 301.

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

Function expiration has a Cognitive Complexity of 83 (exceeds 5 allowed). Consider refactoring.
Open

this.workbox.expiration = (function (exports, DBWrapper_mjs, deleteDatabase_mjs, WorkboxError_mjs, assert_mjs, logger_mjs, cacheNames_mjs, getFriendlyURL_mjs, registerQuotaErrorCallback_mjs) {
  'use strict';

  try {
    self['workbox:expiration:4.3.1'] && _();
Severity: Minor
Found in public/javascripts/workbox/workbox-expiration.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

File topic.js has 718 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import getURL from "discourse-common/lib/get-url";
import I18n from "I18n";
import EmberObject from "@ember/object";
import { not, notEmpty, equal, and, or } from "@ember/object/computed";
import { ajax } from "discourse/lib/ajax";
Severity: Major
Found in app/assets/javascripts/discourse/app/models/topic.js - About 1 day to fix

    Class PostSerializer has 87 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class PostSerializer < BasicPostSerializer
    
      # To pass in additional information we might need
      INSTANCE_VARS ||= [
        :parent_post,
    Severity: Major
    Found in app/serializers/post_serializer.rb - About 1 day to fix

      Class Instance has 87 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class Plugin::Instance
      
        attr_accessor :path, :metadata
        attr_reader :admin_route
      
      
      Severity: Major
      Found in lib/plugin/instance.rb - About 1 day to fix

        File category.rb has 702 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        class Category < ActiveRecord::Base
          RESERVED_SLUGS = [
            'none'
          ]
        
        
        Severity: Major
        Found in app/models/category.rb - About 1 day to fix

          File staff_action_logger.rb has 693 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          class StaffActionLogger
          
            def self.base_attrs
              [:topic_id, :post_id, :context, :subject, :ip_address, :previous_value, :new_value]
            end
          Severity: Major
          Found in app/services/staff_action_logger.rb - About 1 day to fix

            Class Post has 82 methods (exceeds 20 allowed). Consider refactoring.
            Open

            class Post < ActiveRecord::Base
              include RateLimiter::OnCreateRecord
              include Trashable
              include Searchable
              include HasCustomFields
            Severity: Major
            Found in app/models/post.rb - About 1 day to fix

              Class Receiver has 82 methods (exceeds 20 allowed). Consider refactoring.
              Open

                class Receiver
                  # If you add a new error, you need to
                  #   * add it to Email::Processor#handle_failure()
                  #   * add text to server.en.yml (parent key: "emails.incoming.errors")
                  class ProcessingError              < StandardError; end
              Severity: Major
              Found in lib/email/receiver.rb - About 1 day to fix

                Function applyOnebox has a Cognitive Complexity of 76 (exceeds 5 allowed). Consider refactoring.
                Open

                function applyOnebox(state, silent) {
                  if (silent || !state.tokens) {
                    return;
                  }
                
                

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

                    def execute(args)
                      post_id = args[:post_id]
                      raise Discourse::InvalidParameters.new(:post_id) unless post_id.present?
                
                      post = Post.find_by(id: post_id)
                Severity: Minor
                Found in app/jobs/regular/pull_hotlinked_images.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 discourse.rb has 668 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: Major
                Found in lib/discourse.rb - About 1 day to fix

                  Function expiration has 300 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  this.workbox.expiration = (function (exports, DBWrapper_mjs, deleteDatabase_mjs, WorkboxError_mjs, assert_mjs, logger_mjs, cacheNames_mjs, getFriendlyURL_mjs, registerQuotaErrorCallback_mjs) {
                    'use strict';
                  
                    try {
                      self['workbox:expiration:4.3.1'] && _();
                  Severity: Major
                  Found in public/javascripts/workbox/workbox-expiration.dev.js - About 1 day to fix

                    Method perform has a Cognitive Complexity of 75 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def perform
                        OptimizedImage.downsize(path, path, "#{@max_pixels}@", filename: upload.original_filename)
                        sha1 = Upload.generate_digest(path)
                    
                        if sha1 == upload.sha1
                    Severity: Minor
                    Found in lib/shrink_uploaded_image.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 application_controller.rb has 661 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    require 'current_user'
                    
                    class ApplicationController < ActionController::Base
                      include CurrentUser
                      include CanonicalURL::ControllerExtensions
                    Severity: Major
                    Found in app/controllers/application_controller.rb - About 1 day to fix

                      Method post_process_oneboxes has a Cognitive Complexity of 74 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def post_process_oneboxes
                          limit = SiteSetting.max_oneboxes_per_post
                          oneboxes = {}
                          inlineOneboxes = {}
                      
                      
                      Severity: Minor
                      Found in lib/cooked_post_processor.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

                      Class StaffActionLogger has 78 methods (exceeds 20 allowed). Consider refactoring.
                      Open

                      class StaffActionLogger
                      
                        def self.base_attrs
                          [:topic_id, :post_id, :context, :subject, :ip_address, :previous_value, :new_value]
                        end
                      Severity: Major
                      Found in app/services/staff_action_logger.rb - About 1 day to fix
                        Severity
                        Category
                        Status
                        Source
                        Language