rubocop-sorbet 0.6.5 → 0.6.8

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: 7c1aed7de77dddecfab7d01e2370897d1da0081d92795aa9fdd221b831da980d
4
- data.tar.gz: ecc9c7d3168bd636a45d2e9f9c4c9f20e04e42379ea89280452d7a9f59e2f3f8
3
+ metadata.gz: 64fed7c9d13d31d36b4291400c35f40857cd11522f877538aa4225bf0da1382b
4
+ data.tar.gz: f813a95fd882e1d51585cb1cffb79169f378d2a27ff5956b4a1f7b2f397e4f21
5
5
  SHA512:
6
- metadata.gz: 555054526bf69633f6faf63c83514255c0622c0b7604eab94dfd31933c023285e53aadd4e76eb49418d92532ca9953a8a0d42bb7d74ef0cfd7478cd4b244dab1
7
- data.tar.gz: fa2e73581f867b029b1a853647b0bbea47f433037064d29773366aa02e2374f9e79209ae712dc7cd54c2d3654dbbf097fe324a5683e34f3180a93b8c88d7da96
6
+ metadata.gz: 5582a0d4b3e833504826549d967eded49aa32403741eea67af4a89dd3a95170164ae0ff540bc6f2422c9c34a82ceec281f991312c525937d956659773250f9ca
7
+ data.tar.gz: b3354da7079b05cfd16a541d25db45c271eb2dc43e1fae34dd336e38fca8b290ea8a58c643a178bebe722e2ed5b3d4f2f2d2096ad67ab943fdbae950a67f5f04
@@ -11,7 +11,7 @@ jobs:
11
11
  strategy:
12
12
  fail-fast: false
13
13
  matrix:
14
- ruby: [ 2.5, 2.6, 2.7, 3.0 ]
14
+ ruby: [ '2.5', '2.6', '2.7', '3.0', '3.1' ]
15
15
  name: Test Ruby ${{ matrix.ruby }}
16
16
  steps:
17
17
  - uses: actions/checkout@v2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-sorbet (0.6.5)
4
+ rubocop-sorbet (0.6.8)
5
5
  rubocop (>= 0.90.0)
6
6
 
7
7
  GEM
@@ -10,12 +10,12 @@ GEM
10
10
  ast (2.4.2)
11
11
  byebug (11.1.3)
12
12
  diff-lcs (1.3)
13
- parallel (1.20.1)
13
+ parallel (1.21.0)
14
14
  parser (3.0.1.1)
15
15
  ast (~> 2.4.1)
16
- rainbow (3.0.0)
16
+ rainbow (3.1.1)
17
17
  rake (13.0.1)
18
- regexp_parser (2.1.1)
18
+ regexp_parser (2.2.0)
19
19
  rexml (3.2.5)
20
20
  rspec (3.8.0)
21
21
  rspec-core (~> 3.8.0)
@@ -30,21 +30,21 @@ GEM
30
30
  diff-lcs (>= 1.2.0, < 2.0)
31
31
  rspec-support (~> 3.8.0)
32
32
  rspec-support (3.8.2)
33
- rubocop (1.16.0)
33
+ rubocop (1.24.1)
34
34
  parallel (~> 1.10)
35
35
  parser (>= 3.0.0.0)
36
36
  rainbow (>= 2.2.2, < 4.0)
37
37
  regexp_parser (>= 1.8, < 3.0)
38
38
  rexml
39
- rubocop-ast (>= 1.7.0, < 2.0)
39
+ rubocop-ast (>= 1.15.1, < 2.0)
40
40
  ruby-progressbar (~> 1.7)
41
41
  unicode-display_width (>= 1.4.0, < 3.0)
42
- rubocop-ast (1.7.0)
42
+ rubocop-ast (1.15.1)
43
43
  parser (>= 3.0.1.1)
44
44
  rubocop-shopify (2.1.0)
45
45
  rubocop (~> 1.13)
46
46
  ruby-progressbar (1.11.0)
47
- unicode-display_width (2.0.0)
47
+ unicode-display_width (2.1.0)
48
48
  unparser (0.6.0)
49
49
  diff-lcs (~> 1.3)
50
50
  parser (>= 3.0.0)
data/README.md CHANGED
@@ -60,13 +60,15 @@ end
60
60
 
61
61
  ### Rubocop rules for RBI files
62
62
 
63
- Put this into your `.rubocop.yml`:
63
+ To enable the cops related to RBI files under the `sorbet/rbi/` directory, put this in `sorbet/rbi/.rubocop.yml`:
64
64
 
65
65
  ```yaml
66
66
  inherit_gem:
67
67
  rubocop-sorbet: config/rbi.yml
68
68
  ```
69
69
 
70
+ This will turn off default cops for `**/*.rbi` files and enable the RBI specific cops.
71
+
70
72
  ## The Cops
71
73
  All cops are located under [`lib/rubocop/cop/sorbet`](lib/rubocop/cop/sorbet), and contain examples/documentation.
72
74
 
data/config/default.yml CHANGED
@@ -39,7 +39,7 @@ Sorbet/EnforceSigilOrder:
39
39
  Enabled: true
40
40
  VersionAdded: 0.3.4
41
41
 
42
- Sorbet/sigils/EnforceSingleSigil:
42
+ Sorbet/EnforceSingleSigil:
43
43
  Description: 'Ensures that there is only one Sorbet sigil in a file.'
44
44
  Enabled: true
45
45
  VersionAdded: '<<next>>'
@@ -197,6 +197,17 @@ Sorbet/TrueSigil:
197
197
  - db/**/*.rb
198
198
  - script/**/*
199
199
 
200
+ Sorbet/TypeAliasName:
201
+ Description: 'Type alias constant names must be in CamelCase.'
202
+ Enabled: true
203
+ VersionAdded: 0.6.6
204
+ Include:
205
+ - "**/*.{rb,rbi,rake,ru}"
206
+ Exclude:
207
+ - bin/**/*
208
+ - db/**/*.rb
209
+ - script/**/*
210
+
200
211
  Sorbet/ValidSigil:
201
212
  Description: 'All files must have a valid sigil.'
202
213
  Enabled: true
data/config/rbi.yml CHANGED
@@ -220,6 +220,9 @@ Sorbet/SignatureBuildOrder:
220
220
  Sorbet/SingleLineRbiClassModuleDefinitions:
221
221
  Enabled: true
222
222
 
223
+ Sorbet/TypeAliasName:
224
+ Enabled: true
225
+
223
226
  Sorbet/ValidSigil:
224
227
  Enabled: true
225
228
  RequireSigilOnAllFiles: true
@@ -57,12 +57,18 @@ module RuboCop
57
57
  )
58
58
  PATTERN
59
59
 
60
- def_node_matcher(:generic_parameter_decl?, <<-PATTERN)
60
+ def_node_matcher(:generic_parameter_decl_call?, <<-PATTERN)
61
61
  (
62
62
  send nil? {:type_template :type_member} ...
63
63
  )
64
64
  PATTERN
65
65
 
66
+ def_node_matcher(:generic_parameter_decl_block_call?, <<-PATTERN)
67
+ (block
68
+ (send nil? {:type_template :type_member}) ...
69
+ )
70
+ PATTERN
71
+
66
72
  def_node_search(:method_needing_aliasing_on_t?, <<-PATTERN)
67
73
  (
68
74
  send
@@ -81,7 +87,7 @@ module RuboCop
81
87
  end
82
88
 
83
89
  def not_generic_parameter_decl?(node)
84
- !generic_parameter_decl?(node)
90
+ !generic_parameter_decl_call?(node) && !generic_parameter_decl_block_call?(node)
85
91
  end
86
92
 
87
93
  def not_nil?(node)
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop/cop/style/mutable_constant"
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Sorbet
8
+ module MutableConstantSorbetAwareBehaviour
9
+ def self.prepended(base)
10
+ base.def_node_matcher(:t_let, <<~PATTERN)
11
+ (send (const nil? :T) :let $_constant _type)
12
+ PATTERN
13
+ end
14
+
15
+ def on_assignment(value)
16
+ t_let(value) do |constant|
17
+ value = constant
18
+ end
19
+
20
+ super(value)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ RuboCop::Cop::Style::MutableConstant.prepend(
28
+ RuboCop::Cop::Sorbet::MutableConstantSorbetAwareBehaviour
29
+ )
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Sorbet
8
+ # This cop ensures all constants used as `T.type_alias` are using CamelCase.
9
+ #
10
+ # @example
11
+ #
12
+ # # bad
13
+ # FOO_OR_BAR = T.type_alias { T.any(Foo, Bar) }
14
+ #
15
+ # # good
16
+ # FooOrBar = T.type_alias { T.any(Foo, Bar) }
17
+ class TypeAliasName < RuboCop::Cop::Cop
18
+ MSG = "Type alias constant name should be in CamelCase"
19
+
20
+ def_node_matcher(:casgn_type_alias?, <<-PATTERN)
21
+ (casgn
22
+ _
23
+ _
24
+ (block
25
+ (send
26
+ (const nil? :T) :type_alias)
27
+ _
28
+ _
29
+ ))
30
+ PATTERN
31
+
32
+ def on_casgn(node)
33
+ return unless casgn_type_alias?(node)
34
+
35
+ name = node.children[1]
36
+
37
+ # From https://github.com/rubocop/rubocop/blob/master/lib/rubocop/cop/naming/class_and_module_camel_case.rb
38
+ return unless /_/.match?(name)
39
+
40
+ add_offense(node)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -7,6 +7,7 @@ require_relative "sorbet/forbid_untyped_struct_props"
7
7
  require_relative "sorbet/one_ancestor_per_line"
8
8
  require_relative "sorbet/callback_conditionals_binding"
9
9
  require_relative "sorbet/forbid_t_unsafe"
10
+ require_relative "sorbet/type_alias_name"
10
11
 
11
12
  require_relative "sorbet/rbi/forbid_extend_t_sig_helpers_in_shims"
12
13
  require_relative "sorbet/rbi/forbid_rbi_outside_of_allowed_paths"
@@ -27,3 +28,5 @@ require_relative "sorbet/sigils/strict_sigil"
27
28
  require_relative "sorbet/sigils/strong_sigil"
28
29
  require_relative "sorbet/sigils/enforce_sigil_order"
29
30
  require_relative "sorbet/sigils/enforce_single_sigil"
31
+
32
+ require_relative "sorbet/mutable_constant_sorbet_aware_behaviour"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module RuboCop
3
3
  module Sorbet
4
- VERSION = "0.6.5"
4
+ VERSION = "0.6.8"
5
5
  end
6
6
  end
data/manual/cops.md CHANGED
@@ -30,6 +30,12 @@ In the following section you find all available cops:
30
30
  * [Sorbet/StrictSigil](cops_sorbet.md#sorbetstrictsigil)
31
31
  * [Sorbet/StrongSigil](cops_sorbet.md#sorbetstrongsigil)
32
32
  * [Sorbet/TrueSigil](cops_sorbet.md#sorbettruesigil)
33
+ * [Sorbet/TypeAliasName](cops_sorbet.md#sorbettypealiasname)
33
34
  * [Sorbet/ValidSigil](cops_sorbet.md#sorbetvalidsigil)
34
35
 
35
36
  <!-- END_COP_LIST -->
37
+
38
+ In addition to the cops defined in this gem, it also modifies the behaviour of some other cops
39
+ defined in other RuboCop gems:
40
+
41
+ * [Style/MutableConstant](https://docs.rubocop.org/rubocop/cops_style.html#stylemutableconstant): In addition to the default behaviour, RuboCop Sorbet makes this cop `T.let` aware, so that `CONST = T.let([1, 2, 3], T::Array[Integer])` is also treated as a mutable literal constant value.
@@ -545,6 +545,31 @@ SuggestedStrictness | `true` | String
545
545
  Include | `**/*.{rb,rbi,rake,ru}` | Array
546
546
  Exclude | `bin/**/*`, `db/**/*.rb`, `script/**/*` | Array
547
547
 
548
+ ## Sorbet/TypeAliasName
549
+
550
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
551
+ --- | --- | --- | --- | ---
552
+ Enabled | Yes | No | 0.6.6 | -
553
+
554
+ This cop ensures all constants used as `T.type_alias` are using CamelCase.
555
+
556
+ ### Examples
557
+
558
+ ```ruby
559
+ # bad
560
+ FOO_OR_BAR = T.type_alias { T.any(Foo, Bar) }
561
+
562
+ # good
563
+ FooOrBar = T.type_alias { T.any(Foo, Bar) }
564
+ ```
565
+
566
+ ### Configurable attributes
567
+
568
+ Name | Default value | Configurable values
569
+ --- | --- | ---
570
+ Include | `**/*.{rb,rbi,rake,ru}` | Array
571
+ Exclude | `bin/**/*`, `db/**/*.rb`, `script/**/*` | Array
572
+
548
573
  ## Sorbet/ValidSigil
549
574
 
550
575
  Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
File without changes
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.6.5
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2021-12-17 00:00:00.000000000 Z
14
+ date: 2022-04-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
@@ -92,6 +92,7 @@ files:
92
92
  - lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
93
93
  - lib/rubocop/cop/sorbet/forbid_t_unsafe.rb
94
94
  - lib/rubocop/cop/sorbet/forbid_untyped_struct_props.rb
95
+ - lib/rubocop/cop/sorbet/mutable_constant_sorbet_aware_behaviour.rb
95
96
  - lib/rubocop/cop/sorbet/one_ancestor_per_line.rb
96
97
  - lib/rubocop/cop/sorbet/rbi/forbid_extend_t_sig_helpers_in_shims.rb
97
98
  - lib/rubocop/cop/sorbet/rbi/forbid_rbi_outside_of_allowed_paths.rb
@@ -111,6 +112,7 @@ files:
111
112
  - lib/rubocop/cop/sorbet/signatures/keyword_argument_ordering.rb
112
113
  - lib/rubocop/cop/sorbet/signatures/signature_build_order.rb
113
114
  - lib/rubocop/cop/sorbet/signatures/signature_cop.rb
115
+ - lib/rubocop/cop/sorbet/type_alias_name.rb
114
116
  - lib/rubocop/cop/sorbet_cops.rb
115
117
  - lib/rubocop/sorbet.rb
116
118
  - lib/rubocop/sorbet/inject.rb
@@ -119,7 +121,7 @@ files:
119
121
  - manual/cops_sorbet.md
120
122
  - rubocop-sorbet.gemspec
121
123
  - service.yml
122
- - shipit.yml
124
+ - shipit.production.yml
123
125
  - tasks/cops_documentation.rake
124
126
  homepage: https://github.com/shopify/rubocop-sorbet
125
127
  licenses: