solidarity 1.0.1 → 1.0.2
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 +4 -4
- data/exe/solidarity +21 -4
- data/lib/solidarity/ast_processor.rb +21 -3
- data/lib/solidarity/railroady_runner.rb +10 -8
- data/lib/solidarity/reporter.rb +12 -2
- data/lib/solidarity/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9da1a43ee95a6830a9cf80311f4e4f3ba226e5fa07c1e47de8af77006906db9b
|
|
4
|
+
data.tar.gz: e09c1317b1da612d1c325fcabb781408d2ad77a779bacb942d03eff81ca2c273
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 53284a3396d78311d11e86fa771dd4fd10630da1df562022a6f1a028b860cfb06406c0ee4cc7dafff9dfcc3ad3d09a2763904a87729414c82be4012028836ec1
|
|
7
|
+
data.tar.gz: d5caf90cca1bb333bb30dd6849359c85fea19a99404e9ab2744dcfca3dcf0189f1e8038e83586f85739d92e48d021b3f6a9e0ab4eb65757c23fae782b1025c68
|
data/exe/solidarity
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
3
|
require "solidarity"
|
|
4
|
+
require 'optparse'
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
options = {}
|
|
7
|
+
OptionParser.new do |opts|
|
|
8
|
+
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [options] <path_to_ruby_project>"
|
|
9
|
+
|
|
10
|
+
opts.on("--with-specs", "Include spec/test files in the analysis") do
|
|
11
|
+
options[:with_specs] = true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
opts.on("--with-srp-details", "Include detailed SRP scores in the report") do
|
|
15
|
+
options[:with_srp_details] = true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
opts.on("-h", "--help", "Prints this help") do
|
|
19
|
+
puts opts
|
|
20
|
+
exit
|
|
21
|
+
end
|
|
22
|
+
end.parse!
|
|
6
23
|
|
|
7
24
|
project_path = ARGV[0]
|
|
8
25
|
|
|
9
26
|
unless project_path
|
|
10
|
-
warn "Usage: #{File.basename($PROGRAM_NAME)} <path_to_ruby_project>"
|
|
27
|
+
warn "Usage: #{File.basename($PROGRAM_NAME)} [options] <path_to_ruby_project>"
|
|
11
28
|
exit 1
|
|
12
29
|
end
|
|
13
30
|
|
|
14
31
|
begin
|
|
15
|
-
graph = Solidarity::RailRoadyRunner.run(project_path)
|
|
32
|
+
graph = Solidarity::RailRoadyRunner.run(project_path, with_specs: options[:with_specs])
|
|
16
33
|
solid_results = Solidarity::SolidEvaluator.new(graph).evaluate_all
|
|
17
|
-
report = Solidarity::Reporter.generate_report(solid_results)
|
|
34
|
+
report = Solidarity::Reporter.generate_report(solid_results, with_srp_details: options[:with_srp_details])
|
|
18
35
|
puts report
|
|
19
36
|
rescue => e
|
|
20
37
|
warn "Error: #{e.message}"
|
|
@@ -14,9 +14,27 @@ module Solidarity
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def process_file(file_path)
|
|
17
|
-
content = File.read(file_path)
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
content = File.read(file_path, encoding: 'UTF-8')
|
|
18
|
+
begin
|
|
19
|
+
ast = Parser::CurrentRuby.parse(content)
|
|
20
|
+
traverse_ast(ast, nil) # Pass initial context as nil
|
|
21
|
+
rescue Parser::SyntaxError => e
|
|
22
|
+
warn "Warning: Could not parse #{file_path} due to syntax error: #{e.message}"
|
|
23
|
+
nil # Return nil to indicate parsing failed
|
|
24
|
+
rescue EncodingError => e
|
|
25
|
+
warn "Warning: Could not read #{file_path} due to encoding error: #{e.message}. Attempting to force encoding to UTF-8."
|
|
26
|
+
begin
|
|
27
|
+
content.force_encoding('UTF-8')
|
|
28
|
+
ast = Parser::CurrentRuby.parse(content)
|
|
29
|
+
traverse_ast(ast, nil)
|
|
30
|
+
rescue Parser::SyntaxError => e
|
|
31
|
+
warn "Warning: Could not parse #{file_path} after forcing encoding due to syntax error: #{e.message}"
|
|
32
|
+
nil
|
|
33
|
+
rescue EncodingError => e
|
|
34
|
+
warn "Warning: Could not read #{file_path} after forcing encoding due to encoding error: #{e.message}"
|
|
35
|
+
nil
|
|
36
|
+
end
|
|
37
|
+
end
|
|
20
38
|
end
|
|
21
39
|
|
|
22
40
|
private
|
|
@@ -4,19 +4,21 @@ require_relative 'ast_processor' # Add this line
|
|
|
4
4
|
|
|
5
5
|
module Solidarity
|
|
6
6
|
class RailRoadyRunner
|
|
7
|
-
def self.run(project_path)
|
|
7
|
+
def self.run(project_path, with_specs: false)
|
|
8
8
|
unless File.directory?(project_path)
|
|
9
9
|
raise ArgumentError, "Project path '#{project_path}' is not a valid directory."
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
all_ruby_files = Dir.glob(File.join(project_path, "**", "*.rb"))
|
|
13
|
+
|
|
14
|
+
ruby_files = if with_specs
|
|
15
|
+
all_ruby_files
|
|
16
|
+
else
|
|
17
|
+
all_ruby_files.reject do |file|
|
|
18
|
+
file.include?("/test/") || file.include?("/spec/") || file.end_with?("_test.rb") || file.end_with?("_spec.rb")
|
|
19
|
+
end
|
|
20
|
+
end
|
|
18
21
|
|
|
19
|
-
ruby_files = Dir.glob(File.join(project_path, "**", "*.rb"))
|
|
20
22
|
ast_data = process_ruby_files_with_ast(ruby_files)
|
|
21
23
|
Solidarity::Graph.from_ast_data(ast_data)
|
|
22
24
|
end
|
data/lib/solidarity/reporter.rb
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
module Solidarity
|
|
2
2
|
class Reporter
|
|
3
|
-
def self.generate_report(solid_results)
|
|
3
|
+
def self.generate_report(solid_results, with_srp_details: false)
|
|
4
4
|
report = "# Ruby SOLID Principles Analysis Report\n\n"
|
|
5
5
|
|
|
6
6
|
solid_results.each do |principle, result|
|
|
7
7
|
report += "## #{principle.to_s.upcase} - #{full_principle_name(principle)}\n"
|
|
8
8
|
report += "Score: #{result[:score].round(2)}/100\n"
|
|
9
|
-
|
|
9
|
+
if principle == :srp && with_srp_details
|
|
10
|
+
report += "Details:\n"
|
|
11
|
+
result[:details].each do |class_name, score|
|
|
12
|
+
report += " - #{class_name}: #{score}/100\n"
|
|
13
|
+
end
|
|
14
|
+
elsif principle == :srp && !with_srp_details
|
|
15
|
+
report += "Details: Omitted for brevity. Use --with-srp-details to see per-class scores.\n"
|
|
16
|
+
else
|
|
17
|
+
report += "Details: #{result[:details]}\n"
|
|
18
|
+
end
|
|
19
|
+
report += "\n"
|
|
10
20
|
end
|
|
11
21
|
|
|
12
22
|
report
|
data/lib/solidarity/version.rb
CHANGED