rubocop-performance 1.5.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +5 -1
  4. data/config/default.yml +75 -6
  5. data/lib/rubocop/cop/mixin/regexp_metacharacter.rb +76 -0
  6. data/lib/rubocop/cop/mixin/sort_block.rb +28 -0
  7. data/lib/rubocop/cop/performance/ancestors_include.rb +45 -0
  8. data/lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb +43 -0
  9. data/lib/rubocop/cop/performance/bind_call.rb +87 -0
  10. data/lib/rubocop/cop/performance/caller.rb +3 -3
  11. data/lib/rubocop/cop/performance/casecmp.rb +5 -3
  12. data/lib/rubocop/cop/performance/chain_array_allocation.rb +1 -1
  13. data/lib/rubocop/cop/performance/compare_with_block.rb +2 -2
  14. data/lib/rubocop/cop/performance/count.rb +3 -3
  15. data/lib/rubocop/cop/performance/delete_prefix.rb +96 -0
  16. data/lib/rubocop/cop/performance/delete_suffix.rb +96 -0
  17. data/lib/rubocop/cop/performance/detect.rb +1 -1
  18. data/lib/rubocop/cop/performance/double_start_end_with.rb +2 -2
  19. data/lib/rubocop/cop/performance/end_with.rb +36 -13
  20. data/lib/rubocop/cop/performance/fixed_size.rb +1 -1
  21. data/lib/rubocop/cop/performance/flat_map.rb +1 -1
  22. data/lib/rubocop/cop/performance/inefficient_hash_search.rb +1 -1
  23. data/lib/rubocop/cop/performance/io_readlines.rb +127 -0
  24. data/lib/rubocop/cop/performance/open_struct.rb +1 -1
  25. data/lib/rubocop/cop/performance/range_include.rb +10 -8
  26. data/lib/rubocop/cop/performance/redundant_block_call.rb +3 -3
  27. data/lib/rubocop/cop/performance/redundant_match.rb +2 -2
  28. data/lib/rubocop/cop/performance/redundant_merge.rb +21 -8
  29. data/lib/rubocop/cop/performance/redundant_sort_block.rb +53 -0
  30. data/lib/rubocop/cop/performance/redundant_string_chars.rb +137 -0
  31. data/lib/rubocop/cop/performance/regexp_match.rb +13 -13
  32. data/lib/rubocop/cop/performance/reverse_each.rb +3 -2
  33. data/lib/rubocop/cop/performance/reverse_first.rb +78 -0
  34. data/lib/rubocop/cop/performance/size.rb +35 -37
  35. data/lib/rubocop/cop/performance/sort_reverse.rb +54 -0
  36. data/lib/rubocop/cop/performance/squeeze.rb +70 -0
  37. data/lib/rubocop/cop/performance/start_with.rb +36 -16
  38. data/lib/rubocop/cop/performance/string_include.rb +57 -0
  39. data/lib/rubocop/cop/performance/string_replacement.rb +4 -11
  40. data/lib/rubocop/cop/performance/times_map.rb +1 -1
  41. data/lib/rubocop/cop/performance/unfreeze_string.rb +3 -7
  42. data/lib/rubocop/cop/performance/uri_default_parser.rb +1 -1
  43. data/lib/rubocop/cop/performance_cops.rb +15 -0
  44. data/lib/rubocop/performance/inject.rb +1 -1
  45. data/lib/rubocop/performance/version.rb +1 -1
  46. metadata +25 -11
@@ -26,9 +26,8 @@ module RuboCop
26
26
  DELETE = 'delete'
27
27
  TR = 'tr'
28
28
  BANG = '!'
29
- SINGLE_QUOTE = "'"
30
29
 
31
- def_node_matcher :string_replacement?, <<-PATTERN
30
+ def_node_matcher :string_replacement?, <<~PATTERN
32
31
  (send _ {:gsub :gsub!}
33
32
  ${regexp str (send (const nil? :Regexp) {:new :compile} _)}
34
33
  $str)
@@ -48,9 +47,7 @@ module RuboCop
48
47
  first_source, = first_source(first_param)
49
48
  second_source, = *second_param
50
49
 
51
- unless first_param.str_type?
52
- first_source = interpret_string_escapes(first_source)
53
- end
50
+ first_source = interpret_string_escapes(first_source) unless first_param.str_type?
54
51
 
55
52
  replacement_method =
56
53
  replacement_method(node, first_source, second_source)
@@ -67,9 +64,7 @@ module RuboCop
67
64
  to_string_literal(first))
68
65
  end
69
66
 
70
- if second.empty? && first.length == 1
71
- remove_second_param(corrector, node, first_param)
72
- end
67
+ remove_second_param(corrector, node, first_param) if second.empty? && first.length == 1
73
68
  end
74
69
  end
75
70
 
@@ -99,9 +94,7 @@ module RuboCop
99
94
 
100
95
  def offense(node, first_param, second_param)
101
96
  first_source, = first_source(first_param)
102
- unless first_param.str_type?
103
- first_source = interpret_string_escapes(first_source)
104
- end
97
+ first_source = interpret_string_escapes(first_source) unless first_param.str_type?
105
98
  second_source, = *second_param
106
99
  message = message(node, first_source, second_source)
107
100
 
@@ -61,7 +61,7 @@ module RuboCop
61
61
  map_or_collect: map_or_collect.method_name)
62
62
  end
63
63
 
64
- def_node_matcher :times_map_call, <<-PATTERN
64
+ def_node_matcher :times_map_call, <<~PATTERN
65
65
  {(block $(send (send $!nil? :times) {:map :collect}) ...)
66
66
  $(send (send $!nil? :times) {:map :collect} (block_pass ...))}
67
67
  PATTERN
@@ -7,7 +7,7 @@ module RuboCop
7
7
  # literal instead of `String#dup` and `String.new`.
8
8
  # Unary plus operator is faster than `String#dup`.
9
9
  #
10
- # Note: `String.new` (without operator) is not exactly the same as `+''`.
10
+ # NOTE: `String.new` (without operator) is not exactly the same as `+''`.
11
11
  # These differ in encoding. `String.new.encoding` is always `ASCII-8BIT`.
12
12
  # However, `(+'').encoding` is the same as script encoding(e.g. `UTF-8`).
13
13
  # So, if you expect `ASCII-8BIT` encoding, disable this cop.
@@ -24,17 +24,13 @@ module RuboCop
24
24
  # +'something'
25
25
  # +''
26
26
  class UnfreezeString < Cop
27
- extend TargetRubyVersion
28
-
29
- minimum_target_ruby_version 2.3
30
-
31
27
  MSG = 'Use unary plus to get an unfrozen string literal.'
32
28
 
33
- def_node_matcher :dup_string?, <<-PATTERN
29
+ def_node_matcher :dup_string?, <<~PATTERN
34
30
  (send {str dstr} :dup)
35
31
  PATTERN
36
32
 
37
- def_node_matcher :string_new?, <<-PATTERN
33
+ def_node_matcher :string_new?, <<~PATTERN
38
34
  {
39
35
  (send (const nil? :String) :new {str dstr})
40
36
  (send (const nil? :String) :new)
@@ -17,7 +17,7 @@ module RuboCop
17
17
  MSG = 'Use `%<double_colon>sURI::DEFAULT_PARSER` instead of ' \
18
18
  '`%<double_colon>sURI::Parser.new`.'
19
19
 
20
- def_node_matcher :uri_parser_new?, <<-PATTERN
20
+ def_node_matcher :uri_parser_new?, <<~PATTERN
21
21
  (send
22
22
  (const
23
23
  (const ${nil? cbase} :URI) :Parser) :new)
@@ -1,10 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'mixin/regexp_metacharacter'
4
+ require_relative 'mixin/sort_block'
5
+
6
+ require_relative 'performance/ancestors_include'
7
+ require_relative 'performance/big_decimal_with_numeric_argument'
8
+ require_relative 'performance/bind_call'
3
9
  require_relative 'performance/caller'
4
10
  require_relative 'performance/case_when_splat'
5
11
  require_relative 'performance/casecmp'
6
12
  require_relative 'performance/compare_with_block'
7
13
  require_relative 'performance/count'
14
+ require_relative 'performance/delete_prefix'
15
+ require_relative 'performance/delete_suffix'
8
16
  require_relative 'performance/detect'
9
17
  require_relative 'performance/double_start_end_with'
10
18
  require_relative 'performance/end_with'
@@ -13,13 +21,20 @@ require_relative 'performance/flat_map'
13
21
  require_relative 'performance/inefficient_hash_search'
14
22
  require_relative 'performance/open_struct'
15
23
  require_relative 'performance/range_include'
24
+ require_relative 'performance/io_readlines'
16
25
  require_relative 'performance/redundant_block_call'
17
26
  require_relative 'performance/redundant_match'
18
27
  require_relative 'performance/redundant_merge'
28
+ require_relative 'performance/redundant_sort_block'
29
+ require_relative 'performance/redundant_string_chars'
19
30
  require_relative 'performance/regexp_match'
20
31
  require_relative 'performance/reverse_each'
32
+ require_relative 'performance/reverse_first'
21
33
  require_relative 'performance/size'
34
+ require_relative 'performance/sort_reverse'
35
+ require_relative 'performance/squeeze'
22
36
  require_relative 'performance/start_with'
37
+ require_relative 'performance/string_include'
23
38
  require_relative 'performance/string_replacement'
24
39
  require_relative 'performance/times_map'
25
40
  require_relative 'performance/unfreeze_string'
@@ -8,7 +8,7 @@ module RuboCop
8
8
  def self.defaults!
9
9
  path = CONFIG_DEFAULT.to_s
10
10
  hash = ConfigLoader.send(:load_yaml_configuration, path)
11
- config = Config.new(hash, path)
11
+ config = Config.new(hash, path).tap(&:make_excludes_absolute)
12
12
  puts "configuration from #{path}" if ConfigLoader.debug?
13
13
  config = ConfigLoader.merge_with_default(config, path)
14
14
  ConfigLoader.instance_variable_set(:@default_configuration, config)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Performance
5
5
  module Version
6
- STRING = '1.5.0'
6
+ STRING = '1.7.0'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-performance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-10-01 00:00:00.000000000 Z
13
+ date: 2020-07-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: 0.71.0
21
+ version: 0.82.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: 0.71.0
28
+ version: 0.82.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: simplecov
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -40,9 +40,9 @@ dependencies:
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
- description: |2
44
- A collection of RuboCop cops to check for performance optimizations
45
- in Ruby code.
43
+ description: |
44
+ A collection of RuboCop cops to check for performance optimizations
45
+ in Ruby code.
46
46
  email: rubocop@googlegroups.com
47
47
  executables: []
48
48
  extensions: []
@@ -54,27 +54,41 @@ files:
54
54
  - README.md
55
55
  - config/default.yml
56
56
  - lib/rubocop-performance.rb
57
+ - lib/rubocop/cop/mixin/regexp_metacharacter.rb
58
+ - lib/rubocop/cop/mixin/sort_block.rb
59
+ - lib/rubocop/cop/performance/ancestors_include.rb
60
+ - lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb
61
+ - lib/rubocop/cop/performance/bind_call.rb
57
62
  - lib/rubocop/cop/performance/caller.rb
58
63
  - lib/rubocop/cop/performance/case_when_splat.rb
59
64
  - lib/rubocop/cop/performance/casecmp.rb
60
65
  - lib/rubocop/cop/performance/chain_array_allocation.rb
61
66
  - lib/rubocop/cop/performance/compare_with_block.rb
62
67
  - lib/rubocop/cop/performance/count.rb
68
+ - lib/rubocop/cop/performance/delete_prefix.rb
69
+ - lib/rubocop/cop/performance/delete_suffix.rb
63
70
  - lib/rubocop/cop/performance/detect.rb
64
71
  - lib/rubocop/cop/performance/double_start_end_with.rb
65
72
  - lib/rubocop/cop/performance/end_with.rb
66
73
  - lib/rubocop/cop/performance/fixed_size.rb
67
74
  - lib/rubocop/cop/performance/flat_map.rb
68
75
  - lib/rubocop/cop/performance/inefficient_hash_search.rb
76
+ - lib/rubocop/cop/performance/io_readlines.rb
69
77
  - lib/rubocop/cop/performance/open_struct.rb
70
78
  - lib/rubocop/cop/performance/range_include.rb
71
79
  - lib/rubocop/cop/performance/redundant_block_call.rb
72
80
  - lib/rubocop/cop/performance/redundant_match.rb
73
81
  - lib/rubocop/cop/performance/redundant_merge.rb
82
+ - lib/rubocop/cop/performance/redundant_sort_block.rb
83
+ - lib/rubocop/cop/performance/redundant_string_chars.rb
74
84
  - lib/rubocop/cop/performance/regexp_match.rb
75
85
  - lib/rubocop/cop/performance/reverse_each.rb
86
+ - lib/rubocop/cop/performance/reverse_first.rb
76
87
  - lib/rubocop/cop/performance/size.rb
88
+ - lib/rubocop/cop/performance/sort_reverse.rb
89
+ - lib/rubocop/cop/performance/squeeze.rb
77
90
  - lib/rubocop/cop/performance/start_with.rb
91
+ - lib/rubocop/cop/performance/string_include.rb
78
92
  - lib/rubocop/cop/performance/string_replacement.rb
79
93
  - lib/rubocop/cop/performance/times_map.rb
80
94
  - lib/rubocop/cop/performance/unfreeze_string.rb
@@ -87,10 +101,10 @@ homepage: https://github.com/rubocop-hq/rubocop-performance
87
101
  licenses:
88
102
  - MIT
89
103
  metadata:
90
- homepage_uri: https://docs.rubocop.org/projects/performance
104
+ homepage_uri: https://docs.rubocop.org/rubocop-performance/
91
105
  changelog_uri: https://github.com/rubocop-hq/rubocop-performance/blob/master/CHANGELOG.md
92
106
  source_code_uri: https://github.com/rubocop-hq/rubocop-performance/
93
- documentation_uri: https://docs.rubocop.org/projects/performance
107
+ documentation_uri: https://docs.rubocop.org/rubocop-performance/
94
108
  bug_tracker_uri: https://github.com/rubocop-hq/rubocop-performance/issues
95
109
  post_install_message:
96
110
  rdoc_options: []
@@ -100,14 +114,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
102
116
  - !ruby/object:Gem::Version
103
- version: 2.3.0
117
+ version: 2.4.0
104
118
  required_rubygems_version: !ruby/object:Gem::Requirement
105
119
  requirements:
106
120
  - - ">="
107
121
  - !ruby/object:Gem::Version
108
122
  version: '0'
109
123
  requirements: []
110
- rubygems_version: 3.0.6
124
+ rubygems_version: 3.1.4
111
125
  signing_key:
112
126
  specification_version: 4
113
127
  summary: Automatic performance checking tool for Ruby code.