metamaps/metamaps

View on GitHub

Showing 309 of 2,044 total issues

Cyclomatic complexity for topics is too high. [15/6]
Open

  def topics
    term = params[:term]
    user = params[:user] ? params[:user] : false

    if term.present? && term.downcase[0..3] != 'map:' &&

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.

Cyclomatic complexity for summarize_data is too high. [15/6]
Open

  def self.summarize_data(map, user, until_moment = DateTime.current)
    results = {
      stats: {}
    }

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.

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

  render: function() {
    const self = Visualize

    if (self.type === 'RGraph') {
      // clear the previous canvas from #infovis
Severity: Major
Found in frontend/src/Metamaps/Visualize.js - About 2 hrs to fix

Function render has 66 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  render () {
    const { topic, map, filterData, allForFiltering, visibleForFiltering, toggleMetacode,
            toggleMapper, toggleSynapse, filterAllMetacodes,
            filterAllMappers, filterAllSynapses } = this.props
    const style = {
Severity: Major
Found in frontend/src/components/FilterBox.js - About 2 hrs to fix

Function init has 65 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  init: function(serverData) {
    var self = Realtime

    self.addJuntoListeners()

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

Assignment Branch Condition size for after_updated is too high. [24.35/16]
Open

  def after_updated
    return unless ATTRS_TO_WATCH.any? { |k| changed_attributes.key?(k) }

    new = attributes.select { |k| ATTRS_TO_WATCH.include?(k) }
    old = changed_attributes.select { |k| ATTRS_TO_WATCH.include?(k) }
Severity: Minor
Found in app/models/synapse.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. [18/10]
Open

  def as_json(options = {})
    json = { id: id,
             name: name,
             image: image.url(:sixtyfour),
             admin: admin }
Severity: Minor
Found in app/models/user.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 show is too high. [24.35/16]
Open

  def show
    respond_to do |format|
      format.html do
        UserMap.where(map: @map, user: current_user).map(&:mark_invite_notifications_as_read)
        @allmappers = @map.contributors
Severity: Minor
Found in app/controllers/maps_controller.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 after_updated is too high. [24.35/16]
Open

  def after_updated
    return unless ATTRS_TO_WATCH.any? { |k| changed_attributes.key?(k) }

    new = attributes.select { |k| ATTRS_TO_WATCH.include?(k) }
    old = changed_attributes.select { |k| ATTRS_TO_WATCH.include?(k) }
Severity: Minor
Found in app/models/topic.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 rdf is too high. [24.04/16]
Open

  def rdf
    output = ''
    output += "PREFIX d: <#{base_url}/maps/#{map.id}>\n"
    output += "PREFIX mm: <#{base_url}/owl/map.owl.ttl>\n"
    output += "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
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. [18/10]
Open

  def exportable_topics
    visible_topics ||= Pundit.policy_scope!(user, map.topics)
    topic_mappings = Mapping.includes(mappable: %i[metacode user])
                            .where(mappable: visible_topics, map: map)
    topic_mappings.map do |mapping|
Severity: Minor
Found in app/services/map_export_service.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 create is too high. [24.35/16]
Open

  def create
    @user = current_user
    @metacode_set = MetacodeSet.new(metacode_set_params)
    @metacode_set.user_id = @user.id

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. [18/10]
Open

  def show
    @receipt.update(is_read: true)
    respond_to do |format|
      format.html do
        case @notification.notification_code

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

  def self.summarize_data(map, user, until_moment = DateTime.current)
    results = {
      stats: {}
    }

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

Assignment Branch Condition size for should_auto_follow is too high. [24.37/16]
Open

    def should_auto_follow(entity, user, reason)
      follow = Follow.where(followed: entity, user: user).first
      return false if follow && follow.muted
      if entity.class == Topic
        return user.settings.follow_topic_on_created == '1' if reason == 'created'
Severity: Minor
Found in app/services/follow_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

Function render has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

  render: function() {
    const self = Visualize

    if (self.type === 'RGraph') {
      // clear the previous canvas from #infovis
Severity: Minor
Found in frontend/src/Metamaps/Visualize.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 init has 64 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    init: function() {
      $('#topic_name').keyup(function(e) {
        const ESC = 27

        if (e.keyCode === ESC) {
Severity: Major
Found in frontend/src/Metamaps/Create.js - About 2 hrs to fix

ChatView has 23 functions (exceeds 20 allowed). Consider refactoring.
Open

const ChatView = {
  isOpen: false,
  unreadMessages: 0,
  messages: new Backbone.Collection(),
  conversationLive: false,
Severity: Minor
Found in frontend/src/Metamaps/Views/ChatView.js - About 2 hrs to fix

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

  def create
    @map = Map.new(create_map_params)
    @map.user = current_user
    @map.updated_by = current_user
    @map.arranged = false
Severity: Minor
Found in app/controllers/maps_controller.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 show is too high. [23.35/16]
Open

  def show
    @receipt.update(is_read: true)
    respond_to do |format|
      format.html do
        case @notification.notification_code

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

Severity
Category
Status
Source
Language