ClusterLabs/hawk

View on GitHub

Showing 2,379 of 2,379 total issues

Method verify has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

  def verify(params)
    @params = params
    @actions = []
    @errors = []
    CrmScript.run ["verify", @name, params], nil do |action, err|
Severity: Minor
Found in hawk/app/models/wizard.rb - About 3 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

Cyclomatic complexity for update_resource_state is too high. [25/6]
Open

  def update_resource_state(resource, node, instance, state, substate, failed_ops)
    # m/s slave state hack (*sigh*)
    state = :slave if resource[:is_ms] && state == :started
    instances = resource[:instances]

Severity: Minor
Found in hawk/app/models/cib.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Assignment Branch Condition size for build_scriptparams is too high. [34.55/15]
Open

  def build_scriptparams(params)
    sp = build_stepmap({}, @wizard)
    id = @wizard.id
    params.select { |k, _v| k.start_with?("#{id}.") }.each do |k, v|
      next if v.empty?

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

Method has too many lines. [49/30]
Open

  def result
    case params[:file]
    when "info"
      send_data File.new("#{Rails.root}/tmp/sim.info").read,
                type: "text/plain", disposition: :inline

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

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

    element.on('click', '#fl-up', function(e) {
      e.preventDefault();
      var ilevel = $(this).closest('.fencing-level').data('sort-index');
      var item = editor.topology[ilevel];
      editor.topology.splice(ilevel, 1)
Severity: Major
Found in hawk/app/assets/javascripts/module/fencing.js and 1 other location - About 3 hrs to fix
hawk/app/assets/javascripts/module/fencing.js on lines 151..167

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

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

  function executeNodeSelectionAction(context, message, defaultmsg) {
    var html = [
      '<div class="modal fade" id="nodeSelectionDialog" role="dialog" tabindex="-1" aria-hidden="true">',
      '<div class="modal-dialog">',
      '<div class="modal-content">',
Severity: Major
Found in hawk/app/assets/javascripts/module/resources.js - About 3 hrs to fix

    Assignment Branch Condition size for update is too high. [33/15]
    Open

      def update
        unless self.class.exists?(self.id, self.class.cib_type_write)
          errors.add :base, _("The ID \"%{id}\" does not exist") % { id: self.id }
          return false
        end
    Severity: Minor
    Found in hawk/app/models/group.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 transitions is too high. [33.24/15]
    Open

      def transitions(hb_report)
        # TODO(fix this)
        # Have to blow this away if it exists (i.e. is a cached report), else
        # prior cibadmin calls on individual PE inputs will have wrecked their mtimes.
        # FileUtils.remove_entry_secure(hb_report.path) if File.exist?(hb_report.path)
    Severity: Minor
    Found in hawk/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

    Method has too many lines. [48/30]
    Open

      def get_resource(elem, is_managed = true, maintenance = false, clone_max = nil, is_ms = false)
        res = {
          id: elem.attributes['id'],
          object_type: elem.name,
          attributes: {},
    Severity: Minor
    Found in hawk/app/models/cib.rb by rubocop

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Method has too many lines. [48/30]
    Open

      def fix_resource_states(rsclist)
        prio = {
          unknown: 0,
          stopped: 1,
          started: 2,
    Severity: Minor
    Found in hawk/app/models/cib.rb by rubocop

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Assignment Branch Condition size for update is too high. [33.3/15]
    Open

      def update
        normalize_params! params[:alert].permit!
        @title = _("Edit Alert")
    
        if params[:revert]

    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.6/15]
    Open

      def create
        normalize_params! params[:order].permit!
        @title = _("Create Order")
    
        @order = Order.new params[:order].permit!

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

      function RecipientList(el, options) {
        this.$el = $(el);
    
        // defined actions: [{name, interval, ...}]
        this.values = this.$el.data('recipients');
    Severity: Major
    Found in hawk/app/assets/javascripts/module/recipientlist.js - About 3 hrs to fix

      Class Cib has 30 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class Cib
        extend ActiveModel::Naming
        include ActiveModel::Conversion
        include FastGettext::Translation
        include Rails.application.routes.url_helpers # needed for routes
      Severity: Minor
      Found in hawk/app/models/cib.rb - About 3 hrs to fix

        Assignment Branch Condition size for shell_syntax is too high. [32.25/15]
        Open

          def shell_syntax
            [].tap do |cmd|
              # TODO(must): Ensure clazz, provider and type are sanitized
              cmd.push "primitive #{id}"
        
        
        Severity: Minor
        Found in hawk/app/models/primitive.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 graph is too high. [32.63/15]
        Open

          def graph(hb_report, path, format = :svg)
            tpath = Pathname.new(hb_report.path).join(path)
            require "tempfile"
            tmpfile = Tempfile.new("hawk_dot")
            tmpfile.close
        Severity: Minor
        Found in hawk/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 shell_syntax is too high. [32.25/15]
        Open

          def shell_syntax
            [].tap do |cmd|
              # TODO(must): Ensure clazz, provider and type are sanitized
              cmd.push "rsc_template #{id}"
        
        
        Severity: Minor
        Found in hawk/app/models/template.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 window_transition is too high. [32.7/15]
        Open

          def window_transition
            if last_transition > 10
              case
              when current_transition <= (first_transition + 5)
                start = first_transition

        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 validate is too high. [32.56/15]
        Open

          def validate(record)  
            unless record.score.blank?
              record.score.strip!
              unless [
                "mandatory",

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

                  success: function(data) {
                    if (data == null || !("resource_agent" in data)) {
                      data = { resource_agent: {
                        shortdesc: agent,
                        longdesc: "",
        Severity: Major
        Found in hawk/app/assets/javascripts/module/primitives.js - About 3 hrs to fix
          Severity
          Category
          Status
          Source
          Language