metamaps/metamaps

View on GitHub

Showing 309 of 2,044 total issues

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

  def create
    @synapse = Synapse.new(synapse_params)
    @synapse.desc = '' if @synapse.desc.nil?
    @synapse.desc.strip! # no trailing/leading whitespace
    @synapse.user = current_user

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

  def self.notify_followers(entity, event_type, event, reason_filter = nil, exclude_follows = nil)
    follows = entity.follows.active.where.not(user_id: event.user.id)

    follows = follows.where.not(id: exclude_follows) unless exclude_follows.nil?

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 exportable_topics is too high. [23.37/16]
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 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 onDragEndTopicHandler has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

  onDragEndTopicHandler: function(node, eventInfo, e) {
    const self = JIT
    const midpoint = {}
    let pixelPos
    let mapping
Severity: Minor
Found in frontend/src/Metamaps/JIT.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 edgeRender has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

  edgeRender: function(adj, canvas) {
    // get nodes cartesian coordinates
    const pos = adj.nodeFrom.pos.getc(true)
    const posChild = adj.nodeTo.pos.getc(true)

Severity: Minor
Found in frontend/src/Metamaps/JIT.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 reducer has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

const reducer = (state = { connectedPeople: {}, liveMaps: {} }, action) => {
  const { type, payload } = action
  const { connectedPeople, liveMaps } = state
  const map = payload && liveMaps[payload.mapid]
  const mapWillEmpty = map && Object.keys(map).length === 1
Severity: Minor
Found in realtime/reducer.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 onDragEndTopicHandler has 60 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  onDragEndTopicHandler: function(node, eventInfo, e) {
    const self = JIT
    const midpoint = {}
    let pixelPos
    let mapping
Severity: Major
Found in frontend/src/Metamaps/JIT.js - About 2 hrs to fix

Method has too many lines. [16/10]
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 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. [16/10]
Open

  def after_created
    if mappable_type == 'Topic'
      ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'topicAdded', topic: mappable.filtered, mapping_id: id
      meta = { 'x': xloc, 'y': yloc, 'mapping_id': id }
      Events::TopicAddedToMap.publish!(mappable, map, user, meta)
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 after_updated is too high. [22.23/16]
Open

  def after_updated
    return unless (mappable_type == 'Topic') && (xloc_changed? || yloc_changed?)
    meta = { 'x': xloc, 'y': yloc, 'mapping_id': id }
    Events::TopicMovedOnMap.publish!(mappable, map, updated_by, meta)
    ActionCable.server.broadcast('map_' + map.id.to_s, type: 'topicMoved',
Severity: Minor
Found in app/models/mapping.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. [16/10]
Open

  def autocomplete_topic
    term = params[:term]
    if term.present?
      topics = policy_scope(Topic)
               .where('LOWER("name") like ?', term.downcase + '%')

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. [22.56/16]
Open

  def show
    respond_to do |format|
      format.html do
        @alltopics = [@topic].concat(policy_scope(Topic.relatives(@topic.id, current_user)).to_a)
        @allsynapses = policy_scope(Synapse.for_topic(@topic.id)).to_a

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

Perceived complexity for update is too high. [13/7]
Open

  def update
    @user = User.find(current_user.id)

    if user_params[:password] == '' && user_params[:password_confirmation] == ''
      # not trying to change the password
Severity: Minor
Found in app/controllers/users_controller.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. [16/10]
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 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 network is too high. [22.36/16]
Open

  def network
    @alltopics = [@topic].concat(policy_scope(Topic.relatives(@topic.id, current_user)).to_a)
    @allsynapses = policy_scope(Synapse.for_topic(@topic.id))

    @allcreators = @alltopics.map(&:user).uniq

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

    def mail_for_notification(notification)
      case notification.notification_code
      when MAP_ACCESS_REQUEST
        request = notification.notified_object
        MapMailer.access_request(request)
Severity: Minor
Found in app/mailers/application_mailer.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 updateMetacodeSet has 59 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  updateMetacodeSet: function(set, index, custom) {
    if (custom && Create.newSelectedMetacodes.length === 0) {
      window.alert('Please select at least one metacode to use!')
      return false
    }
Severity: Major
Found in frontend/src/Metamaps/Create.js - About 2 hrs to fix

Control has 22 functions (exceeds 20 allowed). Consider refactoring.
Open

const Control = {
  selectNode: function(node, e) {
    var filtered = node.getData('alpha') === 0

    if (filtered || Selected.Nodes.indexOf(node) !== -1) return
Severity: Minor
Found in frontend/src/Metamaps/Control.js - About 2 hrs to fix

Function makeRoutes has 58 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export default function makeRoutes (currentUser) {
  const homeComponent = currentUser && currentUser.id ? Maps : nullComponent
  return <Route path="/" component={App} >
    <IndexRoute component={homeComponent} />
    <Route path="explore">
Severity: Major
Found in frontend/src/routes/makeRoutes.js - About 2 hrs to fix

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

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

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

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
Severity
Category
Status
Source
Language