sloprb 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58e1a220d3b716251ffc2d18e26eba840c87010b06c87d2551f5a3838dc9bc85
4
- data.tar.gz: e595902a25e97cc83b841689c814e85d32bb90ba657d57ab0b0c7668cb748b84
3
+ metadata.gz: 48bfebd2f130215caf80aa5f26b9f242f3b417005e31eb445bd96edff9fef59a
4
+ data.tar.gz: 9298cdefb85420447fd2ec3724379fbb61d2e43836ecf02ecc57eefae7527024
5
5
  SHA512:
6
- metadata.gz: ade7937bcab79f4073a295a2942c1b996779fdad9d47f6d274f8b34ff1355c3f7a57136d212f510274fec12c1622801236dd336e0a6e817941ad56696b5d5740
7
- data.tar.gz: 2cc575c4e56be00cbb73ef57f8e8bb7b5f3ce46188eeeeecbff18ea121ba457405535872a4975a86eb5f153adecbbcbf1b428426b1b0766acbfb85dd867cf693
6
+ metadata.gz: af0fd0c23ddcb84a259de9b0d64e8541c3efae31326c00fb7de16689c63f2ddb483fd64ac14b4f83dc188bee1baf984523ecf6c79eb38f808c0a162e29147b04
7
+ data.tar.gz: 96f54a74ea445466cb453f2a12d4ef328fc13b3c1e275c199d6c55f853c169ef27c89d4e88ecd4a054047630ed0b6b7091a1ac19c51c131d799ab7a3d7fea543
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.2.0 (2026-06-05)
6
+
7
+ - Use `#source_transform` and Prism for Typoeater.
8
+
9
+ Catch syntax errors before trying to load files to not break the loading logic.
10
+
5
11
  ## 0.1.1 (2026-05-28)
6
12
 
7
13
  - Get the source path from SyntaxError in Typoeater.
@@ -69,7 +69,7 @@ module Sloprb
69
69
  if current_method
70
70
  bodies[current_method] = current_lines.join.strip
71
71
  end
72
- current_method = line.strip.sub(/^###\s+/, "")
72
+ current_method = line.strip.sub(/^###\s+/, "").sub(/\(.*\)$/, "").sub(/^self\./, "")
73
73
  current_lines = []
74
74
  else
75
75
  current_lines << line
data/lib/sloprb/parser.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Sloprb
4
4
  module Parser
5
- SlopMethod = Data.define(:name, :parameters, :start_offset, :end_offset, :leading_comments, :enclosing_context, :start_column, :body_sketch)
5
+ SlopMethod = Data.define(:name, :parameters, :receiver, :start_offset, :end_offset, :leading_comments, :enclosing_context, :start_column, :body_sketch)
6
6
 
7
7
  class Visitor < Prism::Visitor
8
8
  attr_reader :slop_methods
@@ -43,6 +43,7 @@ module Sloprb
43
43
  @slop_methods << SlopMethod.new(
44
44
  name: node.name.to_s,
45
45
  parameters: params,
46
+ receiver: node.receiver&.slice,
46
47
  start_offset: node.location.start_offset,
47
48
  end_offset: node.location.end_offset,
48
49
  leading_comments: leading,
@@ -40,7 +40,8 @@ module Sloprb
40
40
  indented_body = body.lines.map { |line| "#{indent}#{line}" }.join.rstrip
41
41
 
42
42
  params = method.parameters || ""
43
- replacement = "def #{method.name}#{params}\n#{indented_body}\n#{" " * method.start_column}end"
43
+ receiver = method.receiver ? "#{method.receiver}." : ""
44
+ replacement = "def #{receiver}#{method.name}#{params}\n#{indented_body}\n#{" " * method.start_column}end"
44
45
 
45
46
  result[method.start_offset...method.end_offset] = replacement
46
47
  end
@@ -16,11 +16,10 @@ module Sloprb
16
16
  PROMPT
17
17
 
18
18
  class << self
19
- def call(path, error, chat: nil)
19
+ def call(path, error_context, chat: nil)
20
20
  chat ||= default_chat
21
21
 
22
22
  source = File.read(path)
23
- error_context = error.respond_to?(:detailed_message) ? error.detailed_message(highlight: false) : error.message
24
23
 
25
24
  user_prompt = <<~PROMPT
26
25
  Here is the Ruby source file with a syntax error:
@@ -51,22 +50,21 @@ module Sloprb
51
50
  def register_hook
52
51
  require "require-hooks/setup"
53
52
 
54
- RequireHooks.around_load do |path, &load_block|
55
- load_block.call
56
- rescue ::SyntaxError => original_error
57
- error_path = original_error.path
58
- corrected = Typoeater.call(error_path, original_error)
59
- raise original_error unless corrected
53
+ RequireHooks.source_transform do |path, source|
54
+ result = Prism.parse_file(path)
55
+ next unless result.errors.any?
60
56
 
61
- File.write(error_path, corrected)
57
+ warn "[sloprb] invalid syntax in #{path}, fixing..."
62
58
 
63
- warn "[sloprb] auto-corrected syntax error in #{error_path}"
59
+ corrected = Typoeater.call(path, result.errors_format)
60
+ # Let it fail through
61
+ next unless corrected
64
62
 
65
- begin
66
- load(error_path)
67
- rescue ::SyntaxError
68
- raise original_error
69
- end
63
+ File.write(path, corrected)
64
+
65
+ warn "[sloprb] auto-corrected syntax error in #{path}"
66
+
67
+ corrected
70
68
  end
71
69
  end
72
70
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sloprb # :nodoc:
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sloprb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vova Dem
@@ -43,14 +43,14 @@ dependencies:
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: '2.6'
46
+ version: '2.0'
47
47
  type: :development
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: '2.6'
53
+ version: '2.0'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: rake
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - ">="
117
117
  - !ruby/object:Gem::Version
118
- version: '3.4'
118
+ version: '3.3'
119
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - ">="