sevencop 0.35.1 → 0.37.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00bdcb34361d6d2adc9c56ad5c04a70763a03b9ed94c94836855ccf1bae0504a
4
- data.tar.gz: 42425e905007e02da20af812e08d388a6ab897abc7ae6963084110e709524774
3
+ metadata.gz: 8f8b9af448980183de77764548e3b31c6e402816213fdeb8700a9ab619b2703a
4
+ data.tar.gz: b534ee269ff21655204b2eeb2397703f3c378c34c0e0c3d4702b59c2f96afb2d
5
5
  SHA512:
6
- metadata.gz: 157017650f5d89046b8acfc2cdc7505c3fe24d9f88ebcdde530ca362c11291b2ece58c02fb983843e2c42ded4262ae2e638bed2f3feb9ffa26149405185e623a
7
- data.tar.gz: b42d35a4f16268871b51f794b4d1fcf68cef53576889a8ebbb913fb3ffefb3e0b9ee8d27bbf1eb44d981f9a491f6d14cfae70f026495312a459bdd131f011d5f
6
+ metadata.gz: a7eeff888f7f8f708ef105d9842a9c16db91da60984076528f3c9d4e364bce4934bb04e5fe108c2af2841a1b71438dcad3d82afd963256613ff95adf6ecf95b3
7
+ data.tar.gz: a0a838e1f7ae5eb4c12a0bb30a327140cb5b4bddbfc1c5e089bc1fbc200e19144eab18a263fca11ab1574d9d2d4de4a735e62ee6e3787b6fc6cb96a50a59d648
data/.rubocop.yml CHANGED
@@ -19,6 +19,7 @@ Layout/LineLength:
19
19
  Lint/UselessAccessModifier:
20
20
  MethodCreatingMethods:
21
21
  - def_node_matcher
22
+ - def_node_search
22
23
 
23
24
  Metrics:
24
25
  Enabled: false
@@ -39,10 +40,19 @@ RSpec/FilePath:
39
40
  RSpecEmptyLineAfterLet: rspec_empty_line_after_let
40
41
  RSpecExamplesInSameGroup: rspec_examples_in_same_group
41
42
  RSpecMemoizedHelperBlockDelimiter: rspec_memoized_helper_block_delimiter
43
+ RSpecRailsHaveHttpStatus: rspec_rails_have_http_status
42
44
 
43
45
  RSpec/MultipleExpectations:
44
46
  Enabled: false
45
47
 
48
+ RSpec/SpecFilePathFormat:
49
+ CustomTransform:
50
+ RSpecDescribeHttpEndpoint: rspec_describe_http_endpoint
51
+ RSpecEmptyLineAfterLet: rspec_empty_line_after_let
52
+ RSpecExamplesInSameGroup: rspec_examples_in_same_group
53
+ RSpecMemoizedHelperBlockDelimiter: rspec_memoized_helper_block_delimiter
54
+ RSpecRailsHaveHttpStatus: rspec_rails_have_http_status
55
+
46
56
  Sevencop/AutoloadOrdered:
47
57
  Enabled: true
48
58
 
data/Gemfile.lock CHANGED
@@ -1,32 +1,46 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sevencop (0.35.1)
4
+ sevencop (0.37.0)
5
5
  activesupport
6
6
  rubocop
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (7.0.5)
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
- concurrent-ruby (1.2.2)
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.6.3)
22
- minitest (5.18.0)
23
- parallel (1.23.0)
24
- parser (3.2.2.1)
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.6)
28
- regexp_parser (2.8.0)
29
- rexml (3.2.5)
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.5)
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.0)
43
- rubocop (1.50.2)
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.2.0.0)
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.28.0, < 2.0)
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.28.1)
68
+ rubocop-ast (1.30.0)
54
69
  parser (>= 3.2.1.0)
55
- rubocop-capybara (2.18.0)
70
+ rubocop-capybara (2.20.0)
56
71
  rubocop (~> 1.41)
57
- rubocop-factory_bot (2.22.0)
58
- rubocop (~> 1.33)
59
- rubocop-performance (1.17.1)
60
- rubocop (>= 1.7.0, < 2.0)
61
- rubocop-ast (>= 0.4.0)
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.22.0)
65
- rubocop (~> 1.33)
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.4.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)
@@ -47,6 +48,7 @@ Note that all cops are `Enabled: false` by default.
47
48
  - [Sevencop/RSpecEmptyLineAfterLet](lib/rubocop/cop/sevencop/rspec_empty_line_after_let.rb)
48
49
  - [Sevencop/RSpecExamplesInSameGroup](lib/rubocop/cop/sevencop/rspec_examples_in_same_group.rb)
49
50
  - [Sevencop/RSpecMemoizedHelperBlockDelimiter](lib/rubocop/cop/sevencop/rspec_memoized_helper_block_delimiter.rb)
51
+ - [Sevencop/RSpecRailsHaveHttpStatus](lib/rubocop/cop/sevencop/rspec_rails_have_http_status.rb)
50
52
 
51
53
  ## Notes
52
54
 
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.
@@ -140,3 +146,11 @@ Sevencop/RSpecMemoizedHelperBlockDelimiter:
140
146
  Enabled: false
141
147
  Include:
142
148
  - spec/**/*
149
+
150
+ Sevencop/RSpecRailsHaveHttpStatus:
151
+ Description: |
152
+ Always check status code with `have_http_status`.
153
+ Enabled: false
154
+ Include:
155
+ - spec/controllers/**/*
156
+ - spec/requests/**/*
@@ -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.arguments[-1], ', optional: true')
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.arguments.first
51
+ first_argument_node = node.first_argument
52
52
  add_offense(first_argument_node) do |corrector|
53
53
  corrector.replace(
54
- node.arguments.first,
54
+ node.first_argument,
55
55
  "Arel.sql(#{first_argument_node.source})"
56
56
  )
57
57
  end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Sevencop
6
+ # Always check status code with `have_http_status`.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # it 'creates a new post' do
11
+ # expect { subject }.to change(Post, :count).by(1)
12
+ # end
13
+ #
14
+ # # good
15
+ # it 'creates a new post' do
16
+ # expect { subject }.to change(Post, :count).by(1)
17
+ # expect(response).to have_http_status(200)
18
+ # end
19
+ #
20
+ # # good
21
+ # it 'creates a new post' do
22
+ # expect { subject }.to change(Post, :count).by(1)
23
+ # expect(response).to redirect_to(posts_path)
24
+ # end
25
+ class RSpecRailsHaveHttpStatus < Base
26
+ MSG = 'Always check status code with `have_http_status`.'
27
+
28
+ EXAMPLE_METHOD_NAMES = %i[
29
+ example
30
+ it
31
+ specify
32
+ ].to_set.freeze
33
+
34
+ STATUS_CHECK_METHOD_NAMES = %i[
35
+ have_http_status
36
+ redirect_to
37
+ ].to_set.freeze
38
+
39
+ # @param [RuboCop::AST::BlockNode] node
40
+ # @return [void]
41
+ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
42
+ return unless example_method?(node)
43
+ return if including_status_check_method?(node)
44
+
45
+ add_offense(node)
46
+ end
47
+
48
+ private
49
+
50
+ # @!method example_method?(node)
51
+ # @param [RuboCop::AST::BlockNode] node
52
+ # @return [Boolean]
53
+ def_node_matcher :example_method?, <<~PATTERN
54
+ (block (send nil? EXAMPLE_METHOD_NAMES ...) ...)
55
+ PATTERN
56
+
57
+ # @!method including_status_check_method?(node)
58
+ # @param [RuboCop::AST::BlockNode] node
59
+ # @return [Boolean]
60
+ def_node_search :including_status_check_method?, <<~PATTERN
61
+ (send nil? STATUS_CHECK_METHOD_NAMES ...)
62
+ PATTERN
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sevencop
4
- VERSION = '0.35.1'
4
+ VERSION = '0.37.0'
5
5
  end
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'
@@ -23,3 +24,4 @@ require_relative 'rubocop/cop/sevencop/rspec_describe_http_endpoint'
23
24
  require_relative 'rubocop/cop/sevencop/rspec_empty_line_after_let'
24
25
  require_relative 'rubocop/cop/sevencop/rspec_examples_in_same_group'
25
26
  require_relative 'rubocop/cop/sevencop/rspec_memoized_helper_block_delimiter'
27
+ require_relative 'rubocop/cop/sevencop/rspec_rails_have_http_status'
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.35.1
4
+ version: 0.37.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: 2023-06-04 00:00:00.000000000 Z
11
+ date: 2024-02-01 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
@@ -75,6 +76,7 @@ files:
75
76
  - lib/rubocop/cop/sevencop/rspec_empty_line_after_let.rb
76
77
  - lib/rubocop/cop/sevencop/rspec_examples_in_same_group.rb
77
78
  - lib/rubocop/cop/sevencop/rspec_memoized_helper_block_delimiter.rb
79
+ - lib/rubocop/cop/sevencop/rspec_rails_have_http_status.rb
78
80
  - lib/sevencop.rb
79
81
  - lib/sevencop/config_loader.rb
80
82
  - lib/sevencop/cop_concerns.rb