module RuboCop
  module Cop
    module Migration
      class PrimaryKey < Cop
        def on_send(node)
          _receiver, method_name, *args = *node
          if method_name == :create_table
            check_create_table(node, args)
          end
        end

        NO_PK = Parser::CurrentRuby.parse("{ id: false }").children.first

        def check_create_table(node, args)
          options = args.last
          return unless options.hash_type?

          if options.children.find { |pair| pair == NO_PK }
            message = "Please always include a primary key"
            add_offense(node, :expression, message)
          end
        end
      end
    end
  end
end

require 'parser/current'

module RuboCop
  module Cop
    module Migration
      class PrimaryKey < Cop
        def on_send(node)
          _receiver, method_name, *args = *node
          if method_name == :create_table
            check_create_table(node, args)
          end
        end

        NO_PK = Parser::CurrentRuby.parse("{ id: false }").children.first

        def check_create_table(node, args)
          options = args.last
          return unless options.hash_type?

          if options.children.find { |pair| pair == NO_PK }
            message = "Please always include a primary key"
            add_offense(node, :expression, message)
          end
        end
      end
    end
  end
end

Fix aux build failure in script/rlint
build: Fix aux build failure in script/rlint

Parser::CurrentRuby hadn't been loaded in some cases, requiring
explicitly makes sure it's always available here.

TEST PLAN:
 1) aux build should pass

Change-Id: Ic5d2ef0ebbd8673e9ccec0c6617be49ef451f617
Reviewed-on: https://gerrit.instructure.com/70305
Reviewed-by: Cody Cutrer <c4fe2b1d90ef8f2548c8aeabfa633434316f0305@instructure.com>
Product-Review: Rob Orton <7e09c9d3e96378bf549fc283fd6e1e5b7014cc33@instructure.com>
QA-Review: Rob Orton <7e09c9d3e96378bf549fc283fd6e1e5b7014cc33@instructure.com>
Tested-by: Rob Orton <7e09c9d3e96378bf549fc283fd6e1e5b7014cc33@instructure.com>
