rubocop-sorbet 0.6.3 → 0.6.7

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: bd3fcc1ddd15ba9418aeb852d83149b3594fb315c7aa77ab4641c9046466d109
4
- data.tar.gz: 2b446c026647ebb8d312e8be0034af253f61dc5ac8903c2b75bf42c11be903fe
3
+ metadata.gz: abb9e641bb3b12d53d9364cd235ab21b63c48339d2ffba858f593d421d029868
4
+ data.tar.gz: 5e2758c93d99a35d2c93914bd3e2c2bba08de4770eb2519a6b9a938460cddd3e
5
5
  SHA512:
6
- metadata.gz: dd23c876c6224baf1a3888c169291b6260286326329d9b48650d1c4113571257837e0fa96d12b4357d4aee62e78b20e1be6373295b0d1e7d065c139e8cf3e25f
7
- data.tar.gz: 12c3c8aae878c4474284fd41f79da1f4671399bb8e1f01403fe556d36e25274d951f42771ecd0dfc0c3527686b0f3aa1a0d3a22db9b7287c802adf9c43cbc718
6
+ metadata.gz: d0ae42fc7fb217d55f94ed40dfe8d721c18666d9b5bfe5c87035694c978c4165a41089dac38db2594904befffb3c33c80d62f7fbee440bdcbfa3e1d1e9687bc3
7
+ data.tar.gz: e418a1bdbdcd084c0ebe76a976ee813836be481fdfa336eb3387ab569adacabdd3bea6f9b9fefb74a9968bb56c8ad4a2ec1d5915b467626ecddb6a4904f1d738
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-sorbet (0.6.3)
4
+ rubocop-sorbet (0.6.7)
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
@@ -1,7 +1,5 @@
1
1
  # Rubocop-Sorbet
2
2
 
3
- [![Build Status](https://travis-ci.org/Shopify/rubocop-sorbet.svg?branch=master)](https://travis-ci.org/Shopify/rubocop-sorbet)
4
-
5
3
  A collection of Rubocop rules for Sorbet.
6
4
 
7
5
  ## Installation
@@ -17,7 +15,7 @@ or, if you use `Bundler`, add this line your application's `Gemfile`:
17
15
  gem 'rubocop-sorbet', require: false
18
16
  ```
19
17
 
20
- Note: in order to use the [Sorbet/SignatureBuildOrder](https://github.com/Shopify/rubocop-sorbet/blob/master/manual/cops_sorbet.md#sorbetsignaturebuildorder) cop autocorrect feature, it is necessary
18
+ Note: in order to use the [Sorbet/SignatureBuildOrder](https://github.com/Shopify/rubocop-sorbet/blob/main/manual/cops_sorbet.md#sorbetsignaturebuildorder) cop autocorrect feature, it is necessary
21
19
  to install `unparser` in addition to `rubocop-sorbet`.
22
20
 
23
21
  ```ruby
@@ -111,8 +109,8 @@ bundle exec rake generate_cops_documentation
111
109
 
112
110
  ## License
113
111
 
114
- The gem is available as open source under the terms of the [MIT License](https://github.com/Shopify/rubocop-sorbet/blob/master/LICENSE.txt).
112
+ The gem is available as open source under the terms of the [MIT License](https://github.com/Shopify/rubocop-sorbet/blob/main/LICENSE.txt).
115
113
 
116
114
  ## Code of Conduct
117
115
 
118
- Everyone interacting in the Rubocop::Sorbet project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Shopify/rubocop-sorbet/blob/master/CODE_OF_CONDUCT.md).
116
+ Everyone interacting in the Rubocop::Sorbet project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Shopify/rubocop-sorbet/blob/main/CODE_OF_CONDUCT.md).
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
@@ -188,7 +188,7 @@ Lint/EmptyFile:
188
188
  Enabled: true
189
189
  AllowComments: false
190
190
 
191
- Lint/SyntaxError:
191
+ Lint/Syntax:
192
192
  Enabled: true
193
193
 
194
194
  ## Sorbet
@@ -199,6 +199,9 @@ Sorbet:
199
199
  Sorbet/EnforceSigilOrder:
200
200
  Enabled: true
201
201
 
202
+ Sorbet/EnforceSingleSigil:
203
+ Enabled: true
204
+
202
205
  Sorbet/ForbidExtendTSigHelpersInShims:
203
206
  Enabled: true
204
207
 
@@ -217,6 +220,9 @@ Sorbet/SignatureBuildOrder:
217
220
  Sorbet/SingleLineRbiClassModuleDefinitions:
218
221
  Enabled: true
219
222
 
223
+ Sorbet/TypeAliasName:
224
+ Enabled: true
225
+
220
226
  Sorbet/ValidSigil:
221
227
  Enabled: true
222
228
  RequireSigilOnAllFiles: true
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "pathname"
4
+
3
5
  module RuboCop
4
6
  module Cop
5
7
  module Sorbet
@@ -21,25 +23,41 @@ module RuboCop
21
23
  include RangeHelp
22
24
 
23
25
  def investigate(processed_source)
26
+ paths = allowed_paths
27
+
28
+ if paths.nil?
29
+ add_offense(
30
+ nil,
31
+ location: source_range(processed_source.buffer, 1, 0),
32
+ message: "AllowedPaths expects an array"
33
+ )
34
+ return
35
+ elsif paths.empty?
36
+ add_offense(
37
+ nil,
38
+ location: source_range(processed_source.buffer, 1, 0),
39
+ message: "AllowedPaths cannot be empty"
40
+ )
41
+ return
42
+ end
43
+
44
+ # When executed the path to the source file is absolute.
45
+ # We need to remove the exec path directory prefix before matching with the filename regular expressions.
46
+ rel_path = processed_source.file_path.sub("#{Dir.pwd}/", "")
47
+
24
48
  add_offense(
25
49
  nil,
26
50
  location: source_range(processed_source.buffer, 1, 0),
27
- message: message
28
- ) if allowed_paths.none? { |pattern| File.fnmatch(pattern, processed_source.file_path) }
51
+ message: "RBI file path should match one of: #{paths.join(", ")}"
52
+ ) if paths.none? { |pattern| File.fnmatch(pattern, rel_path) }
29
53
  end
30
54
 
31
55
  private
32
56
 
33
57
  def allowed_paths
34
- cop_config["AllowedPaths"]&.compact || []
35
- end
36
-
37
- def message
38
- if allowed_paths.empty?
39
- "RBI files should be located in an allowed path, but AllowedPaths is empty or nil"
40
- else
41
- "RBI file path should match one of: #{allowed_paths.join(", ")}"
42
- end
58
+ paths = cop_config["AllowedPaths"]
59
+ return nil unless paths.is_a?(Array)
60
+ paths.compact
43
61
  end
44
62
  end
45
63
  end
@@ -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"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module RuboCop
3
3
  module Sorbet
4
- VERSION = "0.6.3"
4
+ VERSION = "0.6.7"
5
5
  end
6
6
  end
data/manual/cops.md CHANGED
@@ -30,6 +30,7 @@ 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 -->
@@ -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
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.3
4
+ version: 0.6.7
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-03 00:00:00.000000000 Z
14
+ date: 2022-02-11 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
@@ -111,6 +111,7 @@ files:
111
111
  - lib/rubocop/cop/sorbet/signatures/keyword_argument_ordering.rb
112
112
  - lib/rubocop/cop/sorbet/signatures/signature_build_order.rb
113
113
  - lib/rubocop/cop/sorbet/signatures/signature_cop.rb
114
+ - lib/rubocop/cop/sorbet/type_alias_name.rb
114
115
  - lib/rubocop/cop/sorbet_cops.rb
115
116
  - lib/rubocop/sorbet.rb
116
117
  - lib/rubocop/sorbet/inject.rb