solidarity 1.0.1 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11cfca9758e874328f377cf0657fbd8632f00302a3dd9f2ac7ee2f2d7fe5e4a9
4
- data.tar.gz: b23fff6c7471189cabad4c86ad1a2e043d9fbf606054efdaeef7cf28a0483f4b
3
+ metadata.gz: 76755d6fef094d3c28913dbf830403263f7f4444921810dec2f649dd0d8f9b95
4
+ data.tar.gz: 362d316be9571ed3fc2f8ccf81ccaa379aca7afd8c5863b183882068e17fb7dd
5
5
  SHA512:
6
- metadata.gz: eb1fc0758c2b738d5eda80f9f31e74d715172d01f6d198e18a659aea0ae8d7178f52802be66a1cb24ca9d6585e1c2a56f741ca86e0a119012afb545378848403
7
- data.tar.gz: bab76cdf46d6727eda7505ccc057a7c733cd8109d462ce50484effead92dec31b60a522c710b8bed351277db831b9e26c8dc87520152b5bfc01689e97734e06f
6
+ metadata.gz: 530e241f657241b50c07173cc66c3185f8c365261dc9f3e300668886e5fabf77219997b3129f921598fd25cf9582f45d3b6bdcdb8d5c076776f1075d4b279e94
7
+ data.tar.gz: 84ae73e8fbb8c612710248287fca173a738b74b811edde370b7d8e3f10116f3f5e8f43d47e5f3ff7b711a2afff279d8adcfa5d4dca853d8656868e7b4459812d
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
- # TODO: Add option parsing (e.g., using OptionParser)
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
- ast = Parser::CurrentRuby.parse(content)
19
- traverse_ast(ast, nil) # Pass initial context as nil
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
- # Remove Railroady's Rails-specific environment loading
13
- # options = OptionsStruct.new(root: project_path, verbose: false, output: nil)
14
- # diagram = ModelsDiagram.new(options)
15
- # diagram.process
16
- # diagram.generate
17
- # diagram.graph
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
@@ -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
- report += "Details: #{result[:details]}\n\n"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Solidarity
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidarity
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Your Name