|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +desc 'Run RuboCop' |
| 4 | +task :rubocop do |
| 5 | + sh 'bundle exec rubocop' |
| 6 | +end |
| 7 | + |
| 8 | +desc 'Run RuboCop with auto-correct' |
| 9 | +task 'rubocop:auto_correct' do |
| 10 | + sh 'bundle exec rubocop -A' |
| 11 | +end |
| 12 | + |
| 13 | +desc 'Run all linters' |
| 14 | +task lint: :rubocop |
| 15 | + |
| 16 | +desc 'Auto-fix all linting issues' |
| 17 | +task 'lint:fix' => 'rubocop:auto_correct' |
| 18 | + |
| 19 | +desc 'Ensure all files end with newline' |
| 20 | +task :check_newlines do |
| 21 | + files_without_newline = [] |
| 22 | + |
| 23 | + Dir.glob('**/*.{rb,rake,yml,yaml,md,gemspec,ru,erb,js,json}').each do |file| |
| 24 | + next if file.include?('vendor/') || file.include?('node_modules/') || file.include?('.git/') |
| 25 | + next if file.include?('pkg/') || file.include?('tmp/') || file.include?('coverage/') |
| 26 | + next unless File.file?(file) |
| 27 | + |
| 28 | + content = File.read(file) |
| 29 | + files_without_newline << file unless content.empty? || content.end_with?("\n") |
| 30 | + end |
| 31 | + |
| 32 | + if files_without_newline.any? |
| 33 | + puts 'Files missing final newline:' |
| 34 | + files_without_newline.each { |f| puts " #{f}" } |
| 35 | + exit 1 |
| 36 | + else |
| 37 | + puts '✓ All files end with newline' |
| 38 | + end |
| 39 | +end |
| 40 | + |
| 41 | +desc 'Fix files missing final newline' |
| 42 | +task :fix_newlines do |
| 43 | + fixed_files = [] |
| 44 | + |
| 45 | + Dir.glob('**/*.{rb,rake,yml,yaml,md,gemspec,ru,erb,js,json}').each do |file| |
| 46 | + next if file.include?('vendor/') || file.include?('node_modules/') || file.include?('.git/') |
| 47 | + next if file.include?('pkg/') || file.include?('tmp/') || file.include?('coverage/') |
| 48 | + next unless File.file?(file) |
| 49 | + |
| 50 | + content = File.read(file) |
| 51 | + unless content.empty? || content.end_with?("\n") |
| 52 | + File.write(file, content + "\n") |
| 53 | + fixed_files << file |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + if fixed_files.any? |
| 58 | + puts "Fixed #{fixed_files.length} files:" |
| 59 | + fixed_files.each { |f| puts " #{f}" } |
| 60 | + else |
| 61 | + puts '✓ All files already end with newline' |
| 62 | + end |
| 63 | +end |
0 commit comments