# frozen_string_literal: true

# Style tasks run on the latest Ruby; RuboCop-LTS selects the compatibility
# rules for the configured Ruby floor independently from task dependency floors.

# Local path overrides for development.
# Loaded by the associated non-local gemfile when RUBOCOP_LTS_LOCAL != "false".

nomono_activation_requirements = ["~> 1.0", ">= 1.0.8"]
nomono_lockfile = File.expand_path("../../Gemfile.lock", __dir__)
if File.file?(nomono_lockfile)
  nomono_locked_spec = Bundler::LockfileParser
    .new(Bundler.read_file(nomono_lockfile))
    .specs
    .find { |spec| spec.name == "nomono" }
  nomono_locked = nomono_locked_spec &&
    Gem::Requirement.new(nomono_activation_requirements).satisfied_by?(nomono_locked_spec.version)
  if nomono_locked
    nomono_activation_requirements = ["= #{nomono_locked_spec.version}"]
  end
end
Kernel.send(:gem, "nomono", *nomono_activation_requirements)
require "nomono/bundler"

local_gems = %w[rubocop-lts rubocop-lts-rspec rubocop-ruby2_2 standard-rubocop-lts]
declared_gems = instance_variable_get(:@dependencies).to_a.map(&:name)
local_gems_to_eval = local_gems - %w[auth-sanitizer] - declared_gems

# export VENDORED_GEMS=rubocop-lts,rubocop-lts-rspec,rubocop-ruby2_2,standard-rubocop-lts
platform :mri do
  eval_nomono_gems(
    gems: local_gems_to_eval,
    prefix: "RUBOCOP_LTS",
    path_env: "RUBOCOP_LTS_LOCAL",
    vendored_gems_env: "VENDORED_GEMS",
    vendor_gem_dir_env: "VENDOR_GEM_DIR",
    debug_env: "RUBOCOP_LTS_DEBUG",
    root: ["src", "rubocop-lts"]
  )
end
