ArtOfCode-/qpixel

View on GitHub

Showing 164 of 164 total issues

Method article_ad has 68 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def article_ad(article)
    ad = Rails.cache.fetch "posts/#{article.id}/ad", expires_in: 60.minutes do
      ad = Image.new(600, 500)
      ad.background_color = 'white'

Severity: Major
Found in app/controllers/advertisement_controller.rb - About 2 hrs to fix

    Function getCaretCoordinates has 67 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      function getCaretCoordinates(element, position, options) {
        if (!isBrowser) {
          throw new Error('textarea-caret-position#getCaretCoordinates should only be called in a browser');
        }
    
    
    Severity: Major
    Found in public/assets/community/judaism.js - About 2 hrs to fix

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

              else if (e.key === 'k') {
                  if (_CodidactKeyboard.selectedItem == null) _CodidactKeyboard.selectedItem = $("[data-ckb-list-item]:first-of-type")[0];
                  else {
                      _CodidactKeyboard.selectedItem = $(_CodidactKeyboard.selectedItem).nextAll('[data-ckb-list-item]')[0] || _CodidactKeyboard.selectedItem;
                  }
      Severity: Major
      Found in app/assets/javascripts/keyboard_tools.js and 1 other location - About 2 hrs to fix
      app/assets/javascripts/keyboard_tools.js on lines 128..163

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

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

              else if (e.key === 'j') {
                  if (_CodidactKeyboard.selectedItem == null) _CodidactKeyboard.selectedItem = $("[data-ckb-list-item]:first-of-type")[0];
                  else {
                      _CodidactKeyboard.selectedItem = $(_CodidactKeyboard.selectedItem).prevAll('[data-ckb-list-item]')[0] || _CodidactKeyboard.selectedItem;
                  }
      Severity: Major
      Found in app/assets/javascripts/keyboard_tools.js and 1 other location - About 2 hrs to fix
      app/assets/javascripts/keyboard_tools.js on lines 121..163

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

      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

      Method community has 60 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def community
          ad = Rails.cache.fetch "#{RequestContext.community_id}/community_ad", expires_in: 60.minutes do
            ad = Image.new(600, 500)
            ad.background_color = 'white'
      
      
      Severity: Major
      Found in app/controllers/advertisement_controller.rb - About 2 hrs to fix

        Class UsersController has 22 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class UsersController < ApplicationController
          include Devise::Controllers::Rememberable
        
          before_action :authenticate_user!, only: [:edit_profile, :update_profile, :stack_redirect, :transfer_se_content,
                                                    :qr_login_code, :me]
        Severity: Minor
        Found in app/controllers/users_controller.rb - About 2 hrs to fix

          Method update has 57 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def update
              before = { body: @post.body_markdown, title: @post.title, tags: @post.tags }
              after_tags = if @post_type.has_category?
                             Tag.where(tag_set_id: @post.category.tag_set_id, name: params[:post][:tags_cache])
                           end
          Severity: Major
          Found in app/controllers/posts_controller.rb - About 2 hrs to fix

            Class User has 21 methods (exceeds 20 allowed). Consider refactoring.
            Open

            class User < ApplicationRecord
              # Include default devise modules. Others available are:
              # :confirmable, :lockable, :timeoutable and :omniauthable
              devise :database_authenticatable, :registerable, :confirmable,
                     :recoverable, :rememberable, :trackable, :validatable,
            Severity: Minor
            Found in app/models/user.rb - About 2 hrs to fix

              Class ApplicationController has 21 methods (exceeds 20 allowed). Consider refactoring.
              Open

              class ApplicationController < ActionController::Base
                # Prevent CSRF attacks by raising an exception.
                # For APIs, you may want to use :null_session instead.
                protect_from_forgery with: :exception
                before_action :configure_permitted_parameters, if: :devise_controller?
              Severity: Minor
              Found in app/controllers/application_controller.rb - About 2 hrs to fix

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

                  def create
                    @post_type = PostType.find(params[:post][:post_type_id])
                    @parent = Post.where(id: params[:parent]).first
                    @category = if @post_type.has_category
                                  if params[:post][:category_id].present?
                Severity: Major
                Found in app/controllers/posts_controller.rb - About 2 hrs to fix

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

                    $("a.show-all-flags-dialog-link").bind("click", (ev) => {
                      ev.preventDefault();
                      const self = $(ev.target);
                      self.parents(".post--body").find(".js-flags").toggleClass("is-active");
                    });
                  Severity: Major
                  Found in app/assets/javascripts/application.js and 1 other location - About 1 hr to fix
                  app/assets/javascripts/application.js on lines 19..23

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

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

                        if question.title.length > 60
                          title.pointsize = 35
                          wrap_text(helpers.do_rtl_witchcraft(question.title), 500, 35).split("\n").each do |line|
                            title.annotate ad, 500, 100, 50, 135 + position * 55, line do
                              self.fill = '#333333'
                  Severity: Major
                  Found in app/controllers/advertisement_controller.rb and 1 other location - About 1 hr to fix
                  app/controllers/advertisement_controller.rb on lines 349..363

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

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

                    posts, posts_file = DumpImport.do_xml_transform(domain, 'Posts', @options) do |rows|
                      ids = rows.map { |r| r['id'].to_s }
                      missing = required_ids.select { |e| !ids.include? e }
                      excess = ids.select { |e| !required_ids.include? e }
                      $logger.info "#{ids.size} post rows in dump, #{missing.size} to get from API, #{excess.size} excess"
                  Severity: Major
                  Found in scripts/import/stack_import.rb and 1 other location - About 1 hr to fix
                  scripts/import/stack_import.rb on lines 171..183

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

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

                    users, users_file = DumpImport.do_xml_transform(domain, 'Users', @options) do |rows|
                      ids = rows.map { |r| r['id'].to_s }
                      missing = required_user_ids.select { |e| !ids.include? e }
                      excess = ids.select { |e| !required_user_ids.include? e }
                      $logger.info "#{ids.size} user rows in dump, #{missing.size} to get from API, #{excess.size} excess"
                  Severity: Major
                  Found in scripts/import/stack_import.rb and 1 other location - About 1 hr to fix
                  scripts/import/stack_import.rb on lines 158..170

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

                  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

                    const replaceSelection = ($field, text) => {
                      const prev = $field.val();
                      $field.val(prev.substring(0, $field[0].selectionStart) + text + prev.substring($field[0].selectionEnd));
                    };
                  Severity: Major
                  Found in app/assets/javascripts/markdown.js and 1 other location - About 1 hr to fix
                  app/assets/javascripts/qpixel_api.js on lines 150..153

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

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

                        if article.title.length > 60
                          title.pointsize = 35
                          wrap_text(helpers.do_rtl_witchcraft(article.title), 500, 35).split("\n").each do |line|
                            title.annotate ad, 500, 100, 50, 135 + position * 55, line do
                              self.fill = '#333333'
                  Severity: Major
                  Found in app/controllers/advertisement_controller.rb and 1 other location - About 1 hr to fix
                  app/controllers/advertisement_controller.rb on lines 272..286

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

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

                    $("a.flag-dialog-link").bind("click", (ev) => {
                      ev.preventDefault();
                      const self = $(ev.target);
                      self.parents(".post--body").find(".js-flag-box").toggleClass("is-active");
                    });
                  Severity: Major
                  Found in app/assets/javascripts/application.js and 1 other location - About 1 hr to fix
                  app/assets/javascripts/application.js on lines 117..121

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

                  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

                    replaceSelection: ($field, text) => {
                      const prev = $field.val();
                      $field.val(prev.substring(0, $field[0].selectionStart) + text + prev.substring($field[0].selectionEnd));
                    },
                  Severity: Major
                  Found in app/assets/javascripts/qpixel_api.js and 1 other location - About 1 hr to fix
                  app/assets/javascripts/markdown.js on lines 13..16

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

                  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

                  Method recalc_privilege has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def recalc_privilege(internal_id, sandbox: false)
                      # Do not recalculate privileges already granted
                      return true if privilege?(internal_id, ignore_suspension: true, ignore_mod: true)
                  
                      priv = Ability.where(internal_id: internal_id).first
                  Severity: Minor
                  Found in app/models/community_user.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

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

                        else if (count > 0.75 * max) {
                          $el.removeClass('has-color-red-500').addClass('has-color-yellow-700');
                          const $button = $el.parents('form').find('input[type="submit"]');
                          if ($button) {
                            $button.attr('disabled', false).removeClass('is-muted');
                  Severity: Major
                  Found in app/assets/javascripts/character_count.js and 1 other location - About 1 hr to fix
                  app/assets/javascripts/character_count.js on lines 15..35

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

                  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

                  Severity
                  Category
                  Status
                  Source
                  Language