igrigorik/vimgolf

View on GitHub

Showing 21 of 21 total issues

Method play has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
Open

    def play(challenge)
      begin
        challenge.start
        VimGolf.ui.warn "Launching VimGolf session for challenge: #{challenge.id}"
        # -Z         - restricted mode, utilities not allowed
Severity: Minor
Found in lib/vimgolf/lib/vimgolf/cli.rb - About 6 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

Method play has 82 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def play(challenge)
      begin
        challenge.start
        VimGolf.ui.warn "Launching VimGolf session for challenge: #{challenge.id}"
        # -Z         - restricted mode, utilities not allowed
Severity: Major
Found in lib/vimgolf/lib/vimgolf/cli.rb - About 3 hrs to fix

    Method print_envs has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

          def print_envs(apps, default_env_name = nil, simple = false)
            if simple
              envs = apps.map{ |a| a.environments }
              envs.flatten.map{|x| x.name}.uniq.each do |env|
                puts env
    Severity: Minor
    Found in lib/vimgolf/lib/vimgolf/ui.rb - 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

    Method each has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def each
          scanner = StringScanner.new(@input)
    
          # A Vim keycode is either a single byte, or a 3-byte sequence starting
          # with 0x80.
    Severity: Minor
    Found in lib/vimgolf/lib/vimgolf/keylog.rb - About 1 hr 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 download has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def download
          @remote = true
          begin
            url = URI("#{GOLFHOST}/challenges/#{@id}.json")
            res = Net::HTTP.start(
    Severity: Minor
    Found in lib/vimgolf/lib/vimgolf/challenge.rb - About 1 hr to fix

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

        def create
          if params[:entry] && params[:entry].size < 2
            @cheat = true
      
          elsif params['challenge_id'] && !params['apikey'].empty? && !params['apikey'].nil?
      Severity: Minor
      Found in app/controllers/entry_controller.rb - About 1 hr 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 has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

        def create
          challenge = challenge_params
      
          challenge[:diff] = challenge.delete(:diff).read rescue nil
      
      
      Severity: Minor
      Found in app/controllers/challenges_controller.rb - About 1 hr 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 debug has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

            def debug(name, message = nil)
              return unless ENV["DEBUG"]
      
              if message
                message = message.inspect unless message.is_a?(String)
      Severity: Minor
      Found in lib/vimgolf/lib/vimgolf/ui.rb - About 1 hr 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

      Possible command injection
      Open

              system(*vimcmd) # assembled as an array, bypasses the shell
      Severity: Minor
      Found in lib/vimgolf/lib/vimgolf/cli.rb by brakeman

      Injection is #1 on the 2010 OWASP Top Ten web security risks. Command injection occurs when shell commands unsafely include user-manipulatable values.

      There are many ways to run commands in Ruby:

      `ls #{params[:file]}`
      
      system("ls #{params[:dir]}")
      
      exec("md5sum #{params[:input]}")

      Brakeman will warn on any method like these that uses user input or unsafely interpolates variables.

      See the Ruby Security Guide for details.

      Parameters should be whitelisted for mass assignment
      Open

          params.require(:challenge).permit!

      Mass assignment is a feature of Rails which allows an application to create a record from the values of a hash.

      Example:

      User.new(params[:user])

      Unfortunately, if there is a user field called admin which controls administrator access, now any user can make themselves an administrator.

      attr_accessible and attr_protected can be used to limit mass assignment. However, Brakeman will warn unless attr_accessible is used, or mass assignment is completely disabled.

      There are two different mass assignment warnings which can arise. The first is when mass assignment actually occurs, such as the example above. This results in a warning like

      Unprotected mass assignment near line 61: User.new(params[:user])

      The other warning is raised whenever a model is found which does not use attr_accessible. This produces generic warnings like

      Mass assignment is not restricted using attr_accessible

      with a list of affected models.

      In Rails 3.1 and newer, mass assignment can easily be disabled:

      config.active_record.whitelist_attributes = true

      Unfortunately, it can also easily be bypassed:

      User.new(params[:user], :without_protection => true)

      Brakeman will warn on uses of without_protection.

      Rule doesn't have all its properties in alphabetical order.
      Open

      pre.prettyprint { padding: 1em; border: 1px solid #888 }
      Severity: Minor
      Found in app/assets/stylesheets/prettify.css by csslint

      Element (li.L0) is overqualified, just use .L0 without element name.
      Open

      li.L0,
      Severity: Minor
      Found in app/assets/stylesheets/prettify.css by csslint

      Element (pre.prettyprint) is overqualified, just use .prettyprint without element name.
      Open

      pre.prettyprint { padding: 1em; border: 1px solid #888 }
      Severity: Minor
      Found in app/assets/stylesheets/prettify.css by csslint

      Element (li.L8) is overqualified, just use .L8 without element name.
      Open

      li.L8 { list-style-type: none }
      Severity: Minor
      Found in app/assets/stylesheets/prettify.css by csslint

      Rule doesn't have all its properties in alphabetical order.
      Open

      ol.linenums { margin-top: 0; margin-bottom: 0 } /* IE indents via margin-left */
      Severity: Minor
      Found in app/assets/stylesheets/prettify.css by csslint

      Element (li.L6) is overqualified, just use .L6 without element name.
      Open

      li.L6,
      Severity: Minor
      Found in app/assets/stylesheets/prettify.css by csslint

      Element (li.L9) is overqualified, just use .L9 without element name.
      Open

      li.L9 { background: #eee }
      Severity: Minor
      Found in app/assets/stylesheets/prettify.css by csslint

      Element (ol.linenums) is overqualified, just use .linenums without element name.
      Open

      ol.linenums { margin-top: 0; margin-bottom: 0 } /* IE indents via margin-left */
      Severity: Minor
      Found in app/assets/stylesheets/prettify.css by csslint

      Element (li.L2) is overqualified, just use .L2 without element name.
      Open

      li.L2,
      Severity: Minor
      Found in app/assets/stylesheets/prettify.css by csslint

      HACK found
      Open

      legend, #IE8#HACK { margin-top:0; margin-bottom:0; }
      Severity: Minor
      Found in app/assets/stylesheets/forms.scss.erb by fixme
      Severity
      Category
      Status
      Source
      Language