sharetribe/sharetribe

View on GitHub
app/assets/javascripts/listing_form.js

Summary

Maintainability
F
3 days
Test Coverage

File listing_form.js has 400 lines of code (exceeds 250 allowed). Consider refactoring.
Open

window.ST = window.ST || {};

(function(module) {
  /* global disable_submit_button */
  /* global set_textarea_maxlength */
Severity: Minor
Found in app/assets/javascripts/listing_form.js - About 5 hrs to fix

    Function initialize_new_listing_form has 114 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      module.initialize_new_listing_form = function(
        fileDefaultText,
        fileBtnText,
        locale,
        share_type_message,
    Severity: Major
    Found in app/assets/javascripts/listing_form.js - About 4 hrs to fix

      Function initialize_new_listing_form has 15 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          fileDefaultText,
          fileBtnText,
          locale,
          share_type_message,
          date_message,
      Severity: Major
      Found in app/assets/javascripts/listing_form.js - About 1 hr to fix

        Function should_show_menu_for has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          function should_show_menu_for(attribute, selected_attributes, attribute_array) {
            if (attribute_selected(attribute, selected_attributes)) {
              return false;
            } else if (attribute == "category") {
              if (attribute_array.length < 2) {
        Severity: Minor
        Found in app/assets/javascripts/listing_form.js - About 1 hr to fix

          Function initialize_edit_listing_form_selectors has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            module.initialize_edit_listing_form_selectors = function(locale, attribute_array, listing_form_menu_titles, category, subcategory, listing_shape, id) {
              var ordered_attributes = ["category", "subcategory", "listing_shape"];
          
              // Selected values (string or null required)
              category = category ? "" + category : null;
          Severity: Minor
          Found in app/assets/javascripts/listing_form.js - About 1 hr to fix

            Function initialize_edit_listing_form_selectors has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              module.initialize_edit_listing_form_selectors = function(locale, attribute_array, listing_form_menu_titles, category, subcategory, listing_shape, id) {
            Severity: Major
            Found in app/assets/javascripts/listing_form.js - About 50 mins to fix

              Avoid deeply nested control flow statements.
              Open

                        if (subcategories.length == 1) {
                          selected_attributes["subcategory"] = subcategories[0]["id"];
                        }
              Severity: Major
              Found in app/assets/javascripts/listing_form.js - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                        if (attribute_selected("subcategory", selected_attributes)) {
                          listing_shapes = get_listing_shapes_for_subcategory(selected_attributes["category"], selected_attributes["subcategory"], attribute_array);
                        } else {
                          listing_shapes = get_listing_shapes_for_category(selected_attributes["category"], attribute_array);
                        }
                Severity: Major
                Found in app/assets/javascripts/listing_form.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                          if (listing_shapes.length === 1) {
                            selected_attributes["listing_shape"] = listing_shapes[0]["id"];
                          }
                  Severity: Major
                  Found in app/assets/javascripts/listing_form.js - About 45 mins to fix

                    Function select_listing_form_menu_link has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                      function select_listing_form_menu_link(link, locale, attribute_array, listing_form_menu_titles, ordered_attributes, selected_attributes) {
                    Severity: Minor
                    Found in app/assets/javascripts/listing_form.js - About 45 mins to fix

                      Function update_listing_form_view has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                        function update_listing_form_view(locale, attribute_array, listing_form_menu_titles, ordered_attributes, selected_attributes) {
                      Severity: Minor
                      Found in app/assets/javascripts/listing_form.js - About 35 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                  return true;
                        Severity: Major
                        Found in app/assets/javascripts/listing_form.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                  return (listing_shapes.length > 1);
                          Severity: Major
                          Found in app/assets/javascripts/listing_form.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                      return false;
                            Severity: Major
                            Found in app/assets/javascripts/listing_form.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                      return false;
                              Severity: Major
                              Found in app/assets/javascripts/listing_form.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                        return false;
                                Severity: Major
                                Found in app/assets/javascripts/listing_form.js - About 30 mins to fix

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

                                        if (attribute_array.length < 2) {
                                          // If there is exactly 1 category, it should be marked automatically as selected,
                                          // without showing the form.
                                          if (attribute_array.length == 1) {
                                            selected_attributes["category"] = attribute_array[0]["id"];
                                  Severity: Major
                                  Found in app/assets/javascripts/listing_form.js and 1 other location - About 1 hr to fix
                                  app/assets/javascripts/listing_form.js on lines 116..125

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

                                  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 (subcategories.length < 2) {
                                            // If there is exactly 1 subcategory, it should be marked automatically as selected,
                                            // without showing the form.
                                            if (subcategories.length == 1) {
                                              selected_attributes["subcategory"] = subcategories[0]["id"];
                                  Severity: Major
                                  Found in app/assets/javascripts/listing_form.js and 1 other location - About 1 hr to fix
                                  app/assets/javascripts/listing_form.js on lines 101..110

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

                                  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

                                      $('#help_valid_until_link').click(function() { $('#help_valid_until').lightbox_me({centered: true, zIndex: 1000000}); });
                                  Severity: Minor
                                  Found in app/assets/javascripts/listing_form.js and 1 other location - About 35 mins to fix
                                  app/assets/javascripts/kassi.js on lines 325..325

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

                                  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

                                  There are no issues that match your filters.

                                  Category
                                  Status