sevencop 0.27.0 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a2d0d56a1f5cbd0bc259bf81abbd5f2120f0a79e535ff9fafe6793de262dfb0
4
- data.tar.gz: a43deda18fed1e061b3442a4bfb6ed27f7af6b71522adde160fe530326462722
3
+ metadata.gz: 79bb602015c9eea9c89de44bfbd22274ef1197412a420f274280cc3cac7fe8c5
4
+ data.tar.gz: 8fe918f1ad6031ec0b4886a778e5333d9574ecf23c5658f133e32423349d2a28
5
5
  SHA512:
6
- metadata.gz: f4888e9cd333099c4ec83c9d0b71349572ad471f4788efe1d8eee377f10286eb6d5c8534e6bb427ad52303f5fcf24e77fc7f3df9aab9ebc35ac726e0098b940f
7
- data.tar.gz: 1cc3e089fa3e922131dd91e4e2c1c7fa6f835a1619bc8c9234f7f86af4e677a0d033583ea8f4eb1cfc3f1da5abc93222eb8506749c616c434350275a18859af0
6
+ metadata.gz: 0bdc4d1d137ea5c3a3b2048e8c1aa37bfff81672aef0b10d75cc361f4ff10938d9327ec1193f7936b6180b8fc2e2f6e51909723a9b036279c2852d76e810990b
7
+ data.tar.gz: 4235669bbd83b5f460663877b3e47272bffa0aadec21e1f413a7e957c6f0bdafe851443d0bbff5985553978b495e4b8c0d418b7736b9ebc9f2ee941859885f85
data/.rubocop.yml CHANGED
@@ -16,6 +16,10 @@ Gemspec/RequireMFA:
16
16
  Layout/LineLength:
17
17
  Enabled: false
18
18
 
19
+ Lint/UselessAccessModifier:
20
+ MethodCreatingMethods:
21
+ - def_node_matcher
22
+
19
23
  Metrics:
20
24
  Enabled: false
21
25
 
@@ -35,6 +39,7 @@ RSpec/FilePath:
35
39
  RSpecEmptyLineAfterLet: rspec_empty_line_after_let
36
40
  RSpecExamplesInSameGroup: rspec_examples_in_same_group
37
41
  RSpecMemoizedHelperBlockDelimiter: rspec_memoized_helper_block_delimiter
42
+ RSpecRailsResponseParsedBody: rspec_rails_response_parsed_body
38
43
 
39
44
  RSpec/MultipleExpectations:
40
45
  Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sevencop (0.27.0)
4
+ sevencop (0.28.0)
5
5
  activesupport
6
6
  rubocop
7
7
 
data/README.md CHANGED
@@ -48,6 +48,7 @@ Note that all cops are `Enabled: false` by default.
48
48
  - [Sevencop/RSpecEmptyLineAfterLet](lib/rubocop/cop/sevencop/rspec_empty_line_after_let.rb)
49
49
  - [Sevencop/RSpecExamplesInSameGroup](lib/rubocop/cop/sevencop/rspec_examples_in_same_group.rb)
50
50
  - [Sevencop/RSpecMemoizedHelperBlockDelimiter](lib/rubocop/cop/sevencop/rspec_memoized_helper_block_delimiter.rb)
51
+ - [Sevencop/RSpecRailsResponseParsedBody](lib/rubocop/cop/sevencop/rspec_rails_response_parsed_body.rb)
51
52
 
52
53
  ## Notes
53
54
 
data/config/default.yml CHANGED
@@ -166,3 +166,13 @@ Sevencop/RSpecMemoizedHelperBlockDelimiter:
166
166
  VersionAdded: '0.27'
167
167
  Include:
168
168
  - spec/**/*
169
+
170
+ Sevencop/RSpecRailsResponseParsedBody:
171
+ Description: |
172
+ Prefer `response.parsed_body` to `JSON.parse(response.body)`.
173
+ Enabled: false
174
+ Safe: false
175
+ VersionAdded: '0.28'
176
+ Include:
177
+ - spec/controllers/**/*
178
+ - spec/requests/**/*
@@ -71,7 +71,7 @@ module RuboCop
71
71
  _
72
72
  _
73
73
  _*
74
- ({ hash | kwargs }
74
+ (hash
75
75
  (pair ...)*
76
76
  $(pair (sym :type) sym)
77
77
  (pair ...)*
@@ -22,7 +22,7 @@ module RuboCop
22
22
  def_node_matcher :rails_where_not_with_multiple_elements_hash?, <<~PATTERN
23
23
  (send
24
24
  (send _ :where) :not
25
- ({ hash | kwargs }
25
+ (hash
26
26
  (pair _ _)
27
27
  (pair _ _)+))
28
28
  PATTERN
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Sevencop
6
+ # Prefer `response.parsed_body` to `JSON.parse(response.body)`.
7
+ #
8
+ # @safety
9
+ # This cop is unsafe because Content-Type may not be `application/json`.
10
+ #
11
+ # @example
12
+ # # bad
13
+ # JSON.parse(response.body)
14
+ #
15
+ # # good
16
+ # response.parsed_body
17
+ class RSpecRailsResponseParsedBody < Base
18
+ extend AutoCorrector
19
+
20
+ MSG = 'Prefer `response.parsed_body` to `JSON.parse(response.body)`.'
21
+
22
+ RESTRICT_ON_SEND = %i[parse].freeze
23
+
24
+ # @param node [RuboCop::AST::SendNode]
25
+ # @return [void]
26
+ def on_send(node)
27
+ return unless bad?(node)
28
+
29
+ add_offense(node) do |corrector|
30
+ autocorrect(corrector, node)
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ # @!method json_parse_response_body?(node)
37
+ # @param node [RuboCop::AST::Node]
38
+ # @return [Boolean]
39
+ def_node_matcher :json_parse_response_body?, <<~PATTERN
40
+ (send
41
+ (const
42
+ {nil? cbase}
43
+ :JSON
44
+ )
45
+ :parse
46
+ (send
47
+ (send
48
+ nil?
49
+ :response
50
+ )
51
+ :body
52
+ )
53
+ )
54
+ PATTERN
55
+ alias bad? json_parse_response_body?
56
+
57
+ # @param corrector [RuboCop::Cop::Corrector]
58
+ # @param node [RuboCop::AST::SendNode]
59
+ # @return [void]
60
+ def autocorrect(
61
+ corrector,
62
+ node
63
+ )
64
+ corrector.replace(node, 'response.parsed_body')
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sevencop
4
- VERSION = '0.27.0'
4
+ VERSION = '0.28.0'
5
5
  end
data/lib/sevencop.rb CHANGED
@@ -24,3 +24,4 @@ require_relative 'rubocop/cop/sevencop/rspec_describe_http_endpoint'
24
24
  require_relative 'rubocop/cop/sevencop/rspec_empty_line_after_let'
25
25
  require_relative 'rubocop/cop/sevencop/rspec_examples_in_same_group'
26
26
  require_relative 'rubocop/cop/sevencop/rspec_memoized_helper_block_delimiter'
27
+ require_relative 'rubocop/cop/sevencop/rspec_rails_response_parsed_body'
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.27.0
4
+ version: 0.28.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: 2022-11-02 00:00:00.000000000 Z
11
+ date: 2022-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -76,6 +76,7 @@ files:
76
76
  - lib/rubocop/cop/sevencop/rspec_empty_line_after_let.rb
77
77
  - lib/rubocop/cop/sevencop/rspec_examples_in_same_group.rb
78
78
  - lib/rubocop/cop/sevencop/rspec_memoized_helper_block_delimiter.rb
79
+ - lib/rubocop/cop/sevencop/rspec_rails_response_parsed_body.rb
79
80
  - lib/sevencop.rb
80
81
  - lib/sevencop/config_loader.rb
81
82
  - lib/sevencop/cop_concerns.rb