rubocop 1.5.0 → 1.5.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: 4ce46e11fac05ae40731d9a49b0c4229aa719d395a3f946b294965c52513ad1b
4
- data.tar.gz: 56c6f908f370d96d011287d67172e41c9a8a3a21748fb04d5235d0f957ffd64f
3
+ metadata.gz: 6385e74786dea3c867437d18cb40ed5715ed391e14c05f9589b9029b5d8e3b82
4
+ data.tar.gz: 56ca46faf293f235cecc7e9efc3590f355889b837bf2a9d27c224eb62e5a5ac5
5
5
  SHA512:
6
- metadata.gz: f58d45c385e3fcccee94a8c258dd9536fb768c8ae069201411bb22f3c33dac0806b1d177f7f5562a27b71ae25ab3896917c06c29703c1f1c7d276506442069c6
7
- data.tar.gz: ca55f537a662481c1337f6301d162074138c76a36c3332715aa2304ef2b67363df4b026ec1aa4dabe6e9c6b7833c0ed48edca99ea249a152a6a563a6242beeac
6
+ metadata.gz: 1f7dd2432b886b8a843fb168179d51a1f2944c045261d461a35e3a40942d55de8a837051bb06635482cf29db50f6bb8f4be16bf284a9596d70ab3e1235a296ec
7
+ data.tar.gz: 3cdc1f213db45d58d9ae5f2b05a6ed93d9c5cb18bf096e7ff2c848bdf191f70b1af011401a97c70f54a0a63107a24bb60c7eea50284a3f7b9467e522c3d9b183
@@ -11,6 +11,15 @@ module RuboCop
11
11
 
12
12
  self.command_name = :suggest_extensions
13
13
 
14
+ def self.dependent_gems
15
+ return [] unless defined?(Bundler)
16
+
17
+ # This only includes gems in Gemfile, not in lockfile
18
+ Bundler.load.dependencies.map(&:name)
19
+ rescue Bundler::GemfileNotFound
20
+ []
21
+ end
22
+
14
23
  def run
15
24
  return if skip? || extensions.none?
16
25
 
@@ -18,14 +27,17 @@ module RuboCop
18
27
  puts 'Tip: Based on detected gems, the following '\
19
28
  'RuboCop extension libraries might be helpful:'
20
29
 
21
- extensions.each do |extension|
30
+ extensions.sort.each do |extension|
22
31
  puts " * #{extension} (http://github.com/rubocop-hq/#{extension})"
23
32
  end
24
33
 
25
34
  puts
26
- puts 'You can opt out of this message by adding the following to your config:'
35
+ puts 'You can opt out of this message by adding the following to your config '\
36
+ '(see https://docs.rubocop.org/rubocop/extensions.html#extension-suggestions '\
37
+ 'for more options):'
27
38
  puts ' AllCops:'
28
39
  puts ' SuggestExtensions: false'
40
+
29
41
  puts if @options[:display_time]
30
42
  end
31
43
 
@@ -46,21 +58,22 @@ module RuboCop
46
58
  end
47
59
 
48
60
  def extensions
49
- extensions = @config_store.for_pwd.for_all_cops['SuggestExtensions']
50
- return [] unless extensions
51
-
52
- extensions.select { |_, v| (v & dependent_gems).any? }.keys - dependent_gems
53
- end
61
+ return [] unless dependent_gems.any?
54
62
 
55
- def dependent_gems
56
- # This only includes gems in Gemfile, not in lockfile
57
- Bundler.load.dependencies.map(&:name)
63
+ @extensions ||= begin
64
+ extensions = @config_store.for_pwd.for_all_cops['SuggestExtensions'] || {}
65
+ extensions.select { |_, v| (Array(v) & dependent_gems).any? }.keys - dependent_gems
66
+ end
58
67
  end
59
68
 
60
69
  def puts(*args)
61
70
  output = (@options[:stderr] ? $stderr : $stdout)
62
71
  output.puts(*args)
63
72
  end
73
+
74
+ def dependent_gems
75
+ @dependent_gems ||= self.class.dependent_gems
76
+ end
64
77
  end
65
78
  end
66
79
  end
@@ -59,7 +59,7 @@ module RuboCop
59
59
  private
60
60
 
61
61
  def receiver_and_method_call_on_different_lines?(node)
62
- node.receiver && node.receiver.loc.last_line != node.loc.selector.line
62
+ node.receiver && node.receiver.loc.last_line != node.loc.selector&.line
63
63
  end
64
64
 
65
65
  def empty_lines(node)
@@ -23,10 +23,11 @@ module RuboCop
23
23
  'Use double quoted strings if you need interpolation.'
24
24
 
25
25
  def on_str(node)
26
- parent = node.parent
27
- return if parent && (parent.dstr_type? || parent.regexp_type?)
26
+ return unless node
27
+ return if string_or_regex?(node.parent)
28
28
  return unless /(?<!\\)#\{.*\}/.match?(node.source)
29
29
  return if heredoc?(node)
30
+ return unless node.loc.begin && node.loc.end
30
31
 
31
32
  add_offense(node) do |corrector|
32
33
  autocorrect(corrector, node)
@@ -35,6 +36,10 @@ module RuboCop
35
36
 
36
37
  private
37
38
 
39
+ def string_or_regex?(node)
40
+ node&.dstr_type? || node&.regexp_type?
41
+ end
42
+
38
43
  def autocorrect(corrector, node)
39
44
  starting_token, ending_token = if node.source.include?('"')
40
45
  ['%{', '}']
@@ -104,6 +104,8 @@ module RuboCop
104
104
  def on_arg(node)
105
105
  @node = node
106
106
  name, = *node
107
+ return if allowed_identifier?(name)
108
+
107
109
  check_name(node, name, node.loc.name)
108
110
  end
109
111
  alias on_lvasgn on_arg
@@ -139,7 +141,7 @@ module RuboCop
139
141
  end
140
142
 
141
143
  def allowed_identifier?(name)
142
- allowed_identifiers.include?(name.to_s)
144
+ allowed_identifiers.include?(name.to_s.delete('@'))
143
145
  end
144
146
 
145
147
  def allowed_identifiers
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.5.0'
6
+ STRING = '1.5.1'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, '\
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-12-01 00:00:00.000000000 Z
13
+ date: 2020-12-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parallel