sevencop 0.35.1 → 0.36.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -0
- data/Gemfile.lock +41 -25
- data/README.md +1 -0
- data/config/default.yml +6 -0
- data/lib/rubocop/cop/sevencop/map_method_chain.rb +74 -0
- data/lib/rubocop/cop/sevencop/rails_belongs_to_optional.rb +1 -1
- data/lib/rubocop/cop/sevencop/rails_order_field_arel_sql.rb +2 -2
- data/lib/sevencop/version.rb +1 -1
- data/lib/sevencop.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41302972abfb2a785a3a9fcffb8b9b229d34d8182125f75cc34062720ef7262c
|
4
|
+
data.tar.gz: ac07370e67a54572895b3d49c5992da0521aa474de7e9e47d3b998a740b9f087
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05fccfbdc29de4b5f0dda00caa7a30528068e98e665ba6ace777d1531c968dedce672c429226b4c0c5c167d986b0fcfb9ead8d7244ea359abd27b1edc8d15b3b
|
7
|
+
data.tar.gz: 07a7d923cc6f06c0b9df3ede1de081b23ea116d1bba328faf9529fe6b2174d691ab1c99ea3f6eaa175d8e762e7b61b2c1dc34457cbe5d6ace012b58a0be83066
|
data/.rubocop.yml
CHANGED
@@ -43,6 +43,13 @@ RSpec/FilePath:
|
|
43
43
|
RSpec/MultipleExpectations:
|
44
44
|
Enabled: false
|
45
45
|
|
46
|
+
RSpec/SpecFilePathFormat:
|
47
|
+
CustomTransform:
|
48
|
+
RSpecDescribeHttpEndpoint: rspec_describe_http_endpoint
|
49
|
+
RSpecEmptyLineAfterLet: rspec_empty_line_after_let
|
50
|
+
RSpecExamplesInSameGroup: rspec_examples_in_same_group
|
51
|
+
RSpecMemoizedHelperBlockDelimiter: rspec_memoized_helper_block_delimiter
|
52
|
+
|
46
53
|
Sevencop/AutoloadOrdered:
|
47
54
|
Enabled: true
|
48
55
|
|
data/Gemfile.lock
CHANGED
@@ -1,32 +1,46 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sevencop (0.
|
4
|
+
sevencop (0.36.0)
|
5
5
|
activesupport
|
6
6
|
rubocop
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (7.
|
11
|
+
activesupport (7.1.3)
|
12
|
+
base64
|
13
|
+
bigdecimal
|
12
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
|
+
connection_pool (>= 2.2.5)
|
16
|
+
drb
|
13
17
|
i18n (>= 1.6, < 2)
|
14
18
|
minitest (>= 5.1)
|
19
|
+
mutex_m
|
15
20
|
tzinfo (~> 2.0)
|
16
21
|
ast (2.4.2)
|
17
|
-
|
22
|
+
base64 (0.2.0)
|
23
|
+
bigdecimal (3.1.6)
|
24
|
+
concurrent-ruby (1.2.3)
|
25
|
+
connection_pool (2.4.1)
|
18
26
|
diff-lcs (1.5.0)
|
27
|
+
drb (2.2.0)
|
28
|
+
ruby2_keywords
|
19
29
|
i18n (1.14.1)
|
20
30
|
concurrent-ruby (~> 1.0)
|
21
|
-
json (2.
|
22
|
-
|
23
|
-
|
24
|
-
|
31
|
+
json (2.7.1)
|
32
|
+
language_server-protocol (3.17.0.3)
|
33
|
+
minitest (5.21.2)
|
34
|
+
mutex_m (0.2.0)
|
35
|
+
parallel (1.24.0)
|
36
|
+
parser (3.3.0.5)
|
25
37
|
ast (~> 2.4.1)
|
38
|
+
racc
|
39
|
+
racc (1.7.3)
|
26
40
|
rainbow (3.1.1)
|
27
|
-
rake (13.0
|
28
|
-
regexp_parser (2.
|
29
|
-
rexml (3.2.
|
41
|
+
rake (13.1.0)
|
42
|
+
regexp_parser (2.9.0)
|
43
|
+
rexml (3.2.6)
|
30
44
|
rspec (3.12.0)
|
31
45
|
rspec-core (~> 3.12.0)
|
32
46
|
rspec-expectations (~> 3.12.0)
|
@@ -36,39 +50,41 @@ GEM
|
|
36
50
|
rspec-expectations (3.12.3)
|
37
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
38
52
|
rspec-support (~> 3.12.0)
|
39
|
-
rspec-mocks (3.12.
|
53
|
+
rspec-mocks (3.12.6)
|
40
54
|
diff-lcs (>= 1.2.0, < 2.0)
|
41
55
|
rspec-support (~> 3.12.0)
|
42
|
-
rspec-support (3.12.
|
43
|
-
rubocop (1.
|
56
|
+
rspec-support (3.12.1)
|
57
|
+
rubocop (1.60.2)
|
44
58
|
json (~> 2.3)
|
59
|
+
language_server-protocol (>= 3.17.0)
|
45
60
|
parallel (~> 1.10)
|
46
|
-
parser (>= 3.
|
61
|
+
parser (>= 3.3.0.2)
|
47
62
|
rainbow (>= 2.2.2, < 4.0)
|
48
63
|
regexp_parser (>= 1.8, < 3.0)
|
49
64
|
rexml (>= 3.2.5, < 4.0)
|
50
|
-
rubocop-ast (>= 1.
|
65
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
51
66
|
ruby-progressbar (~> 1.7)
|
52
67
|
unicode-display_width (>= 2.4.0, < 3.0)
|
53
|
-
rubocop-ast (1.
|
68
|
+
rubocop-ast (1.30.0)
|
54
69
|
parser (>= 3.2.1.0)
|
55
|
-
rubocop-capybara (2.
|
70
|
+
rubocop-capybara (2.20.0)
|
56
71
|
rubocop (~> 1.41)
|
57
|
-
rubocop-factory_bot (2.
|
58
|
-
rubocop (~> 1.
|
59
|
-
rubocop-performance (1.
|
60
|
-
rubocop (>= 1.
|
61
|
-
rubocop-ast (>=
|
72
|
+
rubocop-factory_bot (2.25.1)
|
73
|
+
rubocop (~> 1.41)
|
74
|
+
rubocop-performance (1.20.2)
|
75
|
+
rubocop (>= 1.48.1, < 2.0)
|
76
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
62
77
|
rubocop-rake (0.6.0)
|
63
78
|
rubocop (~> 1.0)
|
64
|
-
rubocop-rspec (2.
|
65
|
-
rubocop (~> 1.
|
79
|
+
rubocop-rspec (2.26.1)
|
80
|
+
rubocop (~> 1.40)
|
66
81
|
rubocop-capybara (~> 2.17)
|
67
82
|
rubocop-factory_bot (~> 2.22)
|
68
83
|
ruby-progressbar (1.13.0)
|
84
|
+
ruby2_keywords (0.0.5)
|
69
85
|
tzinfo (2.0.6)
|
70
86
|
concurrent-ruby (~> 1.0)
|
71
|
-
unicode-display_width (2.
|
87
|
+
unicode-display_width (2.5.0)
|
72
88
|
|
73
89
|
PLATFORMS
|
74
90
|
x86_64-linux
|
data/README.md
CHANGED
@@ -32,6 +32,7 @@ Note that all cops are `Enabled: false` by default.
|
|
32
32
|
- [Sevencop/FactoryBotAssociationOption](lib/rubocop/cop/sevencop/factory_bot_association_option.rb)
|
33
33
|
- [Sevencop/FactoryBotAssociationStyle](lib/rubocop/cop/sevencop/factory_bot_association_style.rb)
|
34
34
|
- [Sevencop/HashElementOrdered](lib/rubocop/cop/sevencop/hash_element_ordered.rb)
|
35
|
+
- [Sevencop/MapMethodChain](lib/rubocop/cop/sevencop/map_method_chain.rb)
|
35
36
|
- [Sevencop/MethodDefinitionArgumentsMultiline](lib/rubocop/cop/sevencop/method_definition_arguments_multiline.rb)
|
36
37
|
- [Sevencop/MethodDefinitionInIncluded](lib/rubocop/cop/sevencop/method_definition_in_included.rb)
|
37
38
|
- [Sevencop/MethodDefinitionKeywordArgumentOrdered](lib/rubocop/cop/sevencop/method_definition_keyword_argument_ordered.rb)
|
data/config/default.yml
CHANGED
@@ -37,6 +37,12 @@ Sevencop/HashElementOrdered:
|
|
37
37
|
Enabled: false
|
38
38
|
Safe: false
|
39
39
|
|
40
|
+
Sevencop/MapMethodChain:
|
41
|
+
Description: |
|
42
|
+
Checks if the map method is used in a chain.
|
43
|
+
Enabled: false
|
44
|
+
Safe: false
|
45
|
+
|
40
46
|
Sevencop/MethodDefinitionArgumentsMultiline:
|
41
47
|
Description: |
|
42
48
|
Inserts new lines between method definition arguments.
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Sevencop
|
6
|
+
# Checks if the map method is used in a chain.
|
7
|
+
#
|
8
|
+
# This cop is another version of `Performance/MapMethodChain` cop which has the autocorrection support.
|
9
|
+
# They have decided not to add autocorrection, so we have this cop in case you want to use it.
|
10
|
+
# https://github.com/rubocop/rubocop-performance/issues/436
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# # bad
|
14
|
+
# array.map(&:foo).map(&:bar)
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# array.map { |element| element.foo.bar }
|
18
|
+
class MapMethodChain < Base
|
19
|
+
extend AutoCorrector
|
20
|
+
|
21
|
+
include IgnoredNode
|
22
|
+
|
23
|
+
RESTRICT_ON_SEND = %i[map collect].freeze
|
24
|
+
|
25
|
+
# @!method block_pass_with_symbol_arg?(node)
|
26
|
+
def_node_matcher :block_pass_with_symbol_arg?, <<~PATTERN
|
27
|
+
(:block_pass (:sym $_))
|
28
|
+
PATTERN
|
29
|
+
|
30
|
+
def on_send(node)
|
31
|
+
return if part_of_ignored_node?(node)
|
32
|
+
return unless (map_arg = block_pass_with_symbol_arg?(node.first_argument))
|
33
|
+
|
34
|
+
map_args = [map_arg]
|
35
|
+
return unless (begin_of_chained_map_method = find_begin_of_chained_map_method(node, map_args))
|
36
|
+
|
37
|
+
range = begin_of_chained_map_method.loc.selector.begin.join(node.source_range.end)
|
38
|
+
replacement = "#{begin_of_chained_map_method.method_name} { |element| element.#{map_args.join('.')} }"
|
39
|
+
add_offense(
|
40
|
+
range,
|
41
|
+
message: format(
|
42
|
+
'Use `%<replacement>s` instead of `%<method_name>s` method chain.',
|
43
|
+
method_name: begin_of_chained_map_method.method_name,
|
44
|
+
replacement: replacement
|
45
|
+
)
|
46
|
+
) do |corrector|
|
47
|
+
corrector.replace(range, replacement)
|
48
|
+
end
|
49
|
+
|
50
|
+
ignore_node(node)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def find_begin_of_chained_map_method(
|
56
|
+
node,
|
57
|
+
map_args
|
58
|
+
)
|
59
|
+
return unless (chained_map_method = node.receiver)
|
60
|
+
return if !chained_map_method.call_type? || !RESTRICT_ON_SEND.include?(chained_map_method.method_name)
|
61
|
+
return unless (map_arg = block_pass_with_symbol_arg?(chained_map_method.first_argument))
|
62
|
+
|
63
|
+
map_args.unshift(map_arg)
|
64
|
+
|
65
|
+
receiver = chained_map_method.receiver
|
66
|
+
|
67
|
+
return chained_map_method unless receiver&.call_type? && block_pass_with_symbol_arg?(receiver.first_argument)
|
68
|
+
|
69
|
+
find_begin_of_chained_map_method(chained_map_method, map_args)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
return unless without_options?(node) || (with_hash_options?(node) && !with_optional?(node))
|
49
49
|
|
50
50
|
add_offense(node) do |corrector|
|
51
|
-
corrector.insert_after(node.
|
51
|
+
corrector.insert_after(node.last_argument, ', optional: true')
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -48,10 +48,10 @@ module RuboCop
|
|
48
48
|
def on_send(node)
|
49
49
|
return unless order_with_field?(node)
|
50
50
|
|
51
|
-
first_argument_node = node.
|
51
|
+
first_argument_node = node.first_argument
|
52
52
|
add_offense(first_argument_node) do |corrector|
|
53
53
|
corrector.replace(
|
54
|
-
node.
|
54
|
+
node.first_argument,
|
55
55
|
"Arel.sql(#{first_argument_node.source})"
|
56
56
|
)
|
57
57
|
end
|
data/lib/sevencop/version.rb
CHANGED
data/lib/sevencop.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative 'rubocop/cop/sevencop/autoload_ordered'
|
|
8
8
|
require_relative 'rubocop/cop/sevencop/factory_bot_association_option'
|
9
9
|
require_relative 'rubocop/cop/sevencop/factory_bot_association_style'
|
10
10
|
require_relative 'rubocop/cop/sevencop/hash_element_ordered'
|
11
|
+
require_relative 'rubocop/cop/sevencop/map_method_chain'
|
11
12
|
require_relative 'rubocop/cop/sevencop/method_definition_arguments_multiline'
|
12
13
|
require_relative 'rubocop/cop/sevencop/method_definition_in_included'
|
13
14
|
require_relative 'rubocop/cop/sevencop/method_definition_keyword_argument_ordered'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sevencop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.36.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/rubocop/cop/sevencop/factory_bot_association_option.rb
|
61
61
|
- lib/rubocop/cop/sevencop/factory_bot_association_style.rb
|
62
62
|
- lib/rubocop/cop/sevencop/hash_element_ordered.rb
|
63
|
+
- lib/rubocop/cop/sevencop/map_method_chain.rb
|
63
64
|
- lib/rubocop/cop/sevencop/method_definition_arguments_multiline.rb
|
64
65
|
- lib/rubocop/cop/sevencop/method_definition_in_included.rb
|
65
66
|
- lib/rubocop/cop/sevencop/method_definition_keyword_argument_ordered.rb
|