rubosquad 0.1.0
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.
- checksums.yaml +7 -0
- data/bin/rubosquad +6 -0
- data/lib/rubosquad.rb +79 -0
- metadata +59 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 703916ceaa4f309f64ef44eafdb3719c5e0951533d626e3c70ea8373c1922013
|
|
4
|
+
data.tar.gz: 8d3e8703e33ba946ce9b4d44682648f9e5f43eea1c4a46bd8ced66220d599368
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 99c82cfa77be12ceb60eac05e5d74296c4a300923c46f6193e400b8b821661c30871d5ce685e7ccabf9a84724e8642895eabce1cb50814ba166cfd248942321e
|
|
7
|
+
data.tar.gz: fa45abefc6483e9dfdc11172ec3ad9531c6a024e1ed0714f17a74fa279f7e83c76edf5dde0c0f3da2c2d4179f2a5f24b92849366ff300fe97c06cf5e4320cb60
|
data/bin/rubosquad
ADDED
data/lib/rubosquad.rb
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'open3'
|
|
4
|
+
require 'set'
|
|
5
|
+
# Get the list of changed Ruby files, excluding this script
|
|
6
|
+
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 }
|
|
11
|
+
|
|
12
|
+
if changed_files.empty?
|
|
13
|
+
puts 'No Ruby files have changed.'
|
|
14
|
+
exit 0
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
puts 'Running Rubocop on changed files:'
|
|
18
|
+
changed_files.each { |file| puts "- #{file}" }
|
|
19
|
+
|
|
20
|
+
# Check for available RuboCop extensions
|
|
21
|
+
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") }
|
|
23
|
+
|
|
24
|
+
# Construct the RuboCop command
|
|
25
|
+
command = "rubocop -A --format offenses --format simple #{available_extensions.map do |ext|
|
|
26
|
+
"--require #{ext}"
|
|
27
|
+
end.join(' ')} #{changed_files.join(' ')}"
|
|
28
|
+
stdout, stderr, status = Open3.capture3(command)
|
|
29
|
+
|
|
30
|
+
puts "\nRubocop Output:"
|
|
31
|
+
|
|
32
|
+
# Process and colorize output
|
|
33
|
+
processed_output = ''
|
|
34
|
+
seen_files = Set.new
|
|
35
|
+
current_file = nil
|
|
36
|
+
|
|
37
|
+
stdout.each_line do |line|
|
|
38
|
+
if line.start_with?('==')
|
|
39
|
+
file_path = line.strip.gsub(/^==\s*|\s*==$/, '')
|
|
40
|
+
current_file = file_path
|
|
41
|
+
processed_output += if seen_files.add?(file_path)
|
|
42
|
+
"\n\e[36m#{line}\e[0m"
|
|
43
|
+
else
|
|
44
|
+
"\n#{line}"
|
|
45
|
+
end
|
|
46
|
+
elsif line.match?(/^[A-Z]:/)
|
|
47
|
+
parts = line.split(':')
|
|
48
|
+
offense_type = parts.shift
|
|
49
|
+
line_col = parts.shift(2).map(&:strip).join(':')
|
|
50
|
+
message = parts.join(':').strip
|
|
51
|
+
processed_output += "[#{current_file}:#{line_col}] - #{offense_type}: #{message}\n"
|
|
52
|
+
else
|
|
53
|
+
processed_output += line
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
puts processed_output
|
|
58
|
+
|
|
59
|
+
if status.success?
|
|
60
|
+
puts "\nRubocop auto-corrections complete."
|
|
61
|
+
else
|
|
62
|
+
puts "\nRubocop completed with offenses:"
|
|
63
|
+
|
|
64
|
+
offenses = stdout.scan(/(\d+) offense.* detected/)
|
|
65
|
+
total_offenses = offenses.flatten.map(&:to_i).sum
|
|
66
|
+
|
|
67
|
+
puts "Files inspected: #{stdout[/(\d+) files? inspected/, 1] || 'Unknown'}"
|
|
68
|
+
puts "Total offenses detected: #{total_offenses}"
|
|
69
|
+
|
|
70
|
+
unless stderr.strip.empty?
|
|
71
|
+
puts "\nStandard error:"
|
|
72
|
+
puts stderr
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
puts "\nRuboCop extensions used: #{available_extensions.join(', ')}"
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rubosquad
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- LucasWaki
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-09-06 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rubocop
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.0'
|
|
27
|
+
description: A tool to run RuboCop on changed Ruby files in a Git repository
|
|
28
|
+
email: lucas.waki@cloudwalk.io
|
|
29
|
+
executables:
|
|
30
|
+
- rubosquad
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- bin/rubosquad
|
|
35
|
+
- lib/rubosquad.rb
|
|
36
|
+
homepage: https://github.com/cw-lucaswaki/rubosquad
|
|
37
|
+
licenses:
|
|
38
|
+
- MIT
|
|
39
|
+
metadata: {}
|
|
40
|
+
post_install_message:
|
|
41
|
+
rdoc_options: []
|
|
42
|
+
require_paths:
|
|
43
|
+
- lib
|
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '0'
|
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
requirements: []
|
|
55
|
+
rubygems_version: 3.3.7
|
|
56
|
+
signing_key:
|
|
57
|
+
specification_version: 4
|
|
58
|
+
summary: Run RuboCop on changed files
|
|
59
|
+
test_files: []
|