ArtOfCode-/qpixel

View on GitHub

Showing 164 of 164 total issues

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

      if (count > max) {
        $el.removeClass('has-color-yellow-700').addClass('has-color-red-500');
        const $button = $el.parents('form').find('input[type="submit"]');
        if ($button) {
          $button.attr('disabled', true).addClass('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 22..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

Method posts has 46 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def posts(ids)
    groups = ids.in_groups_of(100).map(&:compact)
    posts = []
    groups.each do |group|
      posts = posts.concat request("https://api.stackexchange.com/2.2/posts/#{group.join(';')}",
Severity: Minor
Found in scripts/import/api_import.rb - About 1 hr to fix

    Method codidact has 46 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def codidact
        ad = Rails.cache.fetch 'codidact_ad', expires_in: 60.minutes do
          ad = Image.new(600, 500)
          ad.background_color = 'white'
    
    
    Severity: Minor
    Found in app/controllers/advertisement_controller.rb - About 1 hr to fix

      Function gotoMenu has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          function gotoMenu(e) {
              if (e.key === 'm') {
                  window.location.href = '/';
              }
              else if (e.key === 'u') {
      Severity: Minor
      Found in app/assets/javascripts/keyboard_tools.js - About 1 hr to fix

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

            firstAnswer: function () {
                $(".js-good-answer").removeClass("hide");
                $(".js-answer-counter").text("1 answer");
                $(".step-1").addClass("hide");
                $(".step-2").removeClass("hide");
        Severity: Major
        Found in app/assets/javascripts/tour.js and 1 other location - About 1 hr to fix
        app/assets/javascripts/tour.js on lines 18..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 70.

        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

            secondAnswer: function () {
                $(".js-bad-answer").removeClass("hide");
                $(".js-answer-counter").text("2 answers");
                $(".step-4").addClass("hide");
                $(".step-5").removeClass("hide");
        Severity: Major
        Found in app/assets/javascripts/tour.js and 1 other location - About 1 hr to fix
        app/assets/javascripts/tour.js on lines 2..7

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

        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 === 'g') {
                    _CodidactKeyboard.dialog('Go to ...\n' +
                        '=========\n' +
                        'm  Main page\n' +
                        'u  User list\n' +
        Severity: Major
        Found in app/assets/javascripts/keyboard_tools.js and 1 other location - About 1 hr to fix
        app/assets/javascripts/keyboard_tools.js on lines 139..151

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

        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 (_CodidactKeyboard.selectedItemData.type === "post") {
                        _CodidactKeyboard.dialog('Use tool ...\n' +
                            '============\n' +
                            'f  Flag\n' +
                            'e  Edit\n' +
        Severity: Major
        Found in app/assets/javascripts/keyboard_tools.js and 1 other location - About 1 hr to fix
        app/assets/javascripts/keyboard_tools.js on lines 108..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 68.

        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 qualifiers_to_sql has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def qualifiers_to_sql(qualifiers)
            valid_value = {
              date: /^[<>=]{0,2}\d+(?:s|m|h|d|w|mo|y)?$/,
              numeric: /^[<>=]{0,2}\d+$/
            }
        Severity: Minor
        Found in app/helpers/search_helper.rb - About 1 hr to fix

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

            def create
              @post = Post.find(params[:comment][:post_id])
              if @post.comments_disabled && !current_user.is_moderator && !current_user.is_admin
                render json: { status: 'failed', message: 'Comments have been disabled on this post.' }, status: :forbidden
                return
          Severity: Minor
          Found in app/controllers/comments_controller.rb - About 1 hr to fix

            Function toolsMenu has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                function toolsMenu(e) {
                    if (e.key === 'e') {
                        window.location.href = $(_CodidactKeyboard.selectedItem).find('.tools--item i.fa.fa-pencil-alt').parent().attr("href");
                    }
                    else if (e.key === 'h') {
            Severity: Minor
            Found in app/assets/javascripts/keyboard_tools.js - About 1 hr to fix

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

                  if (resp.status !== 200 || data.status !== 'success') {
                    QPixel.createNotification('danger', `<strong>Failed:</strong> ${data.message}`);
                  }
                  else {
                    location.reload();
              Severity: Major
              Found in app/assets/javascripts/users.js and 3 other locations - About 1 hr to fix
              app/assets/javascripts/users.js on lines 16..21
              app/assets/javascripts/users.js on lines 33..38
              app/assets/javascripts/users.js on lines 51..56

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

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

                  if (resp.status !== 200 || data.status !== 'success') {
                    QPixel.createNotification('danger', `<strong>Failed:</strong> ${data.message}`);
                  }
                  else {
                    location.reload();
              Severity: Major
              Found in app/assets/javascripts/users.js and 3 other locations - About 1 hr to fix
              app/assets/javascripts/users.js on lines 33..38
              app/assets/javascripts/users.js on lines 51..56
              app/assets/javascripts/users.js on lines 74..79

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

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

                  if (resp.status !== 200 || data.status !== 'success') {
                    QPixel.createNotification('danger', `<strong>Failed:</strong> ${data.message}`);
                  }
                  else {
                    location.reload();
              Severity: Major
              Found in app/assets/javascripts/users.js and 3 other locations - About 1 hr to fix
              app/assets/javascripts/users.js on lines 16..21
              app/assets/javascripts/users.js on lines 33..38
              app/assets/javascripts/users.js on lines 74..79

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

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

                  if (resp.status !== 200 || data.status !== 'success') {
                    QPixel.createNotification('danger', `<strong>Failed:</strong> ${data.message}`);
                  }
                  else {
                    location.reload();
              Severity: Major
              Found in app/assets/javascripts/users.js and 3 other locations - About 1 hr to fix
              app/assets/javascripts/users.js on lines 16..21
              app/assets/javascripts/users.js on lines 51..56
              app/assets/javascripts/users.js on lines 74..79

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

              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 do_xml_transform has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def self.do_xml_transform(site_domain, data_type, options)
                  dump_path = options.path
                  community_id = options.community
                  category_id = options.category
              
              
              Severity: Minor
              Found in scripts/import/dump_import.rb - About 1 hr to fix

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

                            for (let i = 0; i < data.length; i++) {
                                const entry = data[i];
                                string_response += (i + 1) + "  " + entry[0] + "\n"
                            }
                Severity: Major
                Found in app/assets/javascripts/keyboard_tools.js and 1 other location - About 1 hr to fix
                app/assets/javascripts/keyboard_tools.js on lines 188..191

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

                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

                            for (let i = 0; i < data.length; i++) {
                                const entry = data[i];
                                string_response += (i + 1) + "  " + entry[0] + "\n"
                            }
                Severity: Major
                Found in app/assets/javascripts/keyboard_tools.js and 1 other location - About 1 hr to fix
                app/assets/javascripts/keyboard_tools.js on lines 204..207

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

                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 run has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def run
                    # We only want questions and answers; nuke anything that isn't
                    query "DELETE FROM #{table 'posts'} WHERE #{column 'post_type_id'} NOT IN (1, 2)"
                
                    # Change post user IDs to SE account IDs so we can re-associate them with users later
                Severity: Minor
                Found in scripts/import/database_import.rb - About 1 hr to fix

                  Method mod_privilege_action has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def mod_privilege_action
                      ability = Ability.find_by internal_id: params[:ability]
                      return not_found if ability.internal_id == 'mod'
                  
                      ua = @user.community_user.privilege(ability.internal_id)
                  Severity: Minor
                  Found in app/controllers/users_controller.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

                  Severity
                  Category
                  Status
                  Source
                  Language