rubosquad 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubosquad.rb +72 -10
  3. metadata +5 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 703916ceaa4f309f64ef44eafdb3719c5e0951533d626e3c70ea8373c1922013
4
- data.tar.gz: 8d3e8703e33ba946ce9b4d44682648f9e5f43eea1c4a46bd8ced66220d599368
3
+ metadata.gz: ea0148cd8d05e66b5990557a84a80ff89fa053929e4bbec510aafbc12007e9ff
4
+ data.tar.gz: fd638cb0a18a6a1b0dc77495b38c9b55dadee1045fbba4f79a6ea74b4c59bb62
5
5
  SHA512:
6
- metadata.gz: 99c82cfa77be12ceb60eac05e5d74296c4a300923c46f6193e400b8b821661c30871d5ce685e7ccabf9a84724e8642895eabce1cb50814ba166cfd248942321e
7
- data.tar.gz: fa45abefc6483e9dfdc11172ec3ad9531c6a024e1ed0714f17a74fa279f7e83c76edf5dde0c0f3da2c2d4179f2a5f24b92849366ff300fe97c06cf5e4320cb60
6
+ metadata.gz: e7878218fff87254f16cd8e6c54613301ca65c5ccf39cffd0b420cb0bb6eb7411a3bdf0991436acb634b353e3f2aa86726f9e1176ffc537b97b02e946b5dc7b2
7
+ data.tar.gz: d89bd634df027b5ce0cc35d9e91e3349d5ef936d15cb9883eb500ba8fda11faeee33f0de7c7e4504bb8f0d7bd21ad37de58078ce94c5b4a76fcfbb48033ad6a0
data/lib/rubosquad.rb CHANGED
@@ -2,32 +2,80 @@
2
2
 
3
3
  require 'open3'
4
4
  require 'set'
5
- # Get the list of changed Ruby files, excluding this script
5
+ require 'optparse'
6
+
7
+ # Get the list of changed Ruby files in the current branch compared to main
6
8
  module Rubosquad
7
- class CLI
8
- def self.run
9
- script_name = File.basename(__FILE__)
10
- changed_files = `git diff --name-only main | grep '\.rb$'`.split("\n").reject { |file| file == script_name }
9
+ class CLI
10
+ def self.run
11
+ options = {}
12
+ OptionParser.new do |opts|
13
+ opts.banner = 'Usage: rubosquad [options]'
14
+ opts.on('-a', '--auto-correct', 'Run with rubocop -a instead of -A') do
15
+ options[:auto_correct] = true
16
+ end
17
+ end.parse!
18
+
19
+ # Get the base branch (try main, then master, then origin/main, then origin/master)
20
+ base_branch = detect_base_branch
21
+
22
+ unless base_branch
23
+ puts 'Error: Could not find main or master branch.'
24
+ exit 1
25
+ end
26
+
27
+ # Get current branch name
28
+ current_branch = `git rev-parse --abbrev-ref HEAD`.strip
29
+
30
+ if current_branch == base_branch
31
+ puts "Warning: You are on the #{base_branch} branch. Comparing working directory changes."
32
+ # Compare working directory + staged changes against HEAD
33
+ changed_files = `git diff --name-only HEAD`.split("\n")
34
+ changed_files += `git diff --name-only --cached`.split("\n")
35
+ changed_files = changed_files.uniq.grep(/\.rb$/)
36
+ else
37
+ # Compare current branch against base branch (all commits since divergence)
38
+ changed_files = `git diff --name-only #{base_branch}...HEAD`.split("\n").grep(/\.rb$/)
39
+ end
40
+
41
+ # Filter out deleted files and files that don't exist
42
+ changed_files = changed_files.select { |file| File.exist?(file) }
11
43
 
12
44
  if changed_files.empty?
13
45
  puts 'No Ruby files have changed.'
14
46
  exit 0
15
47
  end
16
48
 
17
- puts 'Running Rubocop on changed files:'
18
- changed_files.each { |file| puts "- #{file}" }
49
+ comparison_info = if current_branch == base_branch
50
+ "working directory changes on #{base_branch}"
51
+ else
52
+ "#{current_branch} vs #{base_branch}"
53
+ end
19
54
 
20
- # Check for available RuboCop extensions
55
+ puts "\nRunning Rubocop on changed files (#{comparison_info}):"
56
+ changed_files.each { |file| puts " - #{file}" }
57
+ puts
58
+
59
+ # Check for available RuboCop extensions that can actually be loaded
21
60
  extensions = %w[rubocop-factory_bot rubocop-rails rubocop-rspec rubocop-rspec_rails]
22
- available_extensions = extensions.select { |ext| system("gem list -i #{ext} > /dev/null 2>&1") }
61
+ available_extensions = extensions.select do |ext|
62
+ require ext
63
+ true
64
+ rescue LoadError
65
+ false
66
+ end
23
67
 
24
68
  # Construct the RuboCop command
25
- command = "rubocop -A --format offenses --format simple #{available_extensions.map do |ext|
69
+
70
+ rubocop_option = options[:auto_correct] ? '-a' : '-A'
71
+ command = "rubocop #{rubocop_option} --format offenses --format simple #{available_extensions.map do |ext|
26
72
  "--require #{ext}"
27
73
  end.join(' ')} #{changed_files.join(' ')}"
74
+
28
75
  stdout, stderr, status = Open3.capture3(command)
29
76
 
30
77
  puts "\nRubocop Output:"
78
+ puts '==Error type: Legend: C = Convention, W = Warning, E = Error, F = Fatal=='
31
79
 
32
80
  # Process and colorize output
33
81
  processed_output = ''
@@ -75,5 +123,19 @@ module Rubosquad
75
123
 
76
124
  puts "\nRuboCop extensions used: #{available_extensions.join(', ')}"
77
125
  end
126
+
127
+ # Detect the base branch to compare against
128
+ def self.detect_base_branch
129
+ # Try different possible base branch names
130
+ candidates = ['main', 'master', 'origin/main', 'origin/master']
131
+
132
+ candidates.each do |branch|
133
+ # Check if the branch exists
134
+ result = `git rev-parse --verify #{branch} 2>/dev/null`.strip
135
+ return branch unless result.empty?
136
+ end
137
+
138
+ nil
139
+ end
78
140
  end
79
141
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubosquad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - LucasWaki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-06 00:00:00.000000000 Z
11
+ date: 2025-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -24,7 +24,8 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
- description: A tool to run RuboCop on changed Ruby files in a Git repository
27
+ description: A tool to run RuboCop with auto-correct on Ruby files changed in your
28
+ Git branch compared to main
28
29
  email: lucas.waki@cloudwalk.io
29
30
  executables:
30
31
  - rubosquad
@@ -55,5 +56,5 @@ requirements: []
55
56
  rubygems_version: 3.3.7
56
57
  signing_key:
57
58
  specification_version: 4
58
- summary: Run RuboCop on changed files
59
+ summary: Run RuboCop on changed files in your branch/PR
59
60
  test_files: []