rubocop-performance 0.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.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.md +1 -0
  4. data/lib/rubocop-performance.rb +5 -0
  5. data/lib/rubocop/cop/performance/caller.rb +69 -0
  6. data/lib/rubocop/cop/performance/case_when_splat.rb +173 -0
  7. data/lib/rubocop/cop/performance/casecmp.rb +117 -0
  8. data/lib/rubocop/cop/performance/compare_with_block.rb +119 -0
  9. data/lib/rubocop/cop/performance/count.rb +102 -0
  10. data/lib/rubocop/cop/performance/detect.rb +110 -0
  11. data/lib/rubocop/cop/performance/double_start_end_with.rb +94 -0
  12. data/lib/rubocop/cop/performance/end_with.rb +56 -0
  13. data/lib/rubocop/cop/performance/fixed_size.rb +97 -0
  14. data/lib/rubocop/cop/performance/flat_map.rb +78 -0
  15. data/lib/rubocop/cop/performance/inefficient_hash_search.rb +99 -0
  16. data/lib/rubocop/cop/performance/lstrip_rstrip.rb +46 -0
  17. data/lib/rubocop/cop/performance/range_include.rb +47 -0
  18. data/lib/rubocop/cop/performance/redundant_block_call.rb +93 -0
  19. data/lib/rubocop/cop/performance/redundant_match.rb +56 -0
  20. data/lib/rubocop/cop/performance/redundant_merge.rb +169 -0
  21. data/lib/rubocop/cop/performance/redundant_sort_by.rb +50 -0
  22. data/lib/rubocop/cop/performance/regexp_match.rb +264 -0
  23. data/lib/rubocop/cop/performance/reverse_each.rb +42 -0
  24. data/lib/rubocop/cop/performance/sample.rb +142 -0
  25. data/lib/rubocop/cop/performance/size.rb +71 -0
  26. data/lib/rubocop/cop/performance/start_with.rb +59 -0
  27. data/lib/rubocop/cop/performance/string_replacement.rb +172 -0
  28. data/lib/rubocop/cop/performance/times_map.rb +71 -0
  29. data/lib/rubocop/cop/performance/unfreeze_string.rb +50 -0
  30. data/lib/rubocop/cop/performance/unneeded_sort.rb +165 -0
  31. data/lib/rubocop/cop/performance/uri_default_parser.rb +47 -0
  32. data/lib/rubocop/cop/performance_cops.rb +37 -0
  33. data/lib/rubocop/performance/version.rb +9 -0
  34. metadata +114 -0
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Performance
6
+ # This cop identifies places where `URI::Parser.new`
7
+ # can be replaced by `URI::DEFAULT_PARSER`.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # URI::Parser.new
12
+ #
13
+ # # good
14
+ # URI::DEFAULT_PARSER
15
+ #
16
+ class UriDefaultParser < Cop
17
+ MSG = 'Use `%<double_colon>sURI::DEFAULT_PARSER` instead of ' \
18
+ '`%<double_colon>sURI::Parser.new`.'.freeze
19
+
20
+ def_node_matcher :uri_parser_new?, <<-PATTERN
21
+ (send
22
+ (const
23
+ (const ${nil? cbase} :URI) :Parser) :new)
24
+ PATTERN
25
+
26
+ def on_send(node)
27
+ return unless uri_parser_new?(node) do |captured_value|
28
+ double_colon = captured_value ? '::' : ''
29
+ message = format(MSG, double_colon: double_colon)
30
+
31
+ add_offense(node, message: message)
32
+ end
33
+ end
34
+
35
+ def autocorrect(node)
36
+ lambda do |corrector|
37
+ double_colon = uri_parser_new?(node) ? '::' : ''
38
+
39
+ corrector.replace(
40
+ node.loc.expression, "#{double_colon}URI::DEFAULT_PARSER"
41
+ )
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ 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
+ remove_const('Performance') if const_defined?('Performance')
8
+ end
9
+ end
10
+
11
+ require_relative 'performance/caller'
12
+ require_relative 'performance/case_when_splat'
13
+ require_relative 'performance/casecmp'
14
+ require_relative 'performance/compare_with_block'
15
+ require_relative 'performance/count'
16
+ require_relative 'performance/detect'
17
+ require_relative 'performance/double_start_end_with'
18
+ require_relative 'performance/end_with'
19
+ require_relative 'performance/fixed_size'
20
+ require_relative 'performance/flat_map'
21
+ require_relative 'performance/inefficient_hash_search'
22
+ require_relative 'performance/lstrip_rstrip'
23
+ require_relative 'performance/range_include'
24
+ require_relative 'performance/redundant_block_call'
25
+ require_relative 'performance/redundant_match'
26
+ require_relative 'performance/redundant_merge'
27
+ require_relative 'performance/redundant_sort_by'
28
+ require_relative 'performance/regexp_match'
29
+ require_relative 'performance/reverse_each'
30
+ require_relative 'performance/sample'
31
+ require_relative 'performance/size'
32
+ require_relative 'performance/start_with'
33
+ require_relative 'performance/string_replacement'
34
+ require_relative 'performance/times_map'
35
+ require_relative 'performance/unfreeze_string'
36
+ require_relative 'performance/unneeded_sort'
37
+ require_relative 'performance/uri_default_parser'
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Performance
5
+ module Version
6
+ STRING = '0.0.0'
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-performance
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Bozhidar Batsov
8
+ - Jonas Arvidsson
9
+ - Yuji Nakayama
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2018-07-10 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rubocop
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '0.57'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '0.57'
29
+ - !ruby/object:Gem::Dependency
30
+ name: simplecov
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ description: |2
44
+ A collection of RuboCop cops to check for performance optimizations
45
+ in Ruby code.
46
+ email: rubocop@googlegroups.com
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files:
50
+ - LICENSE.txt
51
+ - README.md
52
+ files:
53
+ - LICENSE.txt
54
+ - README.md
55
+ - lib/rubocop-performance.rb
56
+ - lib/rubocop/cop/performance/caller.rb
57
+ - lib/rubocop/cop/performance/case_when_splat.rb
58
+ - lib/rubocop/cop/performance/casecmp.rb
59
+ - lib/rubocop/cop/performance/compare_with_block.rb
60
+ - lib/rubocop/cop/performance/count.rb
61
+ - lib/rubocop/cop/performance/detect.rb
62
+ - lib/rubocop/cop/performance/double_start_end_with.rb
63
+ - lib/rubocop/cop/performance/end_with.rb
64
+ - lib/rubocop/cop/performance/fixed_size.rb
65
+ - lib/rubocop/cop/performance/flat_map.rb
66
+ - lib/rubocop/cop/performance/inefficient_hash_search.rb
67
+ - lib/rubocop/cop/performance/lstrip_rstrip.rb
68
+ - lib/rubocop/cop/performance/range_include.rb
69
+ - lib/rubocop/cop/performance/redundant_block_call.rb
70
+ - lib/rubocop/cop/performance/redundant_match.rb
71
+ - lib/rubocop/cop/performance/redundant_merge.rb
72
+ - lib/rubocop/cop/performance/redundant_sort_by.rb
73
+ - lib/rubocop/cop/performance/regexp_match.rb
74
+ - lib/rubocop/cop/performance/reverse_each.rb
75
+ - lib/rubocop/cop/performance/sample.rb
76
+ - lib/rubocop/cop/performance/size.rb
77
+ - lib/rubocop/cop/performance/start_with.rb
78
+ - lib/rubocop/cop/performance/string_replacement.rb
79
+ - lib/rubocop/cop/performance/times_map.rb
80
+ - lib/rubocop/cop/performance/unfreeze_string.rb
81
+ - lib/rubocop/cop/performance/unneeded_sort.rb
82
+ - lib/rubocop/cop/performance/uri_default_parser.rb
83
+ - lib/rubocop/cop/performance_cops.rb
84
+ - lib/rubocop/performance/version.rb
85
+ homepage: https://github.com/rubocop-hq/rubocop-performance
86
+ licenses:
87
+ - MIT
88
+ metadata:
89
+ homepage_uri: https://rubocop-performance.readthedocs.io/
90
+ changelog_uri: https://github.com/rubocop-hq/rubocop-performance/blob/master/CHANGELOG.md
91
+ source_code_uri: https://github.com/rubocop-hq/rubocop-performance/
92
+ documentation_uri: https://rubocop-performance.readthedocs.io/
93
+ bug_tracker_uri: https://github.com/rubocop-hq/rubocop-performance/issues
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 2.3.0
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.7.7
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Automatic performance checking tool for Ruby code.
114
+ test_files: []