Slide 5
Slide 5 text
۩ମྫʢίʔυϨϏϡʔલʣ
1 | # frozen_string_literal: true
2 |
3 | require 'rake/clean'
4 |
5 | namespace :rubocop do
6 | desc 'ରϑΝΠϧͷจࣈྻΛΠϛϡʔλϒϧʹ͢Δ'
7 | task :add_frozen_string do
8 | LIST_NAME = 'target_list.txt'
9 | CLEAN.include(LIST_NAME)
10 | sh %(bundle exec rubocop | grep "Missing frozen string" | cut -d: -f 1 > #{LIST_NAME})
11 | File.open(LIST_NAME, 'r+') do |list|
12 | list.each_line do |file_path|
13 | File.open(file_path.chomp, 'r+') do |target|
14 | lines = target.readlines
15 | inserted = "# frozen_string_literal: true\n\n"
16 | if %r{!/usr/bin/env ruby}.match?(lines.first)
17 | lines.insert(1, inserted)
18 | else
19 | lines.unshift(inserted)
20 | end
21 | target.rewind
22 | lines.each { |line| target.write(line) }
23 | end
24 | end
25 | end
26 | Rake::Task['clean'].execute
27 | end
28 | end