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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/rubocop/socketry/config.yaml +5 -0
- data/lib/rubocop/socketry/style/global_exception_variables.rb +58 -0
- data/lib/rubocop/socketry/version.rb +1 -1
- data/lib/rubocop/socketry.rb +5 -0
- data/readme.md +4 -0
- data/releases.md +4 -0
- data.tar.gz.sig +0 -0
- metadata +2 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 535ee9879245dcd6059d6ad744862b405ef49eec9203d70c8b07e03ca77b3f47
|
|
4
|
+
data.tar.gz: ccd2df428d0cb2652beb7452f0e80952e3dbe0845adb41bcebea5d8d83c0bff6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
+
|
data/lib/rubocop/socketry.rb
CHANGED
|
@@ -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
|
+
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
|