Codeminer42/cm42-central

View on GitHub

Showing 331 of 343 total issues

Function calculateVelocity has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    calculateVelocity: function () {
      if (this.doneIterations().length === 0) {
        return this.get('default_velocity');
      } else {
        // TODO Make number of iterations configurable
Severity: Minor
Found in app/assets/javascripts/models/project.js - About 25 mins 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 canEdit has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  canEdit: function () {
    var isEditable = this.model.get('editing');
    var isSearchResultContainer = this.$el.hasClass('searchResult');
    var clickFromSearchResult = this.model.get('clickFromSearchResult');
    if (_.isUndefined(isEditable)) isEditable = false;
Severity: Minor
Found in app/assets/javascripts/views/story_view.jsx - About 25 mins 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

Complex method ProjectsController#join (20.6)
Open

  def join
    project = projects_unjoined.find_by!(slug: params[:id])
    authorize project

    project.users << current_user
Severity: Minor
Found in app/controllers/projects_controller.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

Complex method ProjectPolicy::Scope#resolve (20.3)
Open

    def resolve
      if root?
        Project.all
      elsif admin?
        current_team.projects
Severity: Minor
Found in app/policies/project_policy.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

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

    match_result(result) do |on|
      on.success do |note|
        render json: note
      end
      on.failure do |note|
Severity: Minor
Found in app/controllers/notes_controller.rb and 1 other location - About 20 mins to fix
app/controllers/tasks_controller.rb on lines 10..17

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

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

    match_result(result) do |on|
      on.success do |task|
        render json: task
      end

Severity: Minor
Found in app/controllers/tasks_controller.rb and 1 other location - About 20 mins to fix
app/controllers/notes_controller.rb on lines 29..35

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

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

Complex method Statistics::variance (20.1)
Open

  def self.variance(enumerable, sample_size = enumerable.size)
    slice = slice_to_sample_size(enumerable, sample_size)
    total = slice.size > 1 && (total(slice) < total(enumerable)) ? total(slice) - 1 : sample_size
    mean  = mean(slice)
    sum(slice.map { |sample| (mean - sample)**2 }) / total
Severity: Minor
Found in app/services/statistics.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

Complex method IterationService#iteration_start_date (20.1)
Open

  def iteration_start_date(date = nil)
    date = start_date if date.nil?
    iteration_start_date = date.beginning_of_day
    if start_date.wday != iteration_start_day
      day_difference = start_date.wday - iteration_start_day
Severity: Minor
Found in app/services/iteration_service.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

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

    def call
      ActiveRecord::Base.transaction do
        yield save_project
        yield create_activity
        yield create_ownership
Severity: Minor
Found in app/operations/project_operations/create.rb and 1 other location - About 15 mins to fix
app/operations/task_operations/create.rb on lines 10..19

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

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

    def call
      ActiveRecord::Base.transaction do
        yield save_task
        yield create_changeset
        yield create_activity
Severity: Minor
Found in app/operations/task_operations/create.rb and 1 other location - About 15 mins to fix
app/operations/project_operations/create.rb on lines 11..20

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

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

Prefer annotated tokens (like %<foo>s</foo>) over template tokens (like %{foo}).
Open

                                       message: '%{value} is not a valid estimation scheme' }
Severity: Minor
Found in app/models/project.rb by rubocop

Use a consistent style for named format string tokens.

Example:

EnforcedStyle: annotated

# bad

format('%{greeting}', greeting: 'Hello')
format('%s', 'Hello')

# good

format('%<greeting>s', greeting: 'Hello')</greeting>

Example:

EnforcedStyle: template

# bad

format('%<greeting>s', greeting: 'Hello')
format('%s', 'Hello')

# good

format('%{greeting}', greeting: 'Hello')</greeting>

Place the . on the next line, together with the method name.
Open

      data.merge(state => current_iteration.
Severity: Minor
Found in app/services/iteration_service.rb by rubocop

Use %i or %I for an array of symbols.
Open

  scope :in_progress, -> { where(state: [:started, :finished, :delivered]) }
Severity: Minor
Found in app/models/story.rb by rubocop

This cop can check for array literals made up of symbols that are not using the %i() syntax.

Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax, perhaps because they support a version of Ruby lower than 2.0.

Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of3` will not enforce a style on an array of 2 or fewer elements.

Example:

EnforcedStyle: percent (default)

# good
%i[foo bar baz]

# bad
[:foo, :bar, :baz]

Example:

EnforcedStyle: brackets

# good
[:foo, :bar, :baz]

# bad
%i[foo bar baz]

Space inside parentheses detected.
Open

        last_date = backlog_iterations.last.start_date + ( project.iteration_length * DAYS_IN_WEEK )
Severity: Minor
Found in app/services/iteration_service.rb by rubocop

Redundant self detected.
Open

        self.new(private_uri, project_channel, bot_username).send(message)

This cop checks for redundant uses of self.

self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

We allow uses of self with operators because it would be awkward otherwise.

Line is too long. [117/100]
Open

    @dummy_user ||= User.find_or_create_by!(username: "dummy", email: "dummy@foo.com", name: "Dummy", initials: "XX")
Severity: Minor
Found in app/services/iteration_service.rb by rubocop

Redundant self detected.
Open

        self.new(private_uri, project_channel, bot_username).send(message)

This cop checks for redundant uses of self.

self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

We allow uses of self with operators because it would be awkward otherwise.

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

    @dummy_user ||= User.find_or_create_by!(username: "dummy", email: "dummy@foo.com", name: "Dummy", initials: "XX")
Severity: Minor
Found in app/services/iteration_service.rb by rubocop

Align reduce with @accepted_stories. on line 106.
Open

      reduce({}) do |group, iteration|
Severity: Minor
Found in app/services/iteration_service.rb by rubocop

Pass &:accepted_at as an argument to sort_by instead of a block.
Open

      accepted = accepted.sort_by { |story| story.accepted_at }.group_by { |story| story.accepted_at.to_date }
Severity: Minor
Found in app/services/iteration_service.rb by rubocop

Use symbols as procs when possible.

Example:

# bad
something.map { |s| s.upcase }

# good
something.map(&:upcase)
Severity
Category
Status
Source
Language