rubocop-sorbet 0.11.0 → 0.12.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: bf3fcf2d81ddb556a7a499288fefc3cdd30f4c1a6a47047ae5111ba510b51d00
4
- data.tar.gz: cfeddb88f154b226f0321ed78b6373725985daf068355659763eb9913a40fbcc
3
+ metadata.gz: 6435562ddd6c7da9c69d97032407e065c2258099a118a71b7d6ac5a0e1164fd0
4
+ data.tar.gz: 22267c08a28a1e491546a310be05de578ba7693aba4c597ba0b508c048669777
5
5
  SHA512:
6
- metadata.gz: 51c844a3c3dc0254a09e7c31fe3c5794873e9757c5f2ebb59f842d7ccf8786b66788d98acbac922e064395baefeb9f44df2a1f128720a9c6b5ffc56d4dabfe51
7
- data.tar.gz: d42d29fbbdaa9ffd32ff3f01e56443677e439ac04444859df3fa2f87f5273a891bd6e9bfdf7f46454e604e6a5c0388c554633f39d11e3932556b7e1dd80c1ed3
6
+ metadata.gz: 85a52ba95de0151045c93321e38ec24e0859067166084b3bf1d96e3e66e91cb27997224340a26cb39a1684341e4ce1d8e1e596643216b8761d3db0960e5e361a
7
+ data.tar.gz: d5897dc561a7fe22cbd099c3b34355bf474f7bbcf139c3c7a1c3fed24cf3295cc02e9349a46e75a6d75da0db547f21cd971dd557c0177b88dba6842ca661602e
@@ -8,7 +8,7 @@ jobs:
8
8
  check-placeholders:
9
9
  runs-on: ubuntu-latest
10
10
  steps:
11
- - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
11
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
12
12
  - uses: ruby/setup-ruby@v1
13
13
  with:
14
14
  bundler-cache: true
@@ -14,7 +14,7 @@ jobs:
14
14
  ruby: ["3.1", "3.2", "3.3", "3.4"]
15
15
  name: Test Ruby ${{ matrix.ruby }}
16
16
  steps:
17
- - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
17
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
18
18
  - name: Set up Ruby
19
19
  uses: ruby/setup-ruby@a4effe49ee8ee5b8b5091268c473a4628afb5651 # v1.245.0
20
20
  with:
@@ -29,7 +29,7 @@ jobs:
29
29
  fail-fast: false
30
30
  name: Lint & Docs
31
31
  steps:
32
- - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
32
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
33
33
  - name: Set up Ruby
34
34
  uses: ruby/setup-ruby@a4effe49ee8ee5b8b5091268c473a4628afb5651 # v1.245.0
35
35
  with:
@@ -12,7 +12,7 @@ jobs:
12
12
  steps:
13
13
  - name: Dependabot metadata
14
14
  id: metadata
15
- uses: dependabot/fetch-metadata@08eff52bf64351f401fb50d4972fa95b9f2c2d1b # v2.4.0
15
+ uses: dependabot/fetch-metadata@21025c705c08248db411dc16f3619e6b5f9ea21a # v2.5.0
16
16
  with:
17
17
  github-token: "${{ secrets.GITHUB_TOKEN }}"
18
18
  - name: Enable auto-merge for Dependabot PRs
@@ -12,7 +12,7 @@ jobs:
12
12
  stale:
13
13
  runs-on: ubuntu-latest
14
14
  steps:
15
- - uses: actions/stale@5f858e3efba33a5ca4407a664cc011ad407f2008 # v10.1.0
15
+ - uses: actions/stale@997185467fa4f803885201cee163a9f38240193d # v10.1.1
16
16
  with:
17
17
  stale-pr-message: >
18
18
  This PR has been automatically marked as stale because it has not had
data/.rubocop.yml CHANGED
@@ -20,7 +20,7 @@ Naming/FileName:
20
20
  - lib/rubocop-sorbet.rb
21
21
 
22
22
  Layout/LineLength:
23
- IgnoreCopDirectives: true
23
+ AllowCopDirectives: true
24
24
 
25
25
  InternalAffairs/UndefinedConfig:
26
26
  Enabled: false # Bug in implementation fails to find our configs
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-sorbet (0.11.0)
4
+ rubocop-sorbet (0.12.0)
5
5
  lint_roller
6
6
  rubocop (>= 1.75.2)
7
7
 
@@ -21,20 +21,20 @@ GEM
21
21
  pp (>= 0.6.0)
22
22
  rdoc (>= 4.0.0)
23
23
  reline (>= 0.4.2)
24
- json (2.12.2)
24
+ json (2.18.1)
25
25
  language_server-protocol (3.17.0.5)
26
26
  lint_roller (1.1.0)
27
27
  minitest (5.25.5)
28
28
  mocha (2.7.1)
29
29
  ruby2_keywords (>= 0.0.5)
30
30
  parallel (1.27.0)
31
- parser (3.3.8.0)
31
+ parser (3.3.10.1)
32
32
  ast (~> 2.4.1)
33
33
  racc
34
34
  pp (0.6.2)
35
35
  prettyprint
36
36
  prettyprint (0.2.0)
37
- prism (1.4.0)
37
+ prism (1.9.0)
38
38
  psych (5.2.6)
39
39
  date
40
40
  stringio
@@ -44,10 +44,10 @@ GEM
44
44
  rdoc (6.14.1)
45
45
  erb
46
46
  psych (>= 4.0.0)
47
- regexp_parser (2.10.0)
47
+ regexp_parser (2.11.3)
48
48
  reline (0.6.1)
49
49
  io-console (~> 0.5)
50
- rubocop (1.77.0)
50
+ rubocop (1.84.1)
51
51
  json (~> 2.3)
52
52
  language_server-protocol (~> 3.17.0.2)
53
53
  lint_roller (~> 1.1.0)
@@ -55,12 +55,12 @@ GEM
55
55
  parser (>= 3.3.0.2)
56
56
  rainbow (>= 2.2.2, < 4.0)
57
57
  regexp_parser (>= 2.9.3, < 3.0)
58
- rubocop-ast (>= 1.45.1, < 2.0)
58
+ rubocop-ast (>= 1.49.0, < 2.0)
59
59
  ruby-progressbar (~> 1.7)
60
60
  unicode-display_width (>= 2.4.0, < 4.0)
61
- rubocop-ast (1.45.1)
61
+ rubocop-ast (1.49.0)
62
62
  parser (>= 3.3.7.2)
63
- prism (~> 1.4)
63
+ prism (~> 1.7)
64
64
  rubocop-minitest (0.38.1)
65
65
  lint_roller (~> 1.1)
66
66
  rubocop (>= 1.75.0, < 2.0)
@@ -70,9 +70,9 @@ GEM
70
70
  ruby-progressbar (1.13.0)
71
71
  ruby2_keywords (0.0.5)
72
72
  stringio (3.1.7)
73
- unicode-display_width (3.1.4)
74
- unicode-emoji (~> 4.0, >= 4.0.4)
75
- unicode-emoji (4.0.4)
73
+ unicode-display_width (3.2.0)
74
+ unicode-emoji (~> 4.1)
75
+ unicode-emoji (4.2.0)
76
76
  yard (0.9.37)
77
77
 
78
78
  PLATFORMS
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.0
1
+ 0.12.0
data/config/default.yml CHANGED
@@ -324,6 +324,14 @@ Sorbet/Refinement:
324
324
  Enabled: pending
325
325
  VersionAdded: 0.8.6
326
326
 
327
+ Sorbet/RuntimeOnFailureDependsOnChecked:
328
+ Description: >-
329
+ Ensures that `on_failure` is called after `checked` in signatures.
330
+ The `on_failure` method has no effect unless `checked(:tests)` or
331
+ `checked(:always)` is also called.
332
+ Enabled: true
333
+ VersionAdded: '0.12.0'
334
+
327
335
  Sorbet/SelectByIsA:
328
336
  Description: >-
329
337
  Suggests using `grep` over `select` when using it only for type narrowing.
data/dev.yml CHANGED
@@ -1,8 +1,12 @@
1
1
  name: "rubocop-sorbet"
2
2
 
3
+ nix: true
4
+
3
5
  type: "ruby"
4
6
 
5
7
  up:
8
+ - packages:
9
+ - libyaml
6
10
  - ruby
7
11
  - "bundler"
8
12
 
@@ -222,7 +222,7 @@ module RuboCop
222
222
  string = +"\n"
223
223
 
224
224
  line = "#{indent}sig { params(#{sorted_props.map(&:initialize_sig_param).join(", ")}).void }\n"
225
- if line.length <= max_line_length
225
+ if max_line_length.nil? || line.length <= max_line_length
226
226
  string << line
227
227
  else
228
228
  string << "#{indent}sig do\n"
@@ -237,7 +237,7 @@ module RuboCop
237
237
  end
238
238
 
239
239
  line = "#{indent}def initialize(#{sorted_props.map(&:initialize_param).join(", ")})\n"
240
- if line.length <= max_line_length
240
+ if max_line_length.nil? || line.length <= max_line_length
241
241
  string << line
242
242
  else
243
243
  string << "#{indent}def initialize(\n"
@@ -66,7 +66,7 @@ module RuboCop
66
66
  correction = "#{ivar} ||= #{t.source}.let(#{init_expr.source}, #{t.source}.nilable(#{ivar_type.source}))"
67
67
 
68
68
  # We know good places to put line breaks, if required.
69
- if line_length(indent + correction) > max_line_length || correction.include?("\n")
69
+ if (max_line_length && line_length(indent + correction) > max_line_length) || correction.include?("\n")
70
70
  correction = <<~RUBY.chomp
71
71
  #{ivar} ||= #{t.source}.let(
72
72
  #{indent} #{init_expr.source.gsub("\n", "\n#{indent}")},
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Sorbet
6
+ # Checks that `on_failure` is not used without `checked(:tests)` or `checked(:always)`.
7
+ #
8
+ # @example
9
+ #
10
+ # # bad
11
+ # sig { params(x: Integer).returns(Integer).on_failure(:raise) }
12
+ # def plus_one(x)
13
+ # x + 1
14
+ # end
15
+ #
16
+ # # good
17
+ # sig { params(x: Integer).returns(Integer).checked(:always).on_failure(:raise) }
18
+ # def plus_one(x)
19
+ # x + 1
20
+ # end
21
+ #
22
+ class RuntimeOnFailureDependsOnChecked < ::RuboCop::Cop::Base
23
+ include SignatureHelp
24
+
25
+ MSG = "To use .on_failure you must additionally call .checked(:tests) or .checked(:always), otherwise, the .on_failure has no effect."
26
+
27
+ # @!method on_failure_call?(node)
28
+ def_node_matcher :on_failure_call?, <<~PATTERN
29
+ (send _ :on_failure ...)
30
+ PATTERN
31
+
32
+ # @!method checked_tests_or_always?(node)
33
+ def_node_matcher :checked_tests_or_always?, <<~PATTERN
34
+ (send _ :checked (sym {:tests | :always}))
35
+ PATTERN
36
+
37
+ def on_signature(node)
38
+ return unless node.descendants.any? { |n| on_failure_call?(n) }
39
+ return if node.descendants.any? { |n| checked_tests_or_always?(n) }
40
+
41
+ add_offense(node)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -50,6 +50,7 @@ require_relative "sorbet/signatures/forbid_sig"
50
50
  require_relative "sorbet/signatures/forbid_sig_with_runtime"
51
51
  require_relative "sorbet/signatures/forbid_sig_without_runtime"
52
52
  require_relative "sorbet/signatures/keyword_argument_ordering"
53
+ require_relative "sorbet/signatures/runtime_on_failure_depends_on_checked"
53
54
  require_relative "sorbet/signatures/signature_build_order"
54
55
  require_relative "sorbet/signatures/void_checked_tests"
55
56
 
data/manual/cops.md CHANGED
@@ -50,6 +50,7 @@ In the following section you find all available cops:
50
50
  * [Sorbet/ObsoleteStrictMemoization](cops_sorbet.md#sorbetobsoletestrictmemoization)
51
51
  * [Sorbet/RedundantExtendTSig](cops_sorbet.md#sorbetredundantextendtsig)
52
52
  * [Sorbet/Refinement](cops_sorbet.md#sorbetrefinement)
53
+ * [Sorbet/RuntimeOnFailureDependsOnChecked](cops_sorbet.md#sorbetruntimeonfailuredependsonchecked)
53
54
  * [Sorbet/SelectByIsA](cops_sorbet.md#sorbetselectbyisa)
54
55
  * [Sorbet/SignatureBuildOrder](cops_sorbet.md#sorbetsignaturebuildorder)
55
56
  * [Sorbet/SingleLineRbiClassModuleDefinitions](cops_sorbet.md#sorbetsinglelinerbiclassmoduledefinitions)
@@ -1197,6 +1197,30 @@ module Foo
1197
1197
  end
1198
1198
  ```
1199
1199
 
1200
+ ## Sorbet/RuntimeOnFailureDependsOnChecked
1201
+
1202
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
1203
+ --- | --- | --- | --- | ---
1204
+ Enabled | Yes | No | 0.12.0 | -
1205
+
1206
+ Checks that `on_failure` is not used without `checked(:tests)` or `checked(:always)`.
1207
+
1208
+ ### Examples
1209
+
1210
+ ```ruby
1211
+ # bad
1212
+ sig { params(x: Integer).returns(Integer).on_failure(:raise) }
1213
+ def plus_one(x)
1214
+ x + 1
1215
+ end
1216
+
1217
+ # good
1218
+ sig { params(x: Integer).returns(Integer).checked(:always).on_failure(:raise) }
1219
+ def plus_one(x)
1220
+ x + 1
1221
+ end
1222
+ ```
1223
+
1200
1224
  ## Sorbet/SelectByIsA
1201
1225
 
1202
1226
  Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-sorbet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu
@@ -132,6 +132,7 @@ files:
132
132
  - lib/rubocop/cop/sorbet/signatures/forbid_sig_with_runtime.rb
133
133
  - lib/rubocop/cop/sorbet/signatures/forbid_sig_without_runtime.rb
134
134
  - lib/rubocop/cop/sorbet/signatures/keyword_argument_ordering.rb
135
+ - lib/rubocop/cop/sorbet/signatures/runtime_on_failure_depends_on_checked.rb
135
136
  - lib/rubocop/cop/sorbet/signatures/signature_build_order.rb
136
137
  - lib/rubocop/cop/sorbet/signatures/void_checked_tests.rb
137
138
  - lib/rubocop/cop/sorbet/t_enum/forbid_comparable_t_enum.rb
@@ -169,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
170
  - !ruby/object:Gem::Version
170
171
  version: '0'
171
172
  requirements: []
172
- rubygems_version: 3.7.2
173
+ rubygems_version: 4.0.6
173
174
  specification_version: 4
174
175
  summary: Automatic Sorbet code style checking tool.
175
176
  test_files: []