publiclab/spectral-workbench

View on GitHub

Showing 127 of 127 total issues

Avoid deeply nested control flow statements.
Open

          if (red == 255) $W.data[4].data.push([w,100])
Severity: Major
Found in app/assets/javascripts/capture.js - About 45 mins to fix

    Function initialize has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      initialize: function(args) {
        this.mobile = args['mobile'] || false
        this.flipped = args['flipped'] == true || false
        this.interface = args['interface'] || false
        this.mode = args['mode'] || 'combined'
    Severity: Minor
    Found in app/assets/javascripts/capture.js - 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

    Function calibrate has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    $W.calibrate = function(id,x1,w1,x2,w2) {
    Severity: Minor
    Found in app/assets/javascripts/api.js - About 35 mins to fix

      Function excerptCanvas has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        excerptCanvas: function(x1,y1,x2,y2,source) {
      Severity: Minor
      Found in app/assets/javascripts/capture.js - About 35 mins to fix

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

          def self.weekly_tallies
            # past 52 weeks of data
            weeks = {}
            (0..52).each do |week|
              weeks[52 - week] = User.select(:created_at).where(created_at: Time.now - week.weeks..Time.now - (week - 1).weeks).count
        Severity: Minor
        Found in app/models/user.rb and 1 other location - About 35 mins to fix
        app/models/spectrum.rb on lines 106..112

        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

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

          def change_reference(snapshot_id)
            # only free, un-depended-on tags can do this
            if snapshot.has_no_dependent_spectra? && !snapshot.has_subsequent_depended_on_snapshots?
              old_name = name
              old_name = old_name.split('#')[0] if has_reference?
        Severity: Minor
        Found in app/models/tag.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 delete has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          def delete
            @macro = Macro.find params[:id]
            if logged_in? && (current_user.id == @macro.user_id || current_user.role == 'admin')
              if @macro.delete
                flash[:notice] = 'Macro deleted.'
        Severity: Minor
        Found in app/controllers/macros_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 is_calibrated? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          def is_calibrated?
            if data.nil?
              false
            else
              if tags.collect(&:key).include?('calibrate') || tags.collect(&:key).include?('linearCalibration')
        Severity: Minor
        Found in app/models/spectrum.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 is_deletable? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          def is_deletable?
            if is_powertag? && needs_snapshot?
              if snapshot.nil?
                true
              elsif snapshot.is_deletable? # includes snapshot.is_latest?
        Severity: Minor
        Found in app/models/tag.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

        Function alert_overexposure has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          alert_overexposure: function() {
            var oe = $W.detect_overexposure()
            if (oe['r'] || oe['g'] || oe['b']) {
              var msg = "Light source is too strong or camera is too sensitive; overexposure in channels: "
              var channels = []
        Severity: Minor
        Found in app/assets/javascripts/analyze.js - 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

          def self.weekly_tallies
            # past 52 weeks of data
            weeks = {}
            (0..52).each do |week|
              weeks[52 - week] = Spectrum.select(:created_at).where(created_at: Time.now - week.weeks..Time.now - (week - 1).weeks).count
        Severity: Minor
        Found in app/models/spectrum.rb and 1 other location - About 35 mins to fix
        app/models/user.rb on lines 33..39

        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

          def comment_notification(spectrum, comment, spectrum_author)
            @user = spectrum.user.login
            @comment = comment
            @spectrum = spectrum
            mail(to: spectrum_author.email,
        Severity: Minor
        Found in app/mailers/user_mailer.rb and 1 other location - About 35 mins to fix
        app/mailers/user_mailer.rb on lines 49..54

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

        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 set_comment_notification(set, comment, set_author)
            @user = set.user.login
            @comment = comment
            @set = set
            mail(to: set_author.email,
        Severity: Minor
        Found in app/mailers/user_mailer.rb and 1 other location - About 35 mins to fix
        app/mailers/user_mailer.rb on lines 28..33

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

        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

            $('.btn-switch-calibration-configure').click(function() {
              window.location = "/capture?calibration_id=" + $('.select-calibration-configure').val()
            });
        Severity: Minor
        Found in app/assets/javascripts/capture.js and 1 other location - About 30 mins to fix
        app/assets/javascripts/capture.js on lines 69..71

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

        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

            $('.btn-switch-calibration-capture').click(function() {
              window.location = "/capture?calibration_id=" + $('.select-calibration-capture').val()
            });
        Severity: Minor
        Found in app/assets/javascripts/capture.js and 1 other location - About 30 mins to fix
        app/assets/javascripts/capture.js on lines 65..67

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

        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 require_login has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def require_login
            unless logged_in?
        
              path_info = request.env['PATH_INFO']
              login_link = "/login?back_to=#{URI.encode(path_info)}"
        Severity: Minor
        Found in app/controllers/application_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

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

          success: function (stream) {
            //console.log('success')
            if ($W.options.context === 'webrtc') {
              $('#heightIndicator').show()
              $('#webcam-msg').hide()
        Severity: Minor
        Found in app/assets/javascripts/capture.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

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

          def fork(user)
            new = dup
            new.author = user.login
            new.user_id = user.id
            new.photo = photo
        Severity: Minor
        Found in app/models/spectrum.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 create_key has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def create_key
            if logged_in? && current_user.role == 'admin'
              @device = Device.new(
                name: 'Precalibrated Countertop Spectrometer',
                user_id: 0,
        Severity: Minor
        Found in app/controllers/device_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 add_reference has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def add_reference(snapshot_id)
            unless has_reference?
              spectrum = Spectrum.find(value)
              if spectrum.snapshots && !spectrum.snapshots.empty?
                snapshot_id ||= spectrum.snapshots.last.id
        Severity: Minor
        Found in app/models/tag.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