testmycode/tmc-server

View on GitHub

Showing 202 of 278 total issues

Avoid deeply nested control flow statements.
Open

    elsif submission.requires_review?
      if can? :create_review, submission.course
        link_to 'Required', new_submission_review_path(submission)
      else
        'Pending'
Severity: Major
Found in app/helpers/submissions_helper.rb - About 45 mins to fix

    Method show has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def show
        course_id = params[:course_id]
        user_id = params[:id]
    
        course = Course.where(id: course_id).first || Course.where(name: course_id).first
    Severity: Minor
    Found in app/controllers/exercise_status_controller.rb - About 45 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 maybe_update_password has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

            def maybe_update_password
              if params[:old_password].present? && params[:password].present?
                if !@user.has_password?(params[:old_password])
                  @user.errors.add(:old_password, 'incorrect')
                elsif params[:password] != params[:password_repeat]
    Severity: Minor
    Found in app/controllers/api/v8/users_controller.rb - About 45 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 validate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def validate(record)
        kind = record.feedback_question.kind
        ans = record.answer.strip
    
        if kind =~ FeedbackQuestion.send(:intrange_regex)
    Severity: Minor
    Found in app/models/validators/feedback_answer_format_validator.rb - About 45 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 filter_by has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.filter_by(filter_params)
        users = includes(:user_field_values)
    
        users = users.where(administrator: false) unless filter_params['include_administrators']
    
    
    Severity: Minor
    Found in app/models/user.rb - About 45 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 raise_pretest_error_if_any has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def raise_pretest_error_if_any
        unless pretest_error.nil?
          error = "Submission failed: #{pretest_error}."
          error << if stdout.blank?
            "\n\n(no stdout)"
    Severity: Minor
    Found in app/models/submission.rb - About 45 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 difference_with_solution has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def difference_with_solution
        @course ||= @submission.course
        authorize! :teach, @course
        @exercise ||= @submission.exercise
        @organization = @course.organization
    Severity: Minor
    Found in app/controllers/submissions_controller.rb - About 45 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 course_points has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.course_points(course, include_admins = false, hidden = false, only_for_user = nil)
        awarded_points = AwardedPoint.arel_table
        users = User.arel_table
        exercises = Exercise.arel_table
        submissions = Submission.arel_table
    Severity: Minor
    Found in app/models/awarded_point.rb - About 45 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

    Avoid deeply nested control flow statements.
    Open

          if can? :create_review, submission.course
            link_to 'Requested', new_submission_review_path(submission)
          else
            'Requested'
          end
    Severity: Major
    Found in app/helpers/submissions_helper.rb - About 45 mins to fix

      Method index has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def index
          respond_to do |format|
            format.json do
              if params[:row_format] == 'datatables'
                index_json_datatables
      Severity: Minor
      Found in app/controllers/submissions_controller.rb - About 45 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

      Avoid deeply nested control flow statements.
      Open

                if remaining > 0
                  "get #{remaining} more #{plural(remaining, 'point')} from #{group}"
                end
      Severity: Major
      Found in app/models/unlock_spec.rb - About 45 mins to fix

        Method create has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

                def create
                  return respond_forbidden unless current_user.administrator?
                  users = params[:emails].map do |email|
                    User.find_by('lower(email) = ?', email.downcase)
                  end.compact
        Severity: Minor
        Found in app/controllers/api/v8/users/basic_info_by_emails_controller.rb - About 45 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 find_dir_containing has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def find_dir_containing(root, to_find)
            Pathname(root).find do |path|
              next unless path.directory?
              next unless (path + to_find).directory?
              return path
        Severity: Minor
        Found in lib/tmc_dir_utils.rb - About 45 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 update_user_course_points has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def update_user_course_points(task)
            finished_successfully = false
            course = Course.find(task.course_id)
            user = User.find(task.user_id)
            Rails.logger.info("Publishing points for user #{user.id} with moocfi id: #{course.moocfi_id}.")
        Severity: Minor
        Found in lib/kafka_updater.rb - About 45 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 set_memory_limit has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

              def set_memory_limit
                @rust_data['exercises'].each do |exercise|
                  ex = @course.exercises.find { |e| e.name == exercise['name'] }
                  next unless ex
                  if (exercise['tmcproject-yml'] || {}).include? 'memory_gb'
        Severity: Minor
        Found in lib/course_refresh_database_updater.rb - About 45 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 set_docker_image has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

              def set_docker_image
                default_image = Exercise.new.docker_image
                @rust_data['exercises'].each do |exercise|
                  ex = @course.exercises.find { |e| e.name == exercise['name'] }
                  next unless ex
        Severity: Minor
        Found in lib/course_refresh_database_updater.rb - About 45 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 set_cpu_limit has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

              def set_cpu_limit
                @rust_data['exercises'].each do |exercise|
                  ex = @course.exercises.find { |e| e.name == exercise['name'] }
                  next unless ex
                  if (exercise['tmcproject-yml'] || {}).include? 'cpus'
        Severity: Minor
        Found in lib/course_refresh_database_updater.rb - About 45 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 check_options has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def check_options
              raise ':name required' unless @options[:name]
              raise ':erb_path required' unless @options[:erb_path]
              raise ':working_dir required' unless @options[:working_dir]
              raise ':executable_path required' unless @options[:executable_path]
        Severity: Minor
        Found in lib/ruby_init_script.rb - About 45 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 update_course_points has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def update_course_points(task)
            finished_successfully = false
            course = Course.find(task.course_id)
            Rails.logger.info("Batch publishing points for course #{course.name} with moocfi id: #{course.moocfi_id}")
            if !course.moocfi_id
        Severity: Minor
        Found in lib/kafka_updater.rb - About 45 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

        Consider simplifying this complex logical expression.
        Open

            elsif !@exercise.visible_to?(user)
              false
            else
              show_when_completed = SiteSetting.value('show_model_solutions_when_exercise_completed')
              show_when_expired = SiteSetting.value('show_model_solutions_when_exercise_expired')
        Severity: Major
        Found in app/models/solution.rb - About 40 mins to fix
          Severity
          Category
          Status
          Source
          Language