opengovernment/askthem

View on GitHub

Showing 154 of 154 total issues

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

    this.filter(ClientSideValidations.selectors.inputs).each(function() {
      return ClientSideValidations.enablers.input(this);
    });
Severity: Minor
Found in app/assets/javascripts/rails.validations.js and 1 other location - About 35 mins to fix
app/assets/javascripts/rails.validations.js on lines 13..15

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

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

    this.filter(ClientSideValidations.selectors.forms).each(function() {
      return ClientSideValidations.enablers.form(this);
    });
Severity: Minor
Found in app/assets/javascripts/rails.validations.js and 1 other location - About 35 mins to fix
app/assets/javascripts/rails.validations.js on lines 16..18

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

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

Method find_site_key_and_video_id has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def find_site_key_and_video_id
    VIDEO_SITE_URL_PATTERNS.each do |key, value|
      value.each do |pattern|
        if original_url =~ pattern
          key = :youtube_full if key == :youtube
Severity: Minor
Found in app/models/video_src_url.rb - About 35 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

Method new has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def new
    new! do
      if params[:twitter_id]
        screen_name = params[:twitter_id]
        twitter_api = TwitterPersonService.new(screen_name, false)
Severity: Minor
Found in app/controllers/candidates_controller.rb - About 35 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

Method most_recent_session has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def most_recent_session(type)
    session_details = read_attribute(:session_details)
    read_attribute(:terms).last["sessions"].reverse.each do |session|
      # OpenStates doesn't always declare the session type.
      return session if session_details[session].key?("type") && session_details[session]["type"] == type ||
Severity: Minor
Found in app/models/metadatum.rb - About 35 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

Method state_name has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def state_name
    if state? || federal?
      @jurisdiction['name']
    elsif local?
      state = Metadatum.where(abbreviation: state_abbreviation).first
Severity: Minor
Found in app/helpers/application_helper.rb - About 35 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

Method legacy_skip_for_now has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def legacy_skip_for_now(office, division)
    (office.level == "county" && (office.name.downcase != "mayor" &&
                                  !office.name.downcase.include?("council"))) ||
      (office.level == "federal" && division.scope == "national") ||
      ((office.level == "city" || office.level == "other") &&
Severity: Minor
Found in app/models/cached_officials_from_google.rb - About 35 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

Method perform has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def perform(id)
    self.person = Person.find(id.to_s)
    return unless person.photo_url.present?

    unless ImageLinkChecker.new(person.photo_url).accessible?
Severity: Minor
Found in app/workers/person_check_photo_url_worker.rb - About 35 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

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

    if question_different_jurisdiction
      correct_jurisdiction = question_different_jurisdiction.state
      if correct_jurisdiction == Metadatum::Unaffiliated::ABBREVIATION
        redirect_to unaffiliated_question_path(params[:id], share: params[:share])
      else
Severity: Minor
Found in app/controllers/questions_controller.rb and 1 other location - About 35 mins to fix
app/controllers/people_controller.rb on lines 26..34

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

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

    if person_different_jurisdiction
      correct_jurisdiction = person_different_jurisdiction.state
      if correct_jurisdiction == Metadatum::Unaffiliated::ABBREVIATION
        redirect_to unaffiliated_person_path(params[:id], share: params[:share])
      else
Severity: Minor
Found in app/controllers/people_controller.rb and 1 other location - About 35 mins to fix
app/controllers/questions_controller.rb on lines 87..95

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

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

Avoid too many return statements within this function.
Open

          return options.messages.even;
Severity: Major
Found in app/assets/javascripts/rails.validations.js - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

              return options.message;
    Severity: Major
    Found in app/assets/javascripts/rails.validations.js - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return;
      Severity: Major
      Found in app/assets/javascripts/rails.validations.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                  return options.messages.odd;
        Severity: Major
        Found in app/assets/javascripts/rails.validations.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                      return options.messages[check];
          Severity: Major
          Found in app/assets/javascripts/rails.validations.js - About 30 mins to fix

            Method id has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def id
                raise "Must specify state" unless state
                raise "Only municipality or county, not both" if municipality && county
            
                id = state.downcase
            Severity: Minor
            Found in app/models/jurisdiction_id.rb - 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

            Method new has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def new
                set_up_steps
                @question = Question.new(state: @state_code)
                @question.user = user_signed_in? ? current_user : User.new
                @question.user.for_new_question = true
            Severity: Minor
            Found in app/controllers/questions_controller.rb - 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

            Method copy_to_new_person has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def copy_to_new_person
                unless Metadatum.where(id: state).first
                  copy_to_new_metadatum
                end
            
            
            Severity: Minor
            Found in app/models/cached_official.rb - 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

            Method guess_office_level has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def guess_office_level(office, division)
                if office.is_governor? || office.is_state_legislator?
                  GoogleCivicInfo::Office::STATE
                elsif office.is_federal_legislator? || office.is_federal_executive_or_judicial?
                  GoogleCivicInfo::Office::FEDERAL
            Severity: Minor
            Found in app/models/cached_officials_from_google.rb - 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

            Method jurisdiction has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def jurisdiction(object)
                if @jurisdiction
                  @jurisdiction
                else
                  @jurisdictions ||= {}
            Severity: Minor
            Found in app/helpers/application_helper.rb - 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

            Severity
            Category
            Status
            Source
            Language