rubocop-sorbet 0.4.0 → 0.4.1

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: ed85b2aa8c9315734700e66a95850b31448f0564044857f05a8b9ffcaaa8bd69
4
- data.tar.gz: 29fbbd4eef2a6039dd1f15247d6a39c05575de00cfd3a9ec2b8a3e5258628f27
3
+ metadata.gz: b73993245df905cf40d9e0dbc440d613315e5b32d89e9b61ee123994fee53e73
4
+ data.tar.gz: '019d4212c2c204492aa38f928ddfc31cceac5d79fe6ee09927c889e3b245f999'
5
5
  SHA512:
6
- metadata.gz: a69d768ccb20841020b531c5befae05d4279b7483e26c266f61214d8702fdb67419187db6ff8f9a8bd8973113aa9861e9ef9f0295a4157397023f6e8d6cdeaab
7
- data.tar.gz: 3c2afa2c95472039e4c95bd81ffa91847a05f0114690d5e89bb5d34f4ad4d303aff4df81e107dcc79c3de146b35834bf8ca5c94595c90b5d2b6d4c1e096bb5e2
6
+ metadata.gz: d491ed5a48d75c2f5151329fc0018ca56ed57504d6d1e338befe0c9395bf85824b65f68164538667b4720eca216eeb15c29c6ed379524ae9ed1a8215cf6daf84
7
+ data.tar.gz: 7944aa4817f48ca0bb43c47dabcf197ced656674ab59ce261705b946045a2e3c0de813200187829cf9936a2144a5203ed625c8cdd89a33b7e80876229f7f2748
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ source "https://rubygems.org"
4
4
  # Specify your gem's dependencies in rubocop-sorbet.gemspec
5
5
  gemspec
6
6
 
7
- gem "rake", "~> 12.0"
7
+ gem "rake", ">= 12.3.3"
8
8
  gem "rspec"
9
9
  gem "rubocop-shopify", require: false
10
10
  gem "yard", "~> 0.9"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-sorbet (0.4.0)
4
+ rubocop-sorbet (0.4.1)
5
5
  rubocop
6
6
 
7
7
  GEM
@@ -25,7 +25,7 @@ GEM
25
25
  ast (~> 2.4.0)
26
26
  procto (0.0.3)
27
27
  rainbow (3.0.0)
28
- rake (12.3.2)
28
+ rake (13.0.1)
29
29
  regexp_parser (1.7.0)
30
30
  rexml (3.2.4)
31
31
  rspec (3.8.0)
@@ -71,7 +71,7 @@ PLATFORMS
71
71
  ruby
72
72
 
73
73
  DEPENDENCIES
74
- rake (~> 12.0)
74
+ rake (>= 12.3.3)
75
75
  rspec
76
76
  rubocop-shopify
77
77
  rubocop-sorbet!
@@ -17,7 +17,7 @@ module RuboCop
17
17
  # FooOrBar = T.type_alias { T.any(Foo, Bar) }
18
18
  class BindingConstantWithoutTypeAlias < RuboCop::Cop::Cop
19
19
  def_node_matcher(:binding_unaliased_type?, <<-PATTERN)
20
- (casgn _ _ [#not_nil? #not_t_let? #method_needing_aliasing_on_t?])
20
+ (casgn _ _ [#not_nil? #not_t_let? #not_generic_parameter_decl? #method_needing_aliasing_on_t?])
21
21
  PATTERN
22
22
 
23
23
  def_node_matcher(:using_type_alias?, <<-PATTERN)
@@ -48,6 +48,12 @@ module RuboCop
48
48
  )
49
49
  PATTERN
50
50
 
51
+ def_node_matcher(:generic_parameter_decl?, <<-PATTERN)
52
+ (
53
+ send nil? {:type_template :type_member} ...
54
+ )
55
+ PATTERN
56
+
51
57
  def_node_search(:method_needing_aliasing_on_t?, <<-PATTERN)
52
58
  (
53
59
  send
@@ -61,6 +67,10 @@ module RuboCop
61
67
  !t_let?(node)
62
68
  end
63
69
 
70
+ def not_generic_parameter_decl?(node)
71
+ !generic_parameter_decl?(node)
72
+ end
73
+
64
74
  def not_nil?(node)
65
75
  !node.nil?
66
76
  end
@@ -55,9 +55,9 @@ module RuboCop
55
55
  return nil unless can_autocorrect?
56
56
 
57
57
  lambda do |corrector|
58
- nodes = call_chain(node).sort_by { |call| ORDER[call.method_name] }
59
- tree =
60
- nodes.reduce(nil) do |receiver, caller|
58
+ tree = call_chain(node_with_index_sends(node))
59
+ .sort_by { |call| ORDER[call.method_name] }
60
+ .reduce(nil) do |receiver, caller|
61
61
  caller.updated(nil, [receiver] + caller.children.drop(1))
62
62
  end
63
63
 
@@ -70,6 +70,16 @@ module RuboCop
70
70
 
71
71
  private
72
72
 
73
+ def node_with_index_sends(node)
74
+ # This is really dirty hack to reparse the current node with index send
75
+ # emitting enabled, which is necessary to unparse them back as index accessors.
76
+ emit_index_value = RuboCop::AST::Builder.emit_index
77
+ RuboCop::AST::Builder.emit_index = true
78
+ RuboCop::AST::ProcessedSource.new(node.source, target_ruby_version, processed_source.path).ast
79
+ ensure
80
+ RuboCop::AST::Builder.emit_index = emit_index_value
81
+ end
82
+
73
83
  def can_autocorrect?
74
84
  defined?(::Unparser)
75
85
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module RuboCop
3
3
  module Sorbet
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
6
6
  end
@@ -3,4 +3,4 @@ owners:
3
3
  - Shopify/sorbet
4
4
  classification: library
5
5
  slack_channels:
6
- - sorbet
6
+ - help-ruby-typing
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.4.0
4
+ version: 0.4.1
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: 2020-06-05 00:00:00.000000000 Z
14
+ date: 2020-08-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec