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 +4 -4
- data/.rubocop.yml +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/config/default.yml +10 -0
- data/lib/rubocop/cop/sevencop/rails_inferred_spec_type.rb +1 -1
- data/lib/rubocop/cop/sevencop/rails_where_not.rb +1 -1
- data/lib/rubocop/cop/sevencop/rspec_rails_response_parsed_body.rb +69 -0
- 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: 79bb602015c9eea9c89de44bfbd22274ef1197412a420f274280cc3cac7fe8c5
|
4
|
+
data.tar.gz: 8fe918f1ad6031ec0b4886a778e5333d9574ecf23c5658f133e32423349d2a28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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/**/*
|
@@ -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
|
data/lib/sevencop/version.rb
CHANGED
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.
|
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-
|
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
|