diaspora/diaspora

View on GitHub

Showing 4,486 of 4,486 total issues

Assignment Branch Condition size for create is too high. [36.62/20]
Open

  def create
    emails = inviter_params[:emails].split(",").map(&:strip).uniq

    valid_emails, invalid_emails = emails.partition {|email| valid_email?(email) }

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Function textFormatter has 88 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  app.helpers.textFormatter = function(text, mentions) {
    mentions = mentions ? mentions : [];

    var md = window.markdownit({
      breaks:      true,
Severity: Major
Found in app/assets/javascripts/app/helpers/text_formatter.js - About 3 hrs to fix

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

      presenter : function() {
        return _.extend(this.defaultPresenter(), {
          authorIsCurrentUser :app.currentUser.isAuthorOf(this.model),
          showPost : this.showPost(),
          text : app.helpers.textFormatter(this.model.get("text"), this.model.get("mentioned_people"))
    app/assets/javascripts/app/views/post_view.js on lines 4..10

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

    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 2 locations. Consider refactoring.
    Open

      presenter : function() {
        return _.extend(this.defaultPresenter(), {
          authorIsCurrentUser : app.currentUser.isAuthorOf(this.model), 
          showPost : this.showPost(),
          text : app.helpers.textFormatter(this.model.get("text"), this.model.get("mentioned_people"))
    Severity: Major
    Found in app/assets/javascripts/app/views/post_view.js and 1 other location - About 3 hrs to fix
    app/assets/javascripts/app/views/single-post-viewer/single_post_content_view.js on lines 47..53

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

    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

    Assignment Branch Condition size for index is too high. [35.16/20]
    Open

      def index
        @post_type = :photos
        @person = Person.find_by_guid(params[:person_id])
        authenticate_user! if @person.try(:remote?) && !user_signed_in?
        @presenter = PersonPresenter.new(@person, current_user)

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Assignment Branch Condition size for index is too high. [35.19/20]
    Open

      def index
        if params[:q] && params[:q].length > 1
          params[:q].gsub!("#", "")
          params[:limit] = !params[:limit].blank? ? params[:limit].to_i : 10
          @tags = ActsAsTaggableOn::Tag.autocomplete(params[:q]).limit(params[:limit] - 1)
    Severity: Minor
    Found in app/controllers/tags_controller.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    File receive.rb has 306 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Diaspora
      module Federation
        module Receive
          extend Diaspora::Logging
    
    
    Severity: Minor
    Found in lib/diaspora/federation/receive.rb - About 3 hrs to fix

      Class AuthorizationsController has 28 methods (exceeds 20 allowed). Consider refactoring.
      Open

          class AuthorizationsController < ApplicationController
            rescue_from Rack::OAuth2::Server::Authorize::BadRequest do |e|
              logger.info e.backtrace[0, 10].join("\n")
              error, _description = e.message.split(" :: ")
              handle_params_error(error, "The request was malformed: please double check the client id and redirect uri.")
      Severity: Minor
      Found in app/controllers/api/openid_connect/authorizations_controller.rb - About 3 hrs to fix

        Class PostPresenter has 28 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class PostPresenter < BasePresenter
          include PostsHelper
          include MetaDataHelper
        
          attr_accessor :post
        Severity: Minor
        Found in app/presenters/post_presenter.rb - About 3 hrs to fix

          Assignment Branch Condition size for read_all is too high. [34.19/20]
          Open

            def read_all
              current_type = types[params[:type]]
              notifications = Notification.where(recipient_id: current_user.id, unread: true)
              notifications = notifications.where(type: current_type) if params[:type]
              notifications.update_all(unread: false)

          This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

          Assignment Branch Condition size for index is too high. [34.29/20]
          Open

            def index
              @visibilities = ConversationVisibility.includes(:conversation)
                                                    .order("conversations.updated_at DESC")
                                                    .where(person_id: current_user.person_id)
                                                    .paginate(page: params[:page], per_page: 15)

          This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

          Function createUploader has 80 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function createUploader(){
             var aspectIds = gon.preloads.aspect_ids;
          
            new qq.FineUploaderBasic({
              element: document.getElementById("file-upload-publisher"),
          Severity: Major
          Found in app/assets/javascripts/mobile/mobile_file_uploader.js - About 3 hrs to fix

            Assignment Branch Condition size for perform is too high. [33.36/20]
            Open

                def perform
                  return User.none unless valid?
            
                  users = User.arel_table
                  people = Person.arel_table

            This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

            Assignment Branch Condition size for create is too high. [33.38/20]
            Open

              def create
                # Contacts autocomplete does not work the same way on mobile and desktop
                # Mobile returns contact ids array while desktop returns person id
                # This will have to be removed when mobile autocomplete is ported to Typeahead
                recipients_param, column = [%i(contact_ids id), %i(person_ids person_id)].find {|param, _| params[param].present? }

            This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

            Assignment Branch Condition size for destroy_reported_item is too high. [32.39/20]
            Open

              def destroy_reported_item
                case item
                when Post
                  if item.author.local?
                    item.author.owner.retract(item)
            Severity: Minor
            Found in app/models/report.rb by rubocop

            This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

            Assignment Branch Condition size for destroy is too high. [32.45/20]
            Open

              def destroy
                if params[:user] && params[:user][:current_password] && current_user.valid_password?(params[:user][:current_password])
                  current_user.close_account!
                  sign_out current_user
                  redirect_to(new_user_session_path(format: request[:format]), notice: I18n.t("users.destroy.success"))
            Severity: Minor
            Found in app/controllers/users_controller.rb by rubocop

            This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

            Assignment Branch Condition size for destroy is too high. [32.63/20]
            Open

              def destroy
                @aspect = current_user.aspects.where(id: params[:id]).first
            
                begin
                  if current_user.auto_follow_back && @aspect.id == current_user.auto_follow_back_aspect.id

            This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

            Assignment Branch Condition size for copy_hidden_share_visibilities_to_users is too high. [32.45/20]
            Open

              def self.copy_hidden_share_visibilities_to_users(only_recent = false)
                query = ShareVisibility.where(:hidden => true).includes(:contact => :user)
                query = query.where('share_visibilities.updated_at > ?', RECENT.weeks.ago) if only_recent
                count = query.count
                puts "Updating #{count} records in batches of 1000..."
            Severity: Minor
            Found in lib/share_visibility_converter.rb by rubocop

            This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

            Function bookmarklet has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

            var bookmarklet = function(url, width, height, opts) {
              var maxLen = 1900; // max GET request length, see #3076
              var maxTitleLen = 128; // cut title after this length, if too long
            
              // calculate popup dimensions & placement
            Severity: Minor
            Found in app/assets/javascripts/bookmarklet.js - 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

            Publisher has 25 functions (exceeds 20 allowed). Consider refactoring.
            Open

            app.views.Publisher = Backbone.View.extend({
            
              el : "#publisher",
            
              events : {
            Severity: Minor
            Found in app/assets/javascripts/app/views/publisher_view.js - About 2 hrs to fix
              Severity
              Category
              Status
              Source
              Language