metamaps/metamaps

View on GitHub

Showing 309 of 2,044 total issues

Method has too many lines. [15/10]
Open

  def autocomplete_map_array_json(maps)
    maps.map do |m|
      {
        id: m.id,
        label: m.name,
Severity: Minor
Found in app/helpers/maps_helper.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.

Perceived complexity for synapses_csv is too high. [12/7]
Open

  def synapses_csv(output_format = 'array')
    output = []
    synapses.each do |synapse|
      if synapse.category == 'from-to'
        if synapse.topic1_id == id
Severity: Minor
Found in app/models/topic.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Method has too many lines. [15/10]
Open

  def self.send_for_follows(follows, entity, event_type, event)
    return if follows.empty?
    settings = get_settings_for_event(entity, event_type, event)
    # we'll prbly want to put the body into the actual loop so we can pass the current user in as a local
    body = renderer.render(template: settings[:template], locals: { entity: entity, event: event }, layout: false)

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 to_spreadsheet is too high. [21.02/16]
Open

  def to_spreadsheet
    spreadsheet = []
    spreadsheet << ['Topics']
    spreadsheet << topic_headings.map(&:capitalize)
    exportable_topics.each do |topics|
Severity: Minor
Found in app/services/map_export_service.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. [15/10]
Open

  def index
    @notifications = current_user.mailbox.notifications.page(params[:page]).per(25)
    respond_to do |format|
      format.html
      format.json do

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.

Function updateAll has 56 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        this.updateAll = function()
        {                                            
            var    minScale = options.minScale;    // This is the smallest scale applied to the furthest item.
            var smallRange = (1-minScale) * 0.5;
            var    w,h,x,y,scale,item,sinVal;
Severity: Major
Found in app/assets/javascripts/cloudcarousel-secret.js - About 2 hrs to fix

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

class MapPolicy < ApplicationPolicy
  class Scope < Scope
    def resolve
      visible = %w[public commons]
      return scope.where(permission: visible) unless user
Severity: Minor
Found in app/policies/map_policy.rb - About 2 hrs to fix

Function fetchSiblings has 54 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  fetchSiblings: function(nodes, metacodeId) {
    var self = this

    var node = Array.isArray(nodes) ? nodes[0] : nodes

Severity: Major
Found in frontend/src/Metamaps/Topic.js - About 2 hrs to fix

Function attachEventListeners has 54 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  attachEventListeners: function() {
    var self = InfoBox
    $('.mapInfoBox').click(function(event) {
      event.stopPropagation()
    })
Severity: Major
Found in frontend/src/Metamaps/Map/InfoBox.js - About 2 hrs to fix

Perceived complexity for user_metacodes is too high. [11/7]
Open

  def user_metacodes
    @m = current_user.settings.metacodes
    set = metacodeset
    @metacodes = if set && set == 'Most'
                   Metacode.where(id: current_user.most_used_metacodes).to_a
Severity: Minor
Found in app/helpers/metacodes_helper.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Cyclomatic complexity for maps is too high. [10/6]
Open

  def maps
    term = params[:term]
    user = params[:user] ? params[:user] : nil

    if term.present? && term.downcase[0..5] != 'topic:' &&

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.

Method has too many lines. [14/10]
Open

  def before_destroyed
    if mappable.defer_to_map
      mappable.permission = mappable.defer_to_map.permission
      mappable.defer_to_map_id = nil
      mappable.save
Severity: Minor
Found in app/models/mapping.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 resolve is too high. [20.12/16]
Open

    def resolve
      visible = %w[public commons]
      permission = 'maps.permission IN (?)'
      return scope.joins(:map).where(permission, visible) unless user

Severity: Minor
Found in app/policies/message_policy.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 resolve is too high. [20.12/16]
Open

    def resolve
      # TODO: base this on the map policy
      # it would be nice if we could also base this on the mappable, but that
      # gets really complicated. Devin thinks it's OK to SHOW a mapping for
      # a private topic, since you can't see the private topic anyways
Severity: Minor
Found in app/policies/mapping_policy.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

Cyclomatic complexity for send_for_follows is too high. [10/6]
Open

  def self.send_for_follows(follows, entity, event_type, event)
    return if follows.empty?
    settings = get_settings_for_event(entity, event_type, event)
    # we'll prbly want to put the body into the actual loop so we can pass the current user in as a local
    body = renderer.render(template: settings[:template], locals: { entity: entity, event: event }, layout: false)

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 handle_unauthorized is too high. [20.4/16]
Open

  def handle_unauthorized
    if authenticated? && (params[:controller] == 'maps') && (params[:action] == 'show')
      redirect_to request_access_map_path(params[:id])
    elsif authenticated?
      redirect_to root_path, notice: "You don't have permission to see that page."

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 ReactApp.js has 254 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* global $ */

import React from 'react'
import ReactDOM from 'react-dom'
import { Router, browserHistory } from 'react-router'
Severity: Minor
Found in frontend/src/Metamaps/GlobalUI/ReactApp.js - About 2 hrs to fix

Function renderSynapse has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

  renderSynapse: function(mapping, synapse, node1, node2, createNewInDB) {
    var edgeOnViz

    var newedge = synapse.createEdge(mapping)

Severity: Minor
Found in frontend/src/Metamaps/Synapse.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

Function selectNodeOnClickHandler has 52 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  selectNodeOnClickHandler: function(node, e) {
    if (Visualize.mGraph.busy) return

    const self = JIT

Severity: Major
Found in frontend/src/Metamaps/JIT.js - About 2 hrs to fix

Function updateFilters has 51 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  updateFilters: function(collection, propertyToCheck, correlatedModel, filtersToUse, listToModify) {
    var self = Filter
    var newList = []
    var removed = []
    var added = []
Severity: Major
Found in frontend/src/Metamaps/Filter.js - About 2 hrs to fix
Severity
Category
Status
Source
Language