rubocop-performance 1.8.0 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +10 -2
- data/config/default.yml +47 -6
- data/lib/rubocop/cop/mixin/regexp_metacharacter.rb +4 -4
- data/lib/rubocop/cop/performance/ancestors_include.rb +1 -0
- data/lib/rubocop/cop/performance/array_semi_infinite_range_slice.rb +77 -0
- data/lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb +1 -0
- data/lib/rubocop/cop/performance/bind_call.rb +3 -2
- data/lib/rubocop/cop/performance/block_given_with_explicit_block.rb +52 -0
- data/lib/rubocop/cop/performance/caller.rb +13 -15
- data/lib/rubocop/cop/performance/casecmp.rb +1 -0
- data/lib/rubocop/cop/performance/chain_array_allocation.rb +20 -18
- data/lib/rubocop/cop/performance/collection_literal_in_loop.rb +1 -1
- data/lib/rubocop/cop/performance/constant_regexp.rb +73 -0
- data/lib/rubocop/cop/performance/count.rb +1 -0
- data/lib/rubocop/cop/performance/delete_prefix.rb +1 -0
- data/lib/rubocop/cop/performance/delete_suffix.rb +1 -0
- data/lib/rubocop/cop/performance/detect.rb +47 -17
- data/lib/rubocop/cop/performance/end_with.rb +1 -0
- data/lib/rubocop/cop/performance/fixed_size.rb +1 -0
- data/lib/rubocop/cop/performance/flat_map.rb +1 -0
- data/lib/rubocop/cop/performance/inefficient_hash_search.rb +2 -0
- data/lib/rubocop/cop/performance/io_readlines.rb +3 -7
- data/lib/rubocop/cop/performance/method_object_as_block.rb +32 -0
- data/lib/rubocop/cop/performance/open_struct.rb +1 -0
- data/lib/rubocop/cop/performance/range_include.rb +1 -0
- data/lib/rubocop/cop/performance/redundant_block_call.rb +4 -4
- data/lib/rubocop/cop/performance/redundant_equality_comparison_block.rb +72 -0
- data/lib/rubocop/cop/performance/redundant_match.rb +1 -0
- data/lib/rubocop/cop/performance/redundant_merge.rb +1 -0
- data/lib/rubocop/cop/performance/redundant_split_regexp_argument.rb +67 -0
- data/lib/rubocop/cop/performance/redundant_string_chars.rb +2 -6
- data/lib/rubocop/cop/performance/reverse_each.rb +7 -10
- data/lib/rubocop/cop/performance/reverse_first.rb +1 -0
- data/lib/rubocop/cop/performance/size.rb +1 -0
- data/lib/rubocop/cop/performance/squeeze.rb +2 -1
- data/lib/rubocop/cop/performance/start_with.rb +1 -0
- data/lib/rubocop/cop/performance/string_include.rb +2 -1
- data/lib/rubocop/cop/performance/string_replacement.rb +1 -0
- data/lib/rubocop/cop/performance/sum.rb +131 -18
- data/lib/rubocop/cop/performance/times_map.rb +1 -0
- data/lib/rubocop/cop/performance/unfreeze_string.rb +19 -1
- data/lib/rubocop/cop/performance/uri_default_parser.rb +1 -0
- data/lib/rubocop/cop/performance_cops.rb +6 -0
- data/lib/rubocop/performance/version.rb +6 -1
- metadata +29 -17
@@ -10,6 +10,7 @@ module RuboCop
|
|
10
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
|
+
# Therefore, auto-correction is unsafe.
|
13
14
|
# So, if you expect `ASCII-8BIT` encoding, disable this cop.
|
14
15
|
#
|
15
16
|
# @example
|
@@ -24,7 +25,10 @@ module RuboCop
|
|
24
25
|
# +'something'
|
25
26
|
# +''
|
26
27
|
class UnfreezeString < Base
|
28
|
+
extend AutoCorrector
|
29
|
+
|
27
30
|
MSG = 'Use unary plus to get an unfrozen string literal.'
|
31
|
+
RESTRICT_ON_SEND = %i[dup new].freeze
|
28
32
|
|
29
33
|
def_node_matcher :dup_string?, <<~PATTERN
|
30
34
|
(send {str dstr} :dup)
|
@@ -38,7 +42,21 @@ module RuboCop
|
|
38
42
|
PATTERN
|
39
43
|
|
40
44
|
def on_send(node)
|
41
|
-
|
45
|
+
return unless dup_string?(node) || string_new?(node)
|
46
|
+
|
47
|
+
add_offense(node) do |corrector|
|
48
|
+
corrector.replace(node, "+#{string_value(node)}")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def string_value(node)
|
55
|
+
if node.receiver.source == 'String' && node.method?(:new)
|
56
|
+
node.arguments.empty? ? "''" : node.first_argument.source
|
57
|
+
else
|
58
|
+
node.receiver.source
|
59
|
+
end
|
42
60
|
end
|
43
61
|
end
|
44
62
|
end
|
@@ -4,13 +4,16 @@ require_relative 'mixin/regexp_metacharacter'
|
|
4
4
|
require_relative 'mixin/sort_block'
|
5
5
|
|
6
6
|
require_relative 'performance/ancestors_include'
|
7
|
+
require_relative 'performance/array_semi_infinite_range_slice'
|
7
8
|
require_relative 'performance/big_decimal_with_numeric_argument'
|
8
9
|
require_relative 'performance/bind_call'
|
10
|
+
require_relative 'performance/block_given_with_explicit_block'
|
9
11
|
require_relative 'performance/caller'
|
10
12
|
require_relative 'performance/case_when_splat'
|
11
13
|
require_relative 'performance/casecmp'
|
12
14
|
require_relative 'performance/collection_literal_in_loop'
|
13
15
|
require_relative 'performance/compare_with_block'
|
16
|
+
require_relative 'performance/constant_regexp'
|
14
17
|
require_relative 'performance/count'
|
15
18
|
require_relative 'performance/delete_prefix'
|
16
19
|
require_relative 'performance/delete_suffix'
|
@@ -20,13 +23,16 @@ require_relative 'performance/end_with'
|
|
20
23
|
require_relative 'performance/fixed_size'
|
21
24
|
require_relative 'performance/flat_map'
|
22
25
|
require_relative 'performance/inefficient_hash_search'
|
26
|
+
require_relative 'performance/method_object_as_block'
|
23
27
|
require_relative 'performance/open_struct'
|
24
28
|
require_relative 'performance/range_include'
|
25
29
|
require_relative 'performance/io_readlines'
|
26
30
|
require_relative 'performance/redundant_block_call'
|
31
|
+
require_relative 'performance/redundant_equality_comparison_block'
|
27
32
|
require_relative 'performance/redundant_match'
|
28
33
|
require_relative 'performance/redundant_merge'
|
29
34
|
require_relative 'performance/redundant_sort_block'
|
35
|
+
require_relative 'performance/redundant_split_regexp_argument'
|
30
36
|
require_relative 'performance/redundant_string_chars'
|
31
37
|
require_relative 'performance/regexp_match'
|
32
38
|
require_relative 'performance/reverse_each'
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-performance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
8
8
|
- Jonas Arvidsson
|
9
9
|
- Yuji Nakayama
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-02-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -18,28 +18,34 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: 0.90.0
|
22
|
+
- - "<"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '2.0'
|
22
25
|
type: :runtime
|
23
26
|
prerelease: false
|
24
27
|
version_requirements: !ruby/object:Gem::Requirement
|
25
28
|
requirements:
|
26
29
|
- - ">="
|
27
30
|
- !ruby/object:Gem::Version
|
28
|
-
version: 0.
|
31
|
+
version: 0.90.0
|
32
|
+
- - "<"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '2.0'
|
29
35
|
- !ruby/object:Gem::Dependency
|
30
|
-
name:
|
36
|
+
name: rubocop-ast
|
31
37
|
requirement: !ruby/object:Gem::Requirement
|
32
38
|
requirements:
|
33
39
|
- - ">="
|
34
40
|
- !ruby/object:Gem::Version
|
35
|
-
version:
|
36
|
-
type: :
|
41
|
+
version: 0.4.0
|
42
|
+
type: :runtime
|
37
43
|
prerelease: false
|
38
44
|
version_requirements: !ruby/object:Gem::Requirement
|
39
45
|
requirements:
|
40
46
|
- - ">="
|
41
47
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
48
|
+
version: 0.4.0
|
43
49
|
description: |
|
44
50
|
A collection of RuboCop cops to check for performance optimizations
|
45
51
|
in Ruby code.
|
@@ -57,14 +63,17 @@ files:
|
|
57
63
|
- lib/rubocop/cop/mixin/regexp_metacharacter.rb
|
58
64
|
- lib/rubocop/cop/mixin/sort_block.rb
|
59
65
|
- lib/rubocop/cop/performance/ancestors_include.rb
|
66
|
+
- lib/rubocop/cop/performance/array_semi_infinite_range_slice.rb
|
60
67
|
- lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb
|
61
68
|
- lib/rubocop/cop/performance/bind_call.rb
|
69
|
+
- lib/rubocop/cop/performance/block_given_with_explicit_block.rb
|
62
70
|
- lib/rubocop/cop/performance/caller.rb
|
63
71
|
- lib/rubocop/cop/performance/case_when_splat.rb
|
64
72
|
- lib/rubocop/cop/performance/casecmp.rb
|
65
73
|
- lib/rubocop/cop/performance/chain_array_allocation.rb
|
66
74
|
- lib/rubocop/cop/performance/collection_literal_in_loop.rb
|
67
75
|
- lib/rubocop/cop/performance/compare_with_block.rb
|
76
|
+
- lib/rubocop/cop/performance/constant_regexp.rb
|
68
77
|
- lib/rubocop/cop/performance/count.rb
|
69
78
|
- lib/rubocop/cop/performance/delete_prefix.rb
|
70
79
|
- lib/rubocop/cop/performance/delete_suffix.rb
|
@@ -75,12 +84,15 @@ files:
|
|
75
84
|
- lib/rubocop/cop/performance/flat_map.rb
|
76
85
|
- lib/rubocop/cop/performance/inefficient_hash_search.rb
|
77
86
|
- lib/rubocop/cop/performance/io_readlines.rb
|
87
|
+
- lib/rubocop/cop/performance/method_object_as_block.rb
|
78
88
|
- lib/rubocop/cop/performance/open_struct.rb
|
79
89
|
- lib/rubocop/cop/performance/range_include.rb
|
80
90
|
- lib/rubocop/cop/performance/redundant_block_call.rb
|
91
|
+
- lib/rubocop/cop/performance/redundant_equality_comparison_block.rb
|
81
92
|
- lib/rubocop/cop/performance/redundant_match.rb
|
82
93
|
- lib/rubocop/cop/performance/redundant_merge.rb
|
83
94
|
- lib/rubocop/cop/performance/redundant_sort_block.rb
|
95
|
+
- lib/rubocop/cop/performance/redundant_split_regexp_argument.rb
|
84
96
|
- lib/rubocop/cop/performance/redundant_string_chars.rb
|
85
97
|
- lib/rubocop/cop/performance/regexp_match.rb
|
86
98
|
- lib/rubocop/cop/performance/reverse_each.rb
|
@@ -99,16 +111,16 @@ files:
|
|
99
111
|
- lib/rubocop/performance.rb
|
100
112
|
- lib/rubocop/performance/inject.rb
|
101
113
|
- lib/rubocop/performance/version.rb
|
102
|
-
homepage: https://github.com/rubocop
|
114
|
+
homepage: https://github.com/rubocop/rubocop-performance
|
103
115
|
licenses:
|
104
116
|
- MIT
|
105
117
|
metadata:
|
106
118
|
homepage_uri: https://docs.rubocop.org/rubocop-performance/
|
107
|
-
changelog_uri: https://github.com/rubocop
|
108
|
-
source_code_uri: https://github.com/rubocop
|
109
|
-
documentation_uri: https://docs.rubocop.org/rubocop-performance/
|
110
|
-
bug_tracker_uri: https://github.com/rubocop
|
111
|
-
post_install_message:
|
119
|
+
changelog_uri: https://github.com/rubocop/rubocop-performance/blob/master/CHANGELOG.md
|
120
|
+
source_code_uri: https://github.com/rubocop/rubocop-performance/
|
121
|
+
documentation_uri: https://docs.rubocop.org/rubocop-performance/1.10/
|
122
|
+
bug_tracker_uri: https://github.com/rubocop/rubocop-performance/issues
|
123
|
+
post_install_message:
|
112
124
|
rdoc_options: []
|
113
125
|
require_paths:
|
114
126
|
- lib
|
@@ -123,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
135
|
- !ruby/object:Gem::Version
|
124
136
|
version: '0'
|
125
137
|
requirements: []
|
126
|
-
rubygems_version: 3.
|
127
|
-
signing_key:
|
138
|
+
rubygems_version: 3.2.9
|
139
|
+
signing_key:
|
128
140
|
specification_version: 4
|
129
141
|
summary: Automatic performance checking tool for Ruby code.
|
130
142
|
test_files: []
|