rubocop-socketry 0.4.0 → 0.5.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: 65b739aa23100b336f58f95cb7e4095888d3c1700f04d91d429b015b5a2cabd0
4
- data.tar.gz: 484ec62657a1ed62f9598e064603086f377a9f7285bad489edbe0a6a5c2c8bc8
3
+ metadata.gz: 535ee9879245dcd6059d6ad744862b405ef49eec9203d70c8b07e03ca77b3f47
4
+ data.tar.gz: ccd2df428d0cb2652beb7452f0e80952e3dbe0845adb41bcebea5d8d83c0bff6
5
5
  SHA512:
6
- metadata.gz: bd7fe0c6568fe75068be352e44af560da13da579a9b55e0c46f8a4021f4146c2ecb4ab2305ac6e866d73afcd5343daceb172434e67192dba9d04a02b2c1b00b5
7
- data.tar.gz: 8a936f14c6b301d717298d1499458f10985a054bcba840062e73a3d34ecae4c150f57dd87ecc37c302755826e92d3c6d648c63385d2b408f44acd76bbe662305
6
+ metadata.gz: 40daa847ae78f73f5c9d2a2521d457a8de458985dded66fb6d06e027c9545ce5dd65eeb3edd38d202fa4c87941ecdc9eee9cacb12d5a231a222acee64ddad889
7
+ data.tar.gz: da03f159be23f86eaea8b43fdfba3f80eca079b8e9c410c8a1f9e66d7e3e09f10e784944f8904fd40cd9d28dd5cd9124d79402633079bc637e3a55652b9c8000
checksums.yaml.gz.sig CHANGED
Binary file
@@ -12,3 +12,8 @@ Layout/BlockDelimiterSpacing:
12
12
  Description: "Enforces consistent spacing before block delimiters."
13
13
  Enabled: true
14
14
  VersionAdded: "0.4.0"
15
+
16
+ Style/GlobalExceptionVariables:
17
+ Description: "Warns against using global exception variables like $! and $@."
18
+ Enabled: true
19
+ VersionAdded: "0.5.0"
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2025, by Samuel Williams.
5
+
6
+ require "rubocop"
7
+
8
+ module RuboCop
9
+ module Socketry
10
+ module Style
11
+ # A RuboCop cop that warns against using global exception variables.
12
+ #
13
+ # This cop discourages the use of:
14
+ # - `$!` (last exception)
15
+ # - `$@` (backtrace of last exception)
16
+ # - `$ERROR_INFO` (English name for `$!`)
17
+ # - `$ERROR_POSITION` (English name for `$@`)
18
+ #
19
+ # These global variables are implicit and can make code harder to understand.
20
+ # Instead, use explicit exception handling with rescue blocks and local variables.
21
+ #
22
+ # @example
23
+ # # bad
24
+ # begin
25
+ # risky_operation
26
+ # rescue
27
+ # puts $!.message
28
+ # puts $@.first
29
+ # end
30
+ #
31
+ # # good
32
+ # begin
33
+ # risky_operation
34
+ # rescue => error
35
+ # puts error.message
36
+ # puts error.backtrace.first
37
+ # end
38
+ class GlobalExceptionVariables < RuboCop::Cop::Base
39
+ MSG = "Avoid using global exception variable `%<variable>s`. " \
40
+ "Use explicit exception handling with `rescue => error` instead."
41
+
42
+ EXCEPTION_VARIABLES = %i[$! $@ $ERROR_INFO $ERROR_POSITION].freeze
43
+
44
+ def on_gvar(node)
45
+ variable_name = node.children.first
46
+
47
+ return unless EXCEPTION_VARIABLES.include?(variable_name)
48
+
49
+ add_offense(
50
+ node,
51
+ message: format(MSG, variable: variable_name)
52
+ )
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+
@@ -5,6 +5,6 @@
5
5
 
6
6
  module RuboCop
7
7
  module Socketry
8
- VERSION = "0.4.0"
8
+ VERSION = "0.5.0"
9
9
  end
10
10
  end
@@ -7,6 +7,7 @@ require_relative "socketry/version"
7
7
  require_relative "socketry/plugin"
8
8
  require_relative "socketry/layout/consistent_blank_line_indentation"
9
9
  require_relative "socketry/layout/block_delimiter_spacing"
10
+ require_relative "socketry/style/global_exception_variables"
10
11
 
11
12
  # @namespace
12
13
  module RuboCop
@@ -15,5 +16,9 @@ module RuboCop
15
16
  # @namespace
16
17
  module Layout
17
18
  end
19
+
20
+ # @namespace
21
+ module Style
22
+ end
18
23
  end
19
24
  end
data/readme.md CHANGED
@@ -27,6 +27,10 @@ Layout/ConsistentBlankLineIndentation:
27
27
 
28
28
  Please see the [project releases](https://socketry.github.io/rubocop-socketry/releases/index) for all releases.
29
29
 
30
+ ### v0.5.0
31
+
32
+ - Added `Style/GlobalExceptionVariables` cop to warn against using global exception variables (`$!`, `$@`, `$ERROR_INFO`, `$ERROR_POSITION`).
33
+
30
34
  ### v0.4.0
31
35
 
32
36
  - Added `Layout/BlockDelimiterSpacing` cop to enforce consistent spacing before block delimiters.
data/releases.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Releases
2
2
 
3
+ ## v0.5.0
4
+
5
+ - Added `Style/GlobalExceptionVariables` cop to warn against using global exception variables (`$!`, `$@`, `$ERROR_INFO`, `$ERROR_POSITION`).
6
+
3
7
  ## v0.4.0
4
8
 
5
9
  - Added `Layout/BlockDelimiterSpacing` cop to enforce consistent spacing before block delimiters.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-socketry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -76,6 +76,7 @@ files:
76
76
  - lib/rubocop/socketry/layout/block_delimiter_spacing.rb
77
77
  - lib/rubocop/socketry/layout/consistent_blank_line_indentation.rb
78
78
  - lib/rubocop/socketry/plugin.rb
79
+ - lib/rubocop/socketry/style/global_exception_variables.rb
79
80
  - lib/rubocop/socketry/version.rb
80
81
  - license.md
81
82
  - readme.md
metadata.gz.sig CHANGED
Binary file