rubocop-sorbet 0.8.4 → 0.8.5
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/Gemfile.lock +1 -1
- data/config/rbi.yml +16 -0
- data/lib/rubocop/cop/sorbet/rbi_versioning/gem_version_annotation_helper.rb +27 -0
- data/lib/rubocop/cop/sorbet/rbi_versioning/valid_gem_version_annotations.rb +62 -0
- data/lib/rubocop/cop/sorbet/t_enum/forbid_comparable_t_enum.rb +1 -1
- data/lib/rubocop/cop/sorbet/t_enum/multiple_t_enum_values.rb +1 -1
- data/lib/rubocop/cop/sorbet_cops.rb +3 -0
- data/lib/rubocop/sorbet/version.rb +1 -1
- data/manual/cops.md +1 -0
- data/manual/cops_sorbet.md +24 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dfcaff074a9af626b94a6909e3d6c3ea99749bced60c513d123cc00d4af2f26
|
4
|
+
data.tar.gz: 961d6723c8fa9e67dd25febab735a58ea4a7023c46132b008f3a8c4f996a18c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 927874817f3166896f9cbb5267f95fa18570ce29c01432ff076a9949b71986bc13ccdbb849bf943b4b908bc5b682448d381c5b7e579af3f1f963662ef93bf606
|
7
|
+
data.tar.gz: 2ad69a1852bea8490f7c3b0cb157482dc0176abeae0f8834f8e8afcc7b582db822a3fa86df331d3315743628f40a9352af45a320de12bb4e990c216babc041a1
|
data/Gemfile.lock
CHANGED
data/config/rbi.yml
CHANGED
@@ -169,9 +169,15 @@ Layout/SpaceBeforeFirstArg:
|
|
169
169
|
Layout/SpaceBeforeSemicolon:
|
170
170
|
Enabled: true
|
171
171
|
|
172
|
+
Layout/SpaceInsideBlockBraces:
|
173
|
+
Enabled: true
|
174
|
+
|
172
175
|
Layout/SpaceInsideParens:
|
173
176
|
Enabled: true
|
174
177
|
|
178
|
+
Layout/SpaceInsideReferenceBrackets:
|
179
|
+
Enabled: true
|
180
|
+
|
175
181
|
Layout/TrailingEmptyLines:
|
176
182
|
Enabled: true
|
177
183
|
EnforcedStyle: final_newline
|
@@ -220,6 +226,16 @@ Sorbet/SingleLineRbiClassModuleDefinitions:
|
|
220
226
|
Sorbet/TypeAliasName:
|
221
227
|
Enabled: true
|
222
228
|
|
229
|
+
Sorbet/ValidGemVersionAnnotations:
|
230
|
+
Description: >-
|
231
|
+
Ensures all gem version annotations in RBI files are correctly formatted per
|
232
|
+
Ruby's gem version specification guidelines.
|
233
|
+
|
234
|
+
See the rubygems.org documentation for more information on how to format gem
|
235
|
+
versions: https://guides.rubygems.org/patterns/#pessimistic-version-constraint
|
236
|
+
Enabled: false
|
237
|
+
VersionAdded: 0.8.5
|
238
|
+
|
223
239
|
Sorbet/ValidSigil:
|
224
240
|
Enabled: true
|
225
241
|
RequireSigilOnAllFiles: true
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Sorbet
|
6
|
+
module GemVersionAnnotationHelper
|
7
|
+
VERSION_PREFIX = "# @version"
|
8
|
+
|
9
|
+
def gem_version_annotations
|
10
|
+
processed_source.comments.select do |comment|
|
11
|
+
gem_version_annotation?(comment)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def gem_version_annotation?(comment)
|
18
|
+
comment.text.start_with?(VERSION_PREFIX)
|
19
|
+
end
|
20
|
+
|
21
|
+
def gem_versions(comment)
|
22
|
+
comment.text.delete_prefix(VERSION_PREFIX).split(/, ?/).map(&:strip)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Sorbet
|
6
|
+
# Checks that gem versions in RBI annotations are properly formatted per the Bundler gem specification.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# # @version > not a version number
|
11
|
+
#
|
12
|
+
# # good
|
13
|
+
# # @version = 1
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
# # @version > 1.2.3
|
17
|
+
#
|
18
|
+
# # good
|
19
|
+
# # @version <= 4.3-preview
|
20
|
+
#
|
21
|
+
class ValidGemVersionAnnotations < RuboCop::Cop::Base
|
22
|
+
include GemVersionAnnotationHelper
|
23
|
+
|
24
|
+
MSG = "Invalid gem version(s) detected: %<versions>s"
|
25
|
+
VALID_OPERATORS = ["=", "!=", ">", ">=", "<", "<=", "~>"]
|
26
|
+
|
27
|
+
def on_new_investigation
|
28
|
+
gem_version_annotations.each do |comment|
|
29
|
+
gem_versions = gem_versions(comment)
|
30
|
+
|
31
|
+
if gem_versions.empty?
|
32
|
+
message = format(MSG, versions: "empty version")
|
33
|
+
add_offense(comment, message: message)
|
34
|
+
break
|
35
|
+
end
|
36
|
+
|
37
|
+
invalid_versions = gem_versions.reject do |version|
|
38
|
+
valid_version?(version)
|
39
|
+
end
|
40
|
+
|
41
|
+
unless invalid_versions.empty?
|
42
|
+
message = format(MSG, versions: invalid_versions.map(&:strip).join(", "))
|
43
|
+
add_offense(comment, message: message)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def valid_version?(version_string)
|
51
|
+
parts = version_string.strip.split(" ")
|
52
|
+
operator, version = parts
|
53
|
+
|
54
|
+
return false unless operator && parts
|
55
|
+
return false unless VALID_OPERATORS.include?(operator)
|
56
|
+
|
57
|
+
Gem::Version.correct?(version)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
# serialize <=> other.serialize
|
22
22
|
# end
|
23
23
|
# end
|
24
|
-
class ForbidComparableTEnum < Base
|
24
|
+
class ForbidComparableTEnum < RuboCop::Cop::Base
|
25
25
|
include TEnum
|
26
26
|
|
27
27
|
MSG = "Do not use `T::Enum` as a comparable object because of significant performance overhead."
|
@@ -24,6 +24,9 @@ require_relative "sorbet/rbi/forbid_extend_t_sig_helpers_in_shims"
|
|
24
24
|
require_relative "sorbet/rbi/forbid_rbi_outside_of_allowed_paths"
|
25
25
|
require_relative "sorbet/rbi/single_line_rbi_class_module_definitions"
|
26
26
|
|
27
|
+
require_relative "sorbet/rbi_versioning/gem_version_annotation_helper"
|
28
|
+
require_relative "sorbet/rbi_versioning/valid_gem_version_annotations"
|
29
|
+
|
27
30
|
require_relative "sorbet/signatures/allow_incompatible_override"
|
28
31
|
require_relative "sorbet/signatures/checked_true_in_signature"
|
29
32
|
require_relative "sorbet/signatures/void_checked_tests"
|
data/manual/cops.md
CHANGED
@@ -39,6 +39,7 @@ In the following section you find all available cops:
|
|
39
39
|
* [Sorbet/StrongSigil](cops_sorbet.md#sorbetstrongsigil)
|
40
40
|
* [Sorbet/TrueSigil](cops_sorbet.md#sorbettruesigil)
|
41
41
|
* [Sorbet/TypeAliasName](cops_sorbet.md#sorbettypealiasname)
|
42
|
+
* [Sorbet/ValidGemVersionAnnotations](cops_sorbet.md#sorbetvalidgemversionannotations)
|
42
43
|
* [Sorbet/ValidSigil](cops_sorbet.md#sorbetvalidsigil)
|
43
44
|
* [Sorbet/VoidCheckedTests](cops_sorbet.md#sorbetvoidcheckedtests)
|
44
45
|
|
data/manual/cops_sorbet.md
CHANGED
@@ -892,6 +892,30 @@ Name | Default value | Configurable values
|
|
892
892
|
Include | `**/*.{rb,rbi,rake,ru}` | Array
|
893
893
|
Exclude | `bin/**/*`, `db/**/*.rb`, `script/**/*` | Array
|
894
894
|
|
895
|
+
## Sorbet/ValidGemVersionAnnotations
|
896
|
+
|
897
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
898
|
+
--- | --- | --- | --- | ---
|
899
|
+
Enabled | Yes | No | - | -
|
900
|
+
|
901
|
+
Checks that gem versions in RBI annotations are properly formatted per the Bundler gem specification.
|
902
|
+
|
903
|
+
### Examples
|
904
|
+
|
905
|
+
```ruby
|
906
|
+
# bad
|
907
|
+
# @version > not a version number
|
908
|
+
|
909
|
+
# good
|
910
|
+
# @version = 1
|
911
|
+
|
912
|
+
# good
|
913
|
+
# @version > 1.2.3
|
914
|
+
|
915
|
+
# good
|
916
|
+
# @version <= 4.3-preview
|
917
|
+
```
|
918
|
+
|
895
919
|
## Sorbet/ValidSigil
|
896
920
|
|
897
921
|
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.8.
|
4
|
+
version: 0.8.5
|
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: 2024-07-
|
14
|
+
date: 2024-07-25 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rubocop
|
@@ -81,6 +81,8 @@ files:
|
|
81
81
|
- lib/rubocop/cop/sorbet/rbi/forbid_extend_t_sig_helpers_in_shims.rb
|
82
82
|
- lib/rubocop/cop/sorbet/rbi/forbid_rbi_outside_of_allowed_paths.rb
|
83
83
|
- lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb
|
84
|
+
- lib/rubocop/cop/sorbet/rbi_versioning/gem_version_annotation_helper.rb
|
85
|
+
- lib/rubocop/cop/sorbet/rbi_versioning/valid_gem_version_annotations.rb
|
84
86
|
- lib/rubocop/cop/sorbet/redundant_extend_t_sig.rb
|
85
87
|
- lib/rubocop/cop/sorbet/sigils/enforce_sigil_order.rb
|
86
88
|
- lib/rubocop/cop/sorbet/sigils/enforce_single_sigil.rb
|
@@ -133,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
135
|
- !ruby/object:Gem::Version
|
134
136
|
version: '0'
|
135
137
|
requirements: []
|
136
|
-
rubygems_version: 3.5.
|
138
|
+
rubygems_version: 3.5.16
|
137
139
|
signing_key:
|
138
140
|
specification_version: 4
|
139
141
|
summary: Automatic Sorbet code style checking tool.
|