Skip to content

Instantly share code, notes, and snippets.

@sakuro
Created September 14, 2025 16:51
Show Gist options
  • Select an option

  • Save sakuro/0e632e5f6df2277231a427cdc47a5fc7 to your computer and use it in GitHub Desktop.

Select an option

Save sakuro/0e632e5f6df2277231a427cdc47a5fc7 to your computer and use it in GitHub Desktop.
PLATFORMSに入っているべき値を強制するCop
# lib/rubocop/cop/bundler/required_platforms.rb
module RuboCop
module Cop
module Bundler
class RequiredPlatforms < Cop
def on_new_investigation
required = Array(cop_config['RequiredPlatforms'])
lockfile = File.read('Gemfile.lock')
platforms = lockfile[/^PLATFORMS\n(.+?)\n\n/m, 1].to_s.lines.map(&:strip)
(required - platforms).each do |missing|
add_offense(nil, message: "Gemfile.lock に #{missing} が含まれていません")
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment