barsoom_utils 0.2.0.63 → 0.2.0.64
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
- data/.gitignore +2 -6
- data/Gemfile +1 -0
- data/VERSION +1 -1
- data/lib/barsoom_utils/exception_notifier.rb +0 -5
- data/lib/barsoom_utils/rubocop/cop/barsoom/trailing_comma_in_arguments.rb +105 -0
- data/lib/barsoom_utils/rubocop.rb +3 -0
- data/shared_rubocop.yml +6 -3
- data/spec/exception_notifier_spec.rb +0 -22
- data/spec/rubocop/cop/barsoom/trailing_comma_in_arguments_spec.rb +179 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2cccdc6fc4265ea2cd6ae9f045fef87d7ef796ca5b330c35abff20006872c59d
|
|
4
|
+
data.tar.gz: b4fdf5c17d092dad93656925955f87cbbd0590307269ae7acea6a30b49127474
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7cc2fec26acb707bcff01af5f29ea62db07b41c90f157687d9591a452fe3281a8a3a7111063418daeb4da0560621995b58412db59c94691e33c7d0949a519e6c
|
|
7
|
+
data.tar.gz: d44aebbadb9488b219d881a61f35da778168894e2b4cf23468f34b82ed02741dd02c112c85fae1850b11e8875b24ba4db16dfc778c1267d397bf65eea989d3dc
|
data/.gitignore
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
|
2
|
-
#
|
|
3
|
-
# If you find yourself ignoring temporary files generated by your text editor
|
|
4
|
-
# or operating system, you probably want to add a global ignore instead:
|
|
5
|
-
# git config --global core.excludesfile '~/.gitignore_global'
|
|
6
|
-
|
|
7
1
|
# Ignore bundler config.
|
|
8
2
|
/.bundle
|
|
9
3
|
|
|
@@ -12,3 +6,5 @@
|
|
|
12
6
|
|
|
13
7
|
Gemfile.lock
|
|
14
8
|
*.gem
|
|
9
|
+
|
|
10
|
+
.claude
|
data/Gemfile
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.2.0.
|
|
1
|
+
0.2.0.64
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Barsoom
|
|
6
|
+
# Require a trailing comma in multiline method arguments when the
|
|
7
|
+
# closing `)` is on its own line. Disallow it when `)` is on the
|
|
8
|
+
# same line as the last argument.
|
|
9
|
+
#
|
|
10
|
+
# This differs from the built-in `Style/TrailingCommaInArguments`:
|
|
11
|
+
# - `comma` disallows trailing commas when args share a line.
|
|
12
|
+
# - `consistent_comma` requires them even when `)` is on the same line.
|
|
13
|
+
#
|
|
14
|
+
# @example
|
|
15
|
+
# # good
|
|
16
|
+
# foo(
|
|
17
|
+
# a,
|
|
18
|
+
# b,
|
|
19
|
+
# )
|
|
20
|
+
#
|
|
21
|
+
# # good – args sharing a line is fine as long as there's a trailing comma
|
|
22
|
+
# foo(
|
|
23
|
+
# a, b,
|
|
24
|
+
# )
|
|
25
|
+
#
|
|
26
|
+
# # good – single-line
|
|
27
|
+
# foo(a, b)
|
|
28
|
+
#
|
|
29
|
+
# # good – closing paren on same line as last arg
|
|
30
|
+
# foo(
|
|
31
|
+
# a, b)
|
|
32
|
+
#
|
|
33
|
+
# # bad – missing trailing comma
|
|
34
|
+
# foo(
|
|
35
|
+
# a,
|
|
36
|
+
# b
|
|
37
|
+
# )
|
|
38
|
+
#
|
|
39
|
+
# # bad – trailing comma but closing paren on same line
|
|
40
|
+
# foo(
|
|
41
|
+
# a, b,)
|
|
42
|
+
class TrailingCommaInArguments < Base
|
|
43
|
+
extend AutoCorrector
|
|
44
|
+
|
|
45
|
+
MSG_MISSING = "Put a trailing comma after the last argument when `)` is on the next line."
|
|
46
|
+
MSG_UNWANTED = "Remove the trailing comma when `)` is on the same line as the last argument."
|
|
47
|
+
|
|
48
|
+
def on_send(node)
|
|
49
|
+
check(node)
|
|
50
|
+
end
|
|
51
|
+
alias on_csend on_send
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def check(node)
|
|
56
|
+
return unless node.arguments? && node.parenthesized?
|
|
57
|
+
|
|
58
|
+
close_paren_line = node.source_range.end.line
|
|
59
|
+
last_arg = node.last_argument
|
|
60
|
+
last_arg_line = last_arg.source_range.end.line
|
|
61
|
+
|
|
62
|
+
return if close_paren_line == last_arg_line && close_paren_line == node.first_argument.first_line
|
|
63
|
+
|
|
64
|
+
# A trailing comma after `&` is a syntax error.
|
|
65
|
+
return if last_arg.block_pass_type?
|
|
66
|
+
|
|
67
|
+
trailing_comma = trailing_comma_token(node)
|
|
68
|
+
paren_on_own_line = close_paren_line > last_arg_line
|
|
69
|
+
|
|
70
|
+
if paren_on_own_line && !trailing_comma
|
|
71
|
+
add_offense_missing(last_arg)
|
|
72
|
+
elsif !paren_on_own_line && trailing_comma
|
|
73
|
+
add_offense_unwanted(trailing_comma)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def add_offense_missing(last_arg)
|
|
78
|
+
add_offense(last_arg, message: MSG_MISSING) do |corrector|
|
|
79
|
+
corrector.insert_after(last_arg, ",")
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def add_offense_unwanted(comma_token)
|
|
84
|
+
range = comma_token.pos
|
|
85
|
+
add_offense(range, message: MSG_UNWANTED) do |corrector|
|
|
86
|
+
corrector.remove(range)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def trailing_comma_token(node)
|
|
91
|
+
close_paren_idx = node.loc.end
|
|
92
|
+
tokens = processed_source.tokens
|
|
93
|
+
|
|
94
|
+
# Find the non-whitespace token just before the closing paren.
|
|
95
|
+
tokens.reverse_each do |token|
|
|
96
|
+
next if token.pos.end_pos > close_paren_idx.begin_pos
|
|
97
|
+
next if token.comment? || token.type == :tNL
|
|
98
|
+
return token if token.comma?
|
|
99
|
+
return nil
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
data/shared_rubocop.yml
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Configuration for the Rubocop code linting tool. See README.
|
|
2
2
|
|
|
3
|
+
require:
|
|
4
|
+
- barsoom_utils/rubocop
|
|
5
|
+
|
|
3
6
|
AllCops:
|
|
4
7
|
ActiveSupportExtensionsEnabled: true
|
|
5
8
|
DisabledByDefault: true
|
|
@@ -228,10 +231,10 @@ Style/RedundantBegin:
|
|
|
228
231
|
Style/MethodCallWithoutArgsParentheses:
|
|
229
232
|
Enabled: true
|
|
230
233
|
|
|
231
|
-
#
|
|
232
|
-
|
|
234
|
+
# Replaces Style/TrailingCommaInArguments, which doesn't support our preferred style:
|
|
235
|
+
# require trailing comma only when `)` is on its own line.
|
|
236
|
+
Barsoom/TrailingCommaInArguments:
|
|
233
237
|
Enabled: true
|
|
234
|
-
EnforcedStyleForMultiline: comma
|
|
235
238
|
|
|
236
239
|
# https://docs.rubocop.org/rubocop/cops_style.html#stylereturnnilinpredicatemethoddefinition
|
|
237
240
|
Style/ReturnNilInPredicateMethodDefinition:
|
|
@@ -73,26 +73,4 @@ RSpec.describe BarsoomUtils::ExceptionNotifier do
|
|
|
73
73
|
)
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
|
-
|
|
77
|
-
describe ".run_with_context" do
|
|
78
|
-
it "updates the context just within the block" do
|
|
79
|
-
allow(Honeybadger).to receive(:context).and_call_original
|
|
80
|
-
Honeybadger.context({ my_old_context: "hello" })
|
|
81
|
-
|
|
82
|
-
context_in_block = nil
|
|
83
|
-
|
|
84
|
-
expect {
|
|
85
|
-
BarsoomUtils::ExceptionNotifier.run_with_context({ my_new_context: "what up" }) do
|
|
86
|
-
context_in_block = Honeybadger.get_context
|
|
87
|
-
raise "boom"
|
|
88
|
-
end
|
|
89
|
-
}.to raise_error /boom/
|
|
90
|
-
|
|
91
|
-
# Adds the new context while running the code.
|
|
92
|
-
expect(context_in_block).to eq({ my_old_context: "hello", my_new_context: "what up" })
|
|
93
|
-
|
|
94
|
-
# Resets the old context, without keeping the new.
|
|
95
|
-
expect(Honeybadger.get_context).to eq({ my_old_context: "hello" })
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
76
|
end
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rubocop"
|
|
4
|
+
require "rubocop/rspec/support"
|
|
5
|
+
require "barsoom_utils/rubocop"
|
|
6
|
+
|
|
7
|
+
RSpec.describe RuboCop::Cop::Barsoom::TrailingCommaInArguments, :config do
|
|
8
|
+
include RuboCop::RSpec::ExpectOffense
|
|
9
|
+
|
|
10
|
+
context "when closing paren is on its own line" do
|
|
11
|
+
it "registers an offense when trailing comma is missing" do
|
|
12
|
+
expect_offense(<<~RUBY)
|
|
13
|
+
foo(
|
|
14
|
+
a,
|
|
15
|
+
b
|
|
16
|
+
^ Put a trailing comma after the last argument when `)` is on the next line.
|
|
17
|
+
)
|
|
18
|
+
RUBY
|
|
19
|
+
|
|
20
|
+
expect_correction(<<~RUBY)
|
|
21
|
+
foo(
|
|
22
|
+
a,
|
|
23
|
+
b,
|
|
24
|
+
)
|
|
25
|
+
RUBY
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "accepts trailing comma" do
|
|
29
|
+
expect_no_offenses(<<~RUBY)
|
|
30
|
+
foo(
|
|
31
|
+
a,
|
|
32
|
+
b,
|
|
33
|
+
)
|
|
34
|
+
RUBY
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "accepts trailing comma when args share a line" do
|
|
38
|
+
expect_no_offenses(<<~RUBY)
|
|
39
|
+
foo(
|
|
40
|
+
a, b,
|
|
41
|
+
)
|
|
42
|
+
RUBY
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "registers an offense for missing comma when args share a line" do
|
|
46
|
+
expect_offense(<<~RUBY)
|
|
47
|
+
foo(
|
|
48
|
+
a, b
|
|
49
|
+
^ Put a trailing comma after the last argument when `)` is on the next line.
|
|
50
|
+
)
|
|
51
|
+
RUBY
|
|
52
|
+
|
|
53
|
+
expect_correction(<<~RUBY)
|
|
54
|
+
foo(
|
|
55
|
+
a, b,
|
|
56
|
+
)
|
|
57
|
+
RUBY
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
context "when closing paren is on the same line as last arg" do
|
|
62
|
+
it "registers an offense when trailing comma is present" do
|
|
63
|
+
expect_offense(<<~RUBY)
|
|
64
|
+
foo(
|
|
65
|
+
a,
|
|
66
|
+
b,)
|
|
67
|
+
^ Remove the trailing comma when `)` is on the same line as the last argument.
|
|
68
|
+
RUBY
|
|
69
|
+
|
|
70
|
+
expect_correction(<<~RUBY)
|
|
71
|
+
foo(
|
|
72
|
+
a,
|
|
73
|
+
b)
|
|
74
|
+
RUBY
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "accepts no trailing comma" do
|
|
78
|
+
expect_no_offenses(<<~RUBY)
|
|
79
|
+
foo(
|
|
80
|
+
a,
|
|
81
|
+
b)
|
|
82
|
+
RUBY
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
context "single-line calls" do
|
|
87
|
+
it "accepts no trailing comma" do
|
|
88
|
+
expect_no_offenses(<<~RUBY)
|
|
89
|
+
foo(a, b)
|
|
90
|
+
RUBY
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "accepts a single argument" do
|
|
94
|
+
expect_no_offenses(<<~RUBY)
|
|
95
|
+
foo(a)
|
|
96
|
+
RUBY
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
context "safe navigation calls" do
|
|
101
|
+
it "registers an offense when trailing comma is missing" do
|
|
102
|
+
expect_offense(<<~RUBY)
|
|
103
|
+
foo&.bar(
|
|
104
|
+
a,
|
|
105
|
+
b
|
|
106
|
+
^ Put a trailing comma after the last argument when `)` is on the next line.
|
|
107
|
+
)
|
|
108
|
+
RUBY
|
|
109
|
+
|
|
110
|
+
expect_correction(<<~RUBY)
|
|
111
|
+
foo&.bar(
|
|
112
|
+
a,
|
|
113
|
+
b,
|
|
114
|
+
)
|
|
115
|
+
RUBY
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
context "with keyword arguments" do
|
|
120
|
+
it "registers an offense when trailing comma is missing" do
|
|
121
|
+
expect_offense(<<~RUBY)
|
|
122
|
+
foo(
|
|
123
|
+
key: "value"
|
|
124
|
+
^^^^^^^^^^^^ Put a trailing comma after the last argument when `)` is on the next line.
|
|
125
|
+
)
|
|
126
|
+
RUBY
|
|
127
|
+
|
|
128
|
+
expect_correction(<<~RUBY)
|
|
129
|
+
foo(
|
|
130
|
+
key: "value",
|
|
131
|
+
)
|
|
132
|
+
RUBY
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "accepts trailing comma" do
|
|
136
|
+
expect_no_offenses(<<~RUBY)
|
|
137
|
+
foo(
|
|
138
|
+
key: "value",
|
|
139
|
+
)
|
|
140
|
+
RUBY
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "accepts trailing comma followed by a comment" do
|
|
144
|
+
expect_no_offenses(<<~RUBY)
|
|
145
|
+
foo(
|
|
146
|
+
key: "value", # some comment
|
|
147
|
+
)
|
|
148
|
+
RUBY
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
context "with block pass argument" do
|
|
153
|
+
it "ignores block pass on its own line" do
|
|
154
|
+
expect_no_offenses(<<~RUBY)
|
|
155
|
+
bar(
|
|
156
|
+
a,
|
|
157
|
+
&block
|
|
158
|
+
)
|
|
159
|
+
RUBY
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
context "without parentheses" do
|
|
164
|
+
it "ignores calls without parentheses" do
|
|
165
|
+
expect_no_offenses(<<~RUBY)
|
|
166
|
+
foo a,
|
|
167
|
+
b
|
|
168
|
+
RUBY
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
context "without arguments" do
|
|
173
|
+
it "ignores calls without arguments" do
|
|
174
|
+
expect_no_offenses(<<~RUBY)
|
|
175
|
+
foo()
|
|
176
|
+
RUBY
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: barsoom_utils
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.0.
|
|
4
|
+
version: 0.2.0.64
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tomas Skogberg
|
|
@@ -29,6 +29,8 @@ files:
|
|
|
29
29
|
- lib/barsoom_utils.rb
|
|
30
30
|
- lib/barsoom_utils/exception_notifier.rb
|
|
31
31
|
- lib/barsoom_utils/feature_toggle.rb
|
|
32
|
+
- lib/barsoom_utils/rubocop.rb
|
|
33
|
+
- lib/barsoom_utils/rubocop/cop/barsoom/trailing_comma_in_arguments.rb
|
|
32
34
|
- lib/barsoom_utils/spec/debug_helpers.rb
|
|
33
35
|
- lib/barsoom_utils/version.rb
|
|
34
36
|
- script/test
|
|
@@ -36,6 +38,7 @@ files:
|
|
|
36
38
|
- shared_rubocop_rails.yml
|
|
37
39
|
- spec/exception_notifier_spec.rb
|
|
38
40
|
- spec/feature_toggle_spec.rb
|
|
41
|
+
- spec/rubocop/cop/barsoom/trailing_comma_in_arguments_spec.rb
|
|
39
42
|
- spec/spec/debug_helpers_spec.rb
|
|
40
43
|
- spec/spec_helper.rb
|
|
41
44
|
homepage: https://dev.auctionet.com/
|