rubocop-performance 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +73 -1
- data/config/default.yml +210 -0
- data/lib/rubocop-performance.rb +6 -0
- data/lib/rubocop/cop/performance/chain_array_allocation.rb +3 -2
- data/lib/rubocop/cop/performance/open_struct.rb +46 -0
- data/lib/rubocop/cop/performance/range_include.rb +3 -0
- data/lib/rubocop/cop/performance/redundant_merge.rb +18 -4
- data/lib/rubocop/cop/performance_cops.rb +3 -2
- data/lib/rubocop/performance.rb +12 -0
- data/lib/rubocop/performance/inject.rb +18 -0
- data/lib/rubocop/performance/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab226ddbd8840eb8a3c4281e137a727b4514d9ee99c0f321de8e5d16621622cd
|
4
|
+
data.tar.gz: 04e64315a9ecbbb6cbef28c1dfecb953069b3282f0749caede003c00c93b981c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59f5c83e64695cb149d5babfa5e8be759fa11f23f4395810e928b627c236f0d7206f20527a1b2a96953e585f39a89c25f18ac68a44a3dd56ae2daffbc2513990
|
7
|
+
data.tar.gz: '0189ac9e3a329fec641134b595776cb04ba34fe13f1a3f72fc506bc95cb2021402a113090edc3be86bccd251f23768afe6cf81c6f64cfb9855ba3b32b30a0a9e'
|
data/README.md
CHANGED
@@ -1 +1,73 @@
|
|
1
|
-
#
|
1
|
+
# RuboCop Performance
|
2
|
+
|
3
|
+
[](https://circleci.com/gh/rubocop-hq/rubocop-performance)
|
4
|
+
|
5
|
+
Performance optimization analysis for your projects, as an extension to [RuboCop](https://github.com/rubocop-hq/rubocop).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Just install the `rubocop-performance` gem
|
10
|
+
|
11
|
+
```sh
|
12
|
+
gem install rubocop-performance
|
13
|
+
```
|
14
|
+
|
15
|
+
or if you use bundler put this in your `Gemfile`
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'rubocop-performance'
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
You need to tell RuboCop to load the Performance extension. There are three
|
24
|
+
ways to do this:
|
25
|
+
|
26
|
+
### RuboCop configuration file
|
27
|
+
|
28
|
+
Put this into your `.rubocop.yml`.
|
29
|
+
|
30
|
+
```yaml
|
31
|
+
require: rubocop-performance
|
32
|
+
```
|
33
|
+
|
34
|
+
Now you can run `rubocop` and it will automatically load the RuboCop Performance
|
35
|
+
cops together with the standard cops.
|
36
|
+
|
37
|
+
### Command line
|
38
|
+
|
39
|
+
```sh
|
40
|
+
rubocop --require rubocop-performance
|
41
|
+
```
|
42
|
+
|
43
|
+
### Rake task
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
RuboCop::RakeTask.new do |task|
|
47
|
+
task.requires << 'rubocop-performance'
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
## The Cops
|
52
|
+
|
53
|
+
All cops are located under
|
54
|
+
[`lib/rubocop/cop/performance`](lib/rubocop/cop/performance), and contain
|
55
|
+
examples/documentation.
|
56
|
+
|
57
|
+
In your `.rubocop.yml`, you may treat the Performance cops just like any other
|
58
|
+
cop. For example:
|
59
|
+
|
60
|
+
```yaml
|
61
|
+
Performance/Size:
|
62
|
+
Exclude:
|
63
|
+
- lib/example.rb
|
64
|
+
```
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
Checkout the [contribution guidelines](CONTRIBUTING.md).
|
69
|
+
|
70
|
+
## License
|
71
|
+
|
72
|
+
`rubocop-performance` is MIT licensed. [See the accompanying file](LICENSE.txt) for
|
73
|
+
the full text.
|
data/config/default.yml
CHANGED
@@ -1,11 +1,27 @@
|
|
1
1
|
# This is the default configuration file.
|
2
2
|
|
3
|
+
Performance/Caller:
|
4
|
+
Description: >-
|
5
|
+
Use `caller(n..n)` instead of `caller`.
|
6
|
+
Enabled: true
|
7
|
+
VersionAdded: '0.49'
|
8
|
+
|
3
9
|
Performance/CaseWhenSplat:
|
4
10
|
Description: >-
|
5
11
|
Reordering `when` conditions with a splat to the end
|
6
12
|
of the `when` branches can improve performance.
|
7
13
|
Enabled: false
|
8
14
|
AutoCorrect: false
|
15
|
+
SafeAutoCorrect: false
|
16
|
+
VersionAdded: '0.34'
|
17
|
+
VersionChanged: '0.59'
|
18
|
+
|
19
|
+
Performance/Casecmp:
|
20
|
+
Description: >-
|
21
|
+
Use `casecmp` rather than `downcase ==`, `upcase ==`, `== downcase`, or `== upcase`..
|
22
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringcasecmp-vs-stringdowncase---code'
|
23
|
+
Enabled: true
|
24
|
+
VersionAdded: '0.36'
|
9
25
|
|
10
26
|
Performance/ChainArrayAllocation:
|
11
27
|
Description: >-
|
@@ -13,12 +29,206 @@ Performance/ChainArrayAllocation:
|
|
13
29
|
existing array.
|
14
30
|
Reference: 'https://twitter.com/schneems/status/1034123879978029057'
|
15
31
|
Enabled: false
|
32
|
+
VersionAdded: '0.59'
|
33
|
+
|
34
|
+
Performance/CompareWithBlock:
|
35
|
+
Description: 'Use `sort_by(&:foo)` instead of `sort { |a, b| a.foo <=> b.foo }`.'
|
36
|
+
Enabled: true
|
37
|
+
VersionAdded: '0.46'
|
38
|
+
|
39
|
+
Performance/Count:
|
40
|
+
Description: >-
|
41
|
+
Use `count` instead of `select...size`, `reject...size`,
|
42
|
+
`select...count`, `reject...count`, `select...length`,
|
43
|
+
and `reject...length`.
|
44
|
+
# This cop has known compatibility issues with `ActiveRecord` and other
|
45
|
+
# frameworks. ActiveRecord's `count` ignores the block that is passed to it.
|
46
|
+
# For more information, see the documentation in the cop itself.
|
47
|
+
# If you understand the known risk, you can disable `SafeMode`.
|
48
|
+
SafeMode: true
|
49
|
+
Enabled: true
|
50
|
+
VersionAdded: '0.31'
|
51
|
+
VersionChanged: '0.39'
|
52
|
+
|
53
|
+
Performance/Detect:
|
54
|
+
Description: >-
|
55
|
+
Use `detect` instead of `select.first`, `find_all.first`,
|
56
|
+
`select.last`, and `find_all.last`.
|
57
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerabledetect-vs-enumerableselectfirst-code'
|
58
|
+
# This cop has known compatibility issues with `ActiveRecord` and other
|
59
|
+
# frameworks. `ActiveRecord` does not implement a `detect` method and `find`
|
60
|
+
# has its own meaning. Correcting `ActiveRecord` methods with this cop
|
61
|
+
# should be considered unsafe.
|
62
|
+
SafeMode: true
|
63
|
+
Enabled: true
|
64
|
+
VersionAdded: '0.30'
|
65
|
+
VersionChanged: '0.39'
|
16
66
|
|
17
67
|
Performance/DoubleStartEndWith:
|
68
|
+
Description: >-
|
69
|
+
Use `str.{start,end}_with?(x, ..., y, ...)`
|
70
|
+
instead of `str.{start,end}_with?(x, ...) || str.{start,end}_with?(y, ...)`.
|
71
|
+
Enabled: true
|
72
|
+
VersionAdded: '0.36'
|
73
|
+
VersionChanged: '0.48'
|
18
74
|
# Used to check for `starts_with?` and `ends_with?`.
|
19
75
|
# These methods are defined by `ActiveSupport`.
|
20
76
|
IncludeActiveSupportAliases: false
|
21
77
|
|
78
|
+
Performance/EndWith:
|
79
|
+
Description: 'Use `end_with?` instead of a regex match anchored to the end of a string.'
|
80
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringmatch-vs-stringstart_withstringend_with-code-start-code-end'
|
81
|
+
# This will change to a new method call which isn't guaranteed to be on the
|
82
|
+
# object. Switching these methods has to be done with knowledge of the types
|
83
|
+
# of the variables which rubocop doesn't have.
|
84
|
+
SafeAutoCorrect: false
|
85
|
+
AutoCorrect: false
|
86
|
+
Enabled: true
|
87
|
+
VersionAdded: '0.36'
|
88
|
+
VersionChanged: '0.44'
|
89
|
+
|
90
|
+
Performance/FixedSize:
|
91
|
+
Description: 'Do not compute the size of statically sized objects except in constants'
|
92
|
+
Enabled: true
|
93
|
+
VersionAdded: '0.35'
|
94
|
+
|
95
|
+
Performance/FlatMap:
|
96
|
+
Description: >-
|
97
|
+
Use `Enumerable#flat_map`
|
98
|
+
instead of `Enumerable#map...Array#flatten(1)`
|
99
|
+
or `Enumberable#collect..Array#flatten(1)`
|
100
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablemaparrayflatten-vs-enumerableflat_map-code'
|
101
|
+
Enabled: true
|
102
|
+
VersionAdded: '0.30'
|
103
|
+
EnabledForFlattenWithoutParams: false
|
104
|
+
# If enabled, this cop will warn about usages of
|
105
|
+
# `flatten` being called without any parameters.
|
106
|
+
# This can be dangerous since `flat_map` will only flatten 1 level, and
|
107
|
+
# `flatten` without any parameters can flatten multiple levels.
|
108
|
+
|
109
|
+
Performance/InefficientHashSearch:
|
110
|
+
Description: 'Use `key?` or `value?` instead of `keys.include?` or `values.include?`'
|
111
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#hashkey-instead-of-hashkeysinclude-code'
|
112
|
+
Enabled: true
|
113
|
+
VersionAdded: '0.56'
|
114
|
+
Safe: false
|
115
|
+
|
116
|
+
Performance/LstripRstrip:
|
117
|
+
Description: 'Use `strip` instead of `lstrip.rstrip`.'
|
118
|
+
Enabled: true
|
119
|
+
VersionAdded: '0.36'
|
120
|
+
|
121
|
+
Performance/OpenStruct:
|
122
|
+
Description: 'Use `Struct` instead of `OpenStruct`.'
|
123
|
+
Enabled: false
|
124
|
+
VersionAdded: '0.61'
|
125
|
+
Safe: false
|
126
|
+
|
127
|
+
Performance/RangeInclude:
|
128
|
+
Description: 'Use `Range#cover?` instead of `Range#include?`.'
|
129
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#cover-vs-include-code'
|
130
|
+
Enabled: true
|
131
|
+
VersionAdded: '0.36'
|
132
|
+
Safe: false
|
133
|
+
|
134
|
+
Performance/RedundantBlockCall:
|
135
|
+
Description: 'Use `yield` instead of `block.call`.'
|
136
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#proccall-and-block-arguments-vs-yieldcode'
|
137
|
+
Enabled: true
|
138
|
+
VersionAdded: '0.36'
|
139
|
+
|
140
|
+
Performance/RedundantMatch:
|
141
|
+
Description: >-
|
142
|
+
Use `=~` instead of `String#match` or `Regexp#match` in a context where the
|
143
|
+
returned `MatchData` is not needed.
|
144
|
+
Enabled: true
|
145
|
+
VersionAdded: '0.36'
|
146
|
+
|
22
147
|
Performance/RedundantMerge:
|
148
|
+
Description: 'Use Hash#[]=, rather than Hash#merge! with a single key-value pair.'
|
149
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#hashmerge-vs-hash-code'
|
150
|
+
Enabled: true
|
151
|
+
VersionAdded: '0.36'
|
23
152
|
# Max number of key-value pairs to consider an offense
|
24
153
|
MaxKeyValuePairs: 2
|
154
|
+
|
155
|
+
Performance/RedundantSortBy:
|
156
|
+
Description: 'Use `sort` instead of `sort_by { |x| x }`.'
|
157
|
+
Enabled: true
|
158
|
+
VersionAdded: '0.36'
|
159
|
+
|
160
|
+
Performance/RegexpMatch:
|
161
|
+
Description: >-
|
162
|
+
Use `match?` instead of `Regexp#match`, `String#match`, `Symbol#match`,
|
163
|
+
`Regexp#===`, or `=~` when `MatchData` is not used.
|
164
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#regexp-vs-stringmatch-vs-string-vs-stringmatch-code-'
|
165
|
+
Enabled: true
|
166
|
+
VersionAdded: '0.47'
|
167
|
+
|
168
|
+
Performance/ReverseEach:
|
169
|
+
Description: 'Use `reverse_each` instead of `reverse.each`.'
|
170
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablereverseeach-vs-enumerablereverse_each-code'
|
171
|
+
Enabled: true
|
172
|
+
VersionAdded: '0.30'
|
173
|
+
|
174
|
+
Performance/Sample:
|
175
|
+
Description: >-
|
176
|
+
Use `sample` instead of `shuffle.first`,
|
177
|
+
`shuffle.last`, and `shuffle[Integer]`.
|
178
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#arrayshufflefirst-vs-arraysample-code'
|
179
|
+
Enabled: true
|
180
|
+
VersionAdded: '0.30'
|
181
|
+
|
182
|
+
Performance/Size:
|
183
|
+
Description: >-
|
184
|
+
Use `size` instead of `count` for counting
|
185
|
+
the number of elements in `Array` and `Hash`.
|
186
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#arraylength-vs-arraysize-vs-arraycount-code'
|
187
|
+
Enabled: true
|
188
|
+
VersionAdded: '0.30'
|
189
|
+
|
190
|
+
Performance/StartWith:
|
191
|
+
Description: 'Use `start_with?` instead of a regex match anchored to the beginning of a string.'
|
192
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringmatch-vs-stringstart_withstringend_with-code-start-code-end'
|
193
|
+
# This will change to a new method call which isn't guaranteed to be on the
|
194
|
+
# object. Switching these methods has to be done with knowledge of the types
|
195
|
+
# of the variables which rubocop doesn't have.
|
196
|
+
SafeAutoCorrect: false
|
197
|
+
AutoCorrect: false
|
198
|
+
Enabled: true
|
199
|
+
VersionAdded: '0.36'
|
200
|
+
VersionChanged: '0.44'
|
201
|
+
|
202
|
+
Performance/StringReplacement:
|
203
|
+
Description: >-
|
204
|
+
Use `tr` instead of `gsub` when you are replacing the same
|
205
|
+
number of characters. Use `delete` instead of `gsub` when
|
206
|
+
you are deleting characters.
|
207
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringgsub-vs-stringtr-code'
|
208
|
+
Enabled: true
|
209
|
+
VersionAdded: '0.33'
|
210
|
+
|
211
|
+
Performance/TimesMap:
|
212
|
+
Description: 'Checks for .times.map calls.'
|
213
|
+
AutoCorrect: false
|
214
|
+
Enabled: true
|
215
|
+
VersionAdded: '0.36'
|
216
|
+
VersionChanged: '0.50'
|
217
|
+
SafeAutoCorrect: false # see https://github.com/rubocop-hq/rubocop/issues/4658
|
218
|
+
|
219
|
+
Performance/UnfreezeString:
|
220
|
+
Description: 'Use unary plus to get an unfrozen string literal.'
|
221
|
+
Enabled: true
|
222
|
+
VersionAdded: '0.50'
|
223
|
+
|
224
|
+
Performance/UnneededSort:
|
225
|
+
Description: >-
|
226
|
+
Use `min` instead of `sort.first`,
|
227
|
+
`max_by` instead of `sort_by...last`, etc.
|
228
|
+
Enabled: true
|
229
|
+
VersionAdded: '0.55'
|
230
|
+
|
231
|
+
Performance/UriDefaultParser:
|
232
|
+
Description: 'Use `URI::DEFAULT_PARSER` instead of `URI::Parser.new`.'
|
233
|
+
Enabled: true
|
234
|
+
VersionAdded: '0.50'
|
data/lib/rubocop-performance.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rubocop'
|
4
|
+
|
5
|
+
require_relative 'rubocop/performance'
|
4
6
|
require_relative 'rubocop/performance/version'
|
7
|
+
require_relative 'rubocop/performance/inject'
|
8
|
+
|
9
|
+
RuboCop::Performance::Inject.defaults!
|
10
|
+
|
5
11
|
require_relative 'rubocop/cop/performance_cops'
|
@@ -47,8 +47,9 @@ module RuboCop
|
|
47
47
|
HAS_MUTATION_ALTERNATIVE = ':collect :compact :flatten :map :reject '\
|
48
48
|
':reverse :rotate :select :shuffle :sort '\
|
49
49
|
':uniq '.freeze
|
50
|
-
MSG = 'Use `%<method>s
|
51
|
-
'
|
50
|
+
MSG = 'Use unchained `%<method>s!` and `%<second_method>s!` '\
|
51
|
+
'(followed by `return array` if required) instead of chaining '\
|
52
|
+
'`%<method>s...%<second_method>s`.'.freeze
|
52
53
|
|
53
54
|
def_node_matcher :flat_map_candidate?, <<-PATTERN
|
54
55
|
{
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Performance
|
6
|
+
# This cop checks for `OpenStruct.new` calls.
|
7
|
+
# Instantiation of an `OpenStruct` invalidates
|
8
|
+
# Ruby global method cache as it causes dynamic method
|
9
|
+
# definition during program runtime.
|
10
|
+
# This could have an effect on performance,
|
11
|
+
# especially in case of single-threaded
|
12
|
+
# applications with multiple `OpenStruct` instantiations.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# # bad
|
16
|
+
# class MyClass
|
17
|
+
# def my_method
|
18
|
+
# OpenStruct.new(my_key1: 'my_value1', my_key2: 'my_value2')
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# # good
|
23
|
+
# class MyClass
|
24
|
+
# MyStruct = Struct.new(:my_key1, :my_key2)
|
25
|
+
# def my_method
|
26
|
+
# MyStruct.new('my_value1', 'my_value2')
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
class OpenStruct < Cop
|
31
|
+
MSG = 'Consider using `Struct` over `OpenStruct` ' \
|
32
|
+
'to optimize the performance.'.freeze
|
33
|
+
|
34
|
+
def_node_matcher :open_struct, <<-PATTERN
|
35
|
+
(send (const {nil? cbase} :OpenStruct) :new ...)
|
36
|
+
PATTERN
|
37
|
+
|
38
|
+
def on_send(node)
|
39
|
+
open_struct(node) do |method|
|
40
|
+
add_offense(node, location: :selector, message: format(MSG, method))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -9,6 +9,9 @@ module RuboCop
|
|
9
9
|
# end points of the `Range`. In a great majority of cases, this is what
|
10
10
|
# is wanted.
|
11
11
|
#
|
12
|
+
# This cop is `Safe: false` by default because `Range#include?` and
|
13
|
+
# `Range#cover?` are not equivalent behaviour.
|
14
|
+
#
|
12
15
|
# @example
|
13
16
|
# # bad
|
14
17
|
# ('a'..'z').include?('b') # => true
|
@@ -14,6 +14,12 @@ module RuboCop
|
|
14
14
|
AREF_ASGN = '%<receiver>s[%<key>s] = %<value>s'.freeze
|
15
15
|
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'.freeze
|
16
16
|
|
17
|
+
WITH_MODIFIER_CORRECTION = <<-RUBY.strip_indent
|
18
|
+
%<keyword>s %<condition>s
|
19
|
+
%<leading_space>s%<indent>s%<body>s
|
20
|
+
%<leading_space>send
|
21
|
+
RUBY
|
22
|
+
|
17
23
|
def_node_matcher :redundant_merge_candidate, <<-PATTERN
|
18
24
|
(send $!nil? :merge! [(hash $...) !kwsplat_type?])
|
19
25
|
PATTERN
|
@@ -60,6 +66,7 @@ module RuboCop
|
|
60
66
|
|
61
67
|
def non_redundant_merge?(node, receiver, pairs)
|
62
68
|
non_redundant_pairs?(receiver, pairs) ||
|
69
|
+
kwsplat_used?(pairs) ||
|
63
70
|
non_redundant_value_used?(receiver, node)
|
64
71
|
end
|
65
72
|
|
@@ -67,6 +74,10 @@ module RuboCop
|
|
67
74
|
pairs.size > 1 && !receiver.pure? || pairs.size > max_key_value_pairs
|
68
75
|
end
|
69
76
|
|
77
|
+
def kwsplat_used?(pairs)
|
78
|
+
pairs.any?(&:kwsplat_type?)
|
79
|
+
end
|
80
|
+
|
70
81
|
def non_redundant_value_used?(receiver, node)
|
71
82
|
node.value_used? &&
|
72
83
|
!EachWithObjectInspector.new(node, receiver).value_used?
|
@@ -101,12 +112,15 @@ module RuboCop
|
|
101
112
|
end
|
102
113
|
|
103
114
|
def rewrite_with_modifier(node, parent, new_source)
|
104
|
-
|
105
|
-
padding = "\n#{
|
115
|
+
indent = ' ' * indent_width
|
116
|
+
padding = "\n#{indent + leading_spaces(node)}"
|
106
117
|
new_source.gsub!(/\n/, padding)
|
107
118
|
|
108
|
-
parent.loc.keyword.source
|
109
|
-
|
119
|
+
format(WITH_MODIFIER_CORRECTION, keyword: parent.loc.keyword.source,
|
120
|
+
condition: parent.condition.source,
|
121
|
+
leading_space: leading_spaces(node),
|
122
|
+
indent: indent,
|
123
|
+
body: new_source).chomp
|
110
124
|
end
|
111
125
|
|
112
126
|
def leading_spaces(node)
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RuboCop
|
4
|
+
# RuboCop included the performance cops directly before version 1.0.0.
|
5
|
+
# We can remove them to avoid warnings about redefining constants.
|
4
6
|
module Cop
|
5
|
-
# RuboCop included the performance cops directly before version 1.0.0.
|
6
|
-
# We can remove them to avoid warnings about redefining constants.
|
7
7
|
remove_const('Performance') if const_defined?('Performance')
|
8
8
|
end
|
9
9
|
end
|
@@ -20,6 +20,7 @@ require_relative 'performance/fixed_size'
|
|
20
20
|
require_relative 'performance/flat_map'
|
21
21
|
require_relative 'performance/inefficient_hash_search'
|
22
22
|
require_relative 'performance/lstrip_rstrip'
|
23
|
+
require_relative 'performance/open_struct'
|
23
24
|
require_relative 'performance/range_include'
|
24
25
|
require_relative 'performance/redundant_block_call'
|
25
26
|
require_relative 'performance/redundant_match'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
# RuboCop Performance project namespace
|
5
|
+
module Performance
|
6
|
+
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
|
7
|
+
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
|
8
|
+
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
9
|
+
|
10
|
+
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Performance
|
5
|
+
# Because RuboCop doesn't yet support plugins, we have to monkey patch in a
|
6
|
+
# bit of our configuration.
|
7
|
+
module Inject
|
8
|
+
def self.defaults!
|
9
|
+
path = CONFIG_DEFAULT.to_s
|
10
|
+
hash = ConfigLoader.send(:load_yaml_configuration, path)
|
11
|
+
config = Config.new(hash, path)
|
12
|
+
puts "configuration from #{path}" if ConfigLoader.debug?
|
13
|
+
config = ConfigLoader.merge_with_default(config, path)
|
14
|
+
ConfigLoader.instance_variable_set(:@default_configuration, config)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
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: 0.0
|
4
|
+
version: 1.0.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:
|
13
|
+
date: 2019-03-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/rubocop/cop/performance/flat_map.rb
|
68
68
|
- lib/rubocop/cop/performance/inefficient_hash_search.rb
|
69
69
|
- lib/rubocop/cop/performance/lstrip_rstrip.rb
|
70
|
+
- lib/rubocop/cop/performance/open_struct.rb
|
70
71
|
- lib/rubocop/cop/performance/range_include.rb
|
71
72
|
- lib/rubocop/cop/performance/redundant_block_call.rb
|
72
73
|
- lib/rubocop/cop/performance/redundant_match.rb
|
@@ -83,6 +84,8 @@ files:
|
|
83
84
|
- lib/rubocop/cop/performance/unneeded_sort.rb
|
84
85
|
- lib/rubocop/cop/performance/uri_default_parser.rb
|
85
86
|
- lib/rubocop/cop/performance_cops.rb
|
87
|
+
- lib/rubocop/performance.rb
|
88
|
+
- lib/rubocop/performance/inject.rb
|
86
89
|
- lib/rubocop/performance/version.rb
|
87
90
|
homepage: https://github.com/rubocop-hq/rubocop-performance
|
88
91
|
licenses:
|
@@ -108,8 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
111
|
- !ruby/object:Gem::Version
|
109
112
|
version: '0'
|
110
113
|
requirements: []
|
111
|
-
|
112
|
-
rubygems_version: 2.7.6
|
114
|
+
rubygems_version: 3.0.3
|
113
115
|
signing_key:
|
114
116
|
specification_version: 4
|
115
117
|
summary: Automatic performance checking tool for Ruby code.
|