error_highlight 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb083cc3162d22724aa838cfc6c8a6d3473436c9fa276d731c07a840bdab1466
4
- data.tar.gz: 3fb0a3ac24c77556f3343a9da1f43de5fdbe4a6bdf70d96a468cbcae129f3a1a
3
+ metadata.gz: 33a97fb38c24c4c0f5637b458a73525e7fcb3a1803e15d6478f009fd590afa0c
4
+ data.tar.gz: 16646ee686117659558ee48bb3b56f4fc48f01e7549b60240495f8f830794da8
5
5
  SHA512:
6
- metadata.gz: 2d40e91d23f06e0f62db5c9945dc27c96590c0a36448e987e7d2c23b8b5947a978ba2f7918bc5d934342075d3926a525e64df159120c0c0026f19b8bc4203f4d
7
- data.tar.gz: e7cb628e3cf5c60147a97ed96e02898ff9f444230aeed640c61c4998722e1cab6ea97149931340298ee525c72d5c2e663cc3f835fa116a9dbf22167ecad36e69
6
+ metadata.gz: 228531308329b907adb5d78c8c3b031b954b49338cb13d2fb31aa30919b870a61c3809b17b9a67f0d7449049c6c456f33d47e7a1abb7597aad45f09262a5682d
7
+ data.tar.gz: 293349ee401c24887dea1459b84dbf3b2b76a93934d02759b1ccf8ff3cdb376f66025dc664f16ab5bb484982661e3804078e474e7fadcfb602d3657f581f7095
@@ -13,9 +13,9 @@ jobs:
13
13
  runs-on: ubuntu-latest
14
14
  strategy:
15
15
  matrix:
16
- ruby: [ 'ruby-head', '3.1' ]
16
+ ruby: [ 'ruby-head', '3.1', '3.2' ]
17
17
  steps:
18
- - uses: actions/checkout@v3
18
+ - uses: actions/checkout@v4
19
19
  - uses: ruby/setup-ruby@v1
20
20
  with:
21
21
  ruby-version: ${{ matrix.ruby }}
@@ -98,9 +98,40 @@ module ErrorHighlight
98
98
  end
99
99
  end
100
100
 
101
+ OPT_GETCONSTANT_PATH = (RUBY_VERSION.split(".").map {|s| s.to_i } <=> [3, 2]) >= 0
102
+ private_constant :OPT_GETCONSTANT_PATH
103
+
101
104
  def spot
102
105
  return nil unless @node
103
106
 
107
+ if OPT_GETCONSTANT_PATH && @node.type == :COLON2
108
+ # In Ruby 3.2 or later, a nested constant access (like `Foo::Bar::Baz`)
109
+ # is compiled to one instruction (opt_getconstant_path).
110
+ # @node points to the node of the whole `Foo::Bar::Baz` even if `Foo`
111
+ # or `Foo::Bar` causes NameError.
112
+ # So we try to spot the sub-node that causes the NameError by using
113
+ # `NameError#name`.
114
+ subnodes = []
115
+ node = @node
116
+ while node.type == :COLON2
117
+ node2, const = node.children
118
+ subnodes << node if const == @name
119
+ node = node2
120
+ end
121
+ if node.type == :CONST || node.type == :COLON3
122
+ if node.children.first == @name
123
+ subnodes << node
124
+ end
125
+
126
+ # If we found only one sub-node whose name is equal to @name, use it
127
+ return nil if subnodes.size != 1
128
+ @node = subnodes.first
129
+ else
130
+ # Do nothing; opt_getconstant_path is used only when the const base is
131
+ # NODE_CONST (`Foo`) or NODE_COLON3 (`::Foo`)
132
+ end
133
+ end
134
+
104
135
  case @node.type
105
136
 
106
137
  when :CALL, :QCALL
@@ -37,6 +37,11 @@ module ErrorHighlight
37
37
  end
38
38
 
39
39
  NameError.prepend(CoreExt)
40
- TypeError.prepend(CoreExt)
41
- ArgumentError.prepend(CoreExt)
40
+
41
+ if Exception.method_defined?(:detailed_message)
42
+ # ErrorHighlight is enabled for TypeError and ArgumentError only when Exception#detailed_message is available.
43
+ # This is because changing ArgumentError#message is highly incompatible.
44
+ TypeError.prepend(CoreExt)
45
+ ArgumentError.prepend(CoreExt)
46
+ end
42
47
  end
@@ -1,3 +1,3 @@
1
1
  module ErrorHighlight
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: error_highlight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke Endoh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-08 00:00:00.000000000 Z
11
+ date: 2023-12-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: The gem enhances Exception#message by adding a short explanation where
14
14
  the exception is raised
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  - !ruby/object:Gem::Version
51
51
  version: '0'
52
52
  requirements: []
53
- rubygems_version: 3.3.7
53
+ rubygems_version: 3.5.0.dev
54
54
  signing_key:
55
55
  specification_version: 4
56
56
  summary: Shows a one-line code snippet with an underline in the error backtrace