rubocop-sorbet 0.8.5 → 0.8.6

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: 9dfcaff074a9af626b94a6909e3d6c3ea99749bced60c513d123cc00d4af2f26
4
- data.tar.gz: 961d6723c8fa9e67dd25febab735a58ea4a7023c46132b008f3a8c4f996a18c6
3
+ metadata.gz: 5eabd8cb864c16962c3d9f7ca1cb64bd9a811424bc480df6f976f28c2741eb97
4
+ data.tar.gz: c25050b4162e19a06c525e7e008a79ed8ffd1217c24e57cd03e4af88f4194abf
5
5
  SHA512:
6
- metadata.gz: 927874817f3166896f9cbb5267f95fa18570ce29c01432ff076a9949b71986bc13ccdbb849bf943b4b908bc5b682448d381c5b7e579af3f1f963662ef93bf606
7
- data.tar.gz: 2ad69a1852bea8490f7c3b0cb157482dc0176abeae0f8834f8e8afcc7b582db822a3fa86df331d3315743628f40a9352af45a320de12bb4e990c216babc041a1
6
+ metadata.gz: 2cbc0786d76687e380eb8252a580bbfa06fb893d0b283ca7a04516f85f77ccec4ec39d5d6eaecdda31fc1cc5ffa0a2d9b3b6f3357dd1a9a4bd83aa1f0265d617
7
+ data.tar.gz: a22169eca15cf38a85cbf234c73cf26aed164460af125ed15978feab77cc7fdf2555b5f71037ba4a5c938e3861d0bee6d8141bfe5ee30a37bcf3fa71bcc37fd7
@@ -5,6 +5,11 @@ updates:
5
5
  schedule:
6
6
  interval: "weekly"
7
7
  open-pull-requests-limit: 100
8
+ groups:
9
+ minor-and-patch:
10
+ update-types:
11
+ - "minor"
12
+ - "patch"
8
13
  - package-ecosystem: "github-actions"
9
14
  directory: "/"
10
15
  schedule:
@@ -0,0 +1,65 @@
1
+ name: Dependabot auto-merge
2
+ on: pull_request_target
3
+
4
+ permissions:
5
+ pull-requests: write
6
+ contents: write
7
+
8
+ jobs:
9
+ dependabot:
10
+ runs-on: ubuntu-latest
11
+ if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
12
+ steps:
13
+ - name: Dependabot metadata
14
+ id: metadata
15
+ uses: dependabot/fetch-metadata@v2
16
+ with:
17
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
18
+ - name: Enable auto-merge for Dependabot PRs
19
+ if: ${{ steps.metadata.outputs.update-type != 'version-update:semver-major' }}
20
+ uses: actions/github-script@v7
21
+ with:
22
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
23
+ script: |
24
+ const getPullRequestIdQuery = `query GetPullRequestId($owner: String!, $repo: String!, $pullRequestNumber: Int!) {
25
+ repository(owner: $owner, name: $repo) {
26
+ pullRequest(number: $pullRequestNumber) {
27
+ id
28
+ }
29
+ }
30
+ }`
31
+ const repoInfo = {
32
+ owner: context.repo.owner,
33
+ repo: context.repo.repo,
34
+ pullRequestNumber: context.issue.number,
35
+ }
36
+ const response = await github.graphql(getPullRequestIdQuery, repoInfo)
37
+
38
+ await github.rest.pulls.createReview({
39
+ pull_number: context.issue.number,
40
+ owner: context.repo.owner,
41
+ repo: context.repo.repo,
42
+ event: 'APPROVE',
43
+ })
44
+
45
+ const enableAutoMergeQuery = `mutation ($pullRequestId: ID!, $mergeMethod: PullRequestMergeMethod!) {
46
+ enablePullRequestAutoMerge(input: {
47
+ pullRequestId: $pullRequestId,
48
+ mergeMethod: $mergeMethod
49
+ }) {
50
+ pullRequest {
51
+ autoMergeRequest {
52
+ enabledAt
53
+ enabledBy {
54
+ login
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }`
60
+ const data = {
61
+ pullRequestId: response.repository.pullRequest.id,
62
+ mergeMethod: 'MERGE',
63
+ }
64
+
65
+ await github.graphql(enableAutoMergeQuery, data)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-sorbet (0.8.5)
4
+ rubocop-sorbet (0.8.6)
5
5
  rubocop (>= 1)
6
6
 
7
7
  GEM
@@ -18,13 +18,13 @@ GEM
18
18
  reline (>= 0.4.2)
19
19
  json (2.7.2)
20
20
  language_server-protocol (3.17.0.3)
21
- parallel (1.25.1)
22
- parser (3.3.4.0)
21
+ parallel (1.26.3)
22
+ parser (3.3.5.0)
23
23
  ast (~> 2.4.1)
24
24
  racc
25
25
  psych (5.1.2)
26
26
  stringio
27
- racc (1.8.0)
27
+ racc (1.8.1)
28
28
  rainbow (3.1.1)
29
29
  rake (13.2.1)
30
30
  rdoc (6.6.3.1)
@@ -32,8 +32,6 @@ GEM
32
32
  regexp_parser (2.9.2)
33
33
  reline (0.5.1)
34
34
  io-console (~> 0.5)
35
- rexml (3.3.1)
36
- strscan
37
35
  rspec (3.13.0)
38
36
  rspec-core (~> 3.13.0)
39
37
  rspec-expectations (~> 3.13.0)
@@ -47,26 +45,24 @@ GEM
47
45
  diff-lcs (>= 1.2.0, < 2.0)
48
46
  rspec-support (~> 3.13.0)
49
47
  rspec-support (3.13.1)
50
- rubocop (1.65.0)
48
+ rubocop (1.66.1)
51
49
  json (~> 2.3)
52
50
  language_server-protocol (>= 3.17.0)
53
51
  parallel (~> 1.10)
54
52
  parser (>= 3.3.0.2)
55
53
  rainbow (>= 2.2.2, < 4.0)
56
54
  regexp_parser (>= 2.4, < 3.0)
57
- rexml (>= 3.2.5, < 4.0)
58
- rubocop-ast (>= 1.31.1, < 2.0)
55
+ rubocop-ast (>= 1.32.2, < 2.0)
59
56
  ruby-progressbar (~> 1.7)
60
57
  unicode-display_width (>= 2.4.0, < 3.0)
61
- rubocop-ast (1.31.3)
58
+ rubocop-ast (1.32.3)
62
59
  parser (>= 3.3.1.0)
63
60
  rubocop-shopify (2.15.1)
64
61
  rubocop (~> 1.51)
65
62
  ruby-progressbar (1.13.0)
66
63
  stringio (3.1.0)
67
- strscan (3.1.0)
68
64
  unicode-display_width (2.5.0)
69
- yard (0.9.36)
65
+ yard (0.9.37)
70
66
 
71
67
  PLATFORMS
72
68
  ruby
data/config/default.yml CHANGED
@@ -1,3 +1,11 @@
1
+ Sorbet/Refinement:
2
+ Description: >-
3
+ Checks for the use of Ruby Refinements library. Refinements add
4
+ complexity and incur a performance penalty that can be significant
5
+ for large code bases. They are also not supported by Sorbet.
6
+ Enabled: pending
7
+ VersionAdded: '<<next>>'
8
+
1
9
  inherit_mode:
2
10
  merge:
3
11
  - Exclude
@@ -46,6 +46,7 @@ module RuboCop
46
46
  def on_send(node)
47
47
  add_offense(node.selector, message: format(MSG, method_name: node.method_name))
48
48
  end
49
+ alias_method :on_csend, :on_send
49
50
  end
50
51
  end
51
52
  end
@@ -44,7 +44,7 @@ module RuboCop
44
44
  def read_sorbet_static_version_from_bundler_lock_file
45
45
  require "bundler"
46
46
  ::Bundler.locked_gems.specs.find { |spec| spec.name == "sorbet-static" }&.version
47
- rescue LoadError, Bundler::GemfileNotFound
47
+ rescue LoadError, ::Bundler::GemfileNotFound
48
48
  nil
49
49
  end
50
50
  end
@@ -27,16 +27,10 @@ module RuboCop
27
27
  paths = allowed_paths
28
28
 
29
29
  if paths.nil?
30
- add_offense(
31
- source_range(processed_source.buffer, 1, 0),
32
- message: "AllowedPaths expects an array",
33
- )
30
+ add_global_offense("AllowedPaths expects an array")
34
31
  return
35
32
  elsif paths.empty?
36
- add_offense(
37
- source_range(processed_source.buffer, 1, 0),
38
- message: "AllowedPaths cannot be empty",
39
- )
33
+ add_global_offense("AllowedPaths cannot be empty")
40
34
  return
41
35
  end
42
36
 
@@ -44,9 +38,8 @@ module RuboCop
44
38
  # We need to remove the exec path directory prefix before matching with the filename regular expressions.
45
39
  rel_path = processed_source.file_path.sub("#{Dir.pwd}/", "")
46
40
 
47
- add_offense(
48
- source_range(processed_source.buffer, 1, 0),
49
- message: "RBI file path should match one of: #{paths.join(", ")}",
41
+ add_global_offense(
42
+ "RBI file path should match one of: #{paths.join(", ")}",
50
43
  ) if paths.none? { |pattern| File.fnmatch(pattern, rel_path) }
51
44
  end
52
45
 
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Sorbet
6
+ # Checks for the use of Ruby Refinements library. Refinements add
7
+ # complexity and incur a performance penalty that can be significant
8
+ # for large code bases. Good examples are cases of unrelated
9
+ # methods that happen to have the same name as these module methods.
10
+ #
11
+ # @example
12
+ # # bad
13
+ # module Foo
14
+ # refine(Date) do
15
+ # end
16
+ # end
17
+ #
18
+ # # bad
19
+ # module Foo
20
+ # using(Date) do
21
+ # end
22
+ # end
23
+ #
24
+ # # good
25
+ # module Foo
26
+ # bar.refine(Date)
27
+ # end
28
+ #
29
+ # # good
30
+ # module Foo
31
+ # bar.using(Date)
32
+ # end
33
+
34
+ class Refinement < Base
35
+ MSG = "Do not use Ruby Refinements library as it is not supported by Sorbet."
36
+ RESTRICT_ON_SEND = [:refine, :using].freeze
37
+
38
+ def on_send(node)
39
+ return unless node.receiver.nil?
40
+ return unless node.first_argument&.const_type?
41
+
42
+ if node.method?(:refine)
43
+ return unless node.block_node
44
+ return unless node.parent.parent.module_type?
45
+ end
46
+
47
+ add_offense(node)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -16,6 +16,7 @@ require_relative "sorbet/forbid_t_struct"
16
16
  require_relative "sorbet/forbid_t_unsafe"
17
17
  require_relative "sorbet/forbid_t_untyped"
18
18
  require_relative "sorbet/redundant_extend_t_sig"
19
+ require_relative "sorbet/refinement"
19
20
  require_relative "sorbet/type_alias_name"
20
21
  require_relative "sorbet/obsolete_strict_memoization"
21
22
  require_relative "sorbet/buggy_obsolete_strict_memoization"
@@ -11,6 +11,14 @@ module RuboCop
11
11
  def defaults!
12
12
  path = CONFIG_DEFAULT.to_s
13
13
  hash = ConfigLoader.send(:load_yaml_configuration, path)
14
+ if Gem::Version.new(RuboCop::Version::STRING) >= Gem::Version.new("1.66")
15
+ # We use markdown for cop documentation. Unconditionally setting
16
+ # the base url will produce incorrect urls on older RuboCop versions,
17
+ # so we do that for fully supported version only here.
18
+ hash["Sorbet"] ||= {}
19
+ hash["Sorbet"]["DocumentationBaseURL"] = "https://github.com/Shopify/rubocop-sorbet/blob/main/manual"
20
+ hash["Sorbet"]["DocumentationExtension"] = ".md"
21
+ end
14
22
  config = Config.new(hash, path).tap(&:make_excludes_absolute)
15
23
  puts "configuration from #{path}" if ConfigLoader.debug?
16
24
  config = ConfigLoader.merge_with_default(config, path)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Sorbet
5
- VERSION = "0.8.5"
5
+ VERSION = "0.8.6"
6
6
  end
7
7
  end
data/manual/cops.md CHANGED
@@ -33,6 +33,7 @@ In the following section you find all available cops:
33
33
  * [Sorbet/MultipleTEnumValues](cops_sorbet.md#sorbetmultipletenumvalues)
34
34
  * [Sorbet/ObsoleteStrictMemoization](cops_sorbet.md#sorbetobsoletestrictmemoization)
35
35
  * [Sorbet/RedundantExtendTSig](cops_sorbet.md#sorbetredundantextendtsig)
36
+ * [Sorbet/Refinement](cops_sorbet.md#sorbetrefinement)
36
37
  * [Sorbet/SignatureBuildOrder](cops_sorbet.md#sorbetsignaturebuildorder)
37
38
  * [Sorbet/SingleLineRbiClassModuleDefinitions](cops_sorbet.md#sorbetsinglelinerbiclassmoduledefinitions)
38
39
  * [Sorbet/StrictSigil](cops_sorbet.md#sorbetstrictsigil)
@@ -759,6 +759,43 @@ class Example
759
759
  end
760
760
  ```
761
761
 
762
+ ## Sorbet/Refinement
763
+
764
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
765
+ --- | --- | --- | --- | ---
766
+ Enabled | Yes | No | <<next>> | -
767
+
768
+ Checks for the use of Ruby Refinements library. Refinements add
769
+ complexity and incur a performance penalty that can be significant
770
+ for large code bases. Good examples are cases of unrelated
771
+ methods that happen to have the same name as these module methods.
772
+
773
+ ### Examples
774
+
775
+ ```ruby
776
+ # bad
777
+ module Foo
778
+ refine(Date) do
779
+ end
780
+ end
781
+
782
+ # bad
783
+ module Foo
784
+ using(Date) do
785
+ end
786
+ end
787
+
788
+ # good
789
+ module Foo
790
+ bar.refine(Date)
791
+ end
792
+
793
+ # good
794
+ module Foo
795
+ bar.using(Date)
796
+ end
797
+ ```
798
+
762
799
  ## Sorbet/SignatureBuildOrder
763
800
 
764
801
  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.5
4
+ version: 0.8.6
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-25 00:00:00.000000000 Z
14
+ date: 2024-10-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rubocop
@@ -39,6 +39,7 @@ files:
39
39
  - ".github/release.yml"
40
40
  - ".github/workflows/ci.yml"
41
41
  - ".github/workflows/cla.yml"
42
+ - ".github/workflows/dependabot_automerge.yml"
42
43
  - ".github/workflows/stale.yml"
43
44
  - ".gitignore"
44
45
  - ".rspec"
@@ -84,6 +85,7 @@ files:
84
85
  - lib/rubocop/cop/sorbet/rbi_versioning/gem_version_annotation_helper.rb
85
86
  - lib/rubocop/cop/sorbet/rbi_versioning/valid_gem_version_annotations.rb
86
87
  - lib/rubocop/cop/sorbet/redundant_extend_t_sig.rb
88
+ - lib/rubocop/cop/sorbet/refinement.rb
87
89
  - lib/rubocop/cop/sorbet/sigils/enforce_sigil_order.rb
88
90
  - lib/rubocop/cop/sorbet/sigils/enforce_single_sigil.rb
89
91
  - lib/rubocop/cop/sorbet/sigils/false_sigil.rb
@@ -135,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
137
  - !ruby/object:Gem::Version
136
138
  version: '0'
137
139
  requirements: []
138
- rubygems_version: 3.5.16
140
+ rubygems_version: 3.5.21
139
141
  signing_key:
140
142
  specification_version: 4
141
143
  summary: Automatic Sorbet code style checking tool.