sevencop 0.27.0 → 0.29.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 +2 -1
- data/config/default.yml +27 -16
- data/lib/rubocop/cop/sevencop/rails_inferred_spec_type.rb +1 -1
- data/lib/rubocop/cop/sevencop/{rails_action_name.rb → rails_specific_action_name.rb} +11 -2
- 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 +2 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d415f24d882b17eb832c22fa9a17d40ebf1ea91fda15e5a25e8e5ceea6824633
|
4
|
+
data.tar.gz: b770d04a2620d1ef6e5f7a0e0b0cd1e6f440b44a5173bd8c26890f0707a4e9b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddd45cdafff3edc2512a962f32d817cd5836f5435547d987c76f96a0d3a873f8398506dc567caea00ed165f7bd206378bcdbea71eec0516fe05ce7249a2b88e9
|
7
|
+
data.tar.gz: 737bd07f00679aa77fce2209f9692b5babff560362a03c412f228584f74d4cd213bbfc5a1223ed999e3ba66abb3f6f7cd7cfcd1d702ee4fed7f8f80d4940e0a3
|
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
@@ -36,11 +36,11 @@ Note that all cops are `Enabled: false` by default.
|
|
36
36
|
- [Sevencop/MethodDefinitionInIncluded](lib/rubocop/cop/sevencop/method_definition_in_included.rb)
|
37
37
|
- [Sevencop/MethodDefinitionKeywordArgumentOrdered](lib/rubocop/cop/sevencop/method_definition_keyword_argument_ordered.rb)
|
38
38
|
- [Sevencop/MethodDefinitionOrdered](lib/rubocop/cop/sevencop/method_definition_ordered.rb)
|
39
|
-
- [Sevencop/RailsActionName](lib/rubocop/cop/sevencop/rails_action_name.rb)
|
40
39
|
- [Sevencop/RailsBelongsToOptional](lib/rubocop/cop/sevencop/rails_belongs_to_optional.rb)
|
41
40
|
- [Sevencop/RailsDateAndTimeCalculation](lib/rubocop/cop/sevencop/rails_date_and_time_calculation.rb)
|
42
41
|
- [Sevencop/RailsInferredSpecType](lib/rubocop/cop/sevencop/rails_inferred_spec_type.rb)
|
43
42
|
- [Sevencop/RailsOrderField](lib/rubocop/cop/sevencop/rails_order_field.rb)
|
43
|
+
- [Sevencop/RailsSpecificActionName](lib/rubocop/cop/sevencop/rails_specific_action_name.rb)
|
44
44
|
- [Sevencop/RailsUniquenessValidatorExplicitCaseSensitivity](lib/rubocop/cop/sevencop/rails_uniqueness_validator_explicit_case_sensitivity.rb)
|
45
45
|
- [Sevencop/RailsWhereNot](lib/rubocop/cop/sevencop/rails_where_not.rb)
|
46
46
|
- [Sevencop/RequireOrdered](lib/rubocop/cop/sevencop/require_ordered.rb)
|
@@ -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
@@ -68,22 +68,6 @@ Sevencop/MethodDefinitionKeywordArgumentOrdered:
|
|
68
68
|
Safe: false
|
69
69
|
VersionAdded: '0.13'
|
70
70
|
|
71
|
-
Sevencop/RailsActionName:
|
72
|
-
Description: |
|
73
|
-
Use only specific action names.
|
74
|
-
Enabled: false
|
75
|
-
VersionAdded: '0.24'
|
76
|
-
ActionNames:
|
77
|
-
- create
|
78
|
-
- destroy
|
79
|
-
- edit
|
80
|
-
- index
|
81
|
-
- new
|
82
|
-
- show
|
83
|
-
- update
|
84
|
-
Include:
|
85
|
-
- app/controllers/**/*.rb
|
86
|
-
|
87
71
|
Sevencop/RailsBelongsToOptional:
|
88
72
|
Description: |
|
89
73
|
Force `belongs_to` with `optional: true` option.
|
@@ -112,6 +96,23 @@ Sevencop/RailsOrderField:
|
|
112
96
|
Safe: false
|
113
97
|
VersionAdded: '0.4'
|
114
98
|
|
99
|
+
Sevencop/RailsSpecificActionName:
|
100
|
+
Description: |
|
101
|
+
Use only specific action names.
|
102
|
+
Enabled: false
|
103
|
+
VersionAdded: '0.24'
|
104
|
+
VersionChanged: '0.29'
|
105
|
+
ActionNames:
|
106
|
+
- create
|
107
|
+
- destroy
|
108
|
+
- edit
|
109
|
+
- index
|
110
|
+
- new
|
111
|
+
- show
|
112
|
+
- update
|
113
|
+
Include:
|
114
|
+
- app/controllers/**/*.rb
|
115
|
+
|
115
116
|
Sevencop/RailsUniquenessValidatorExplicitCaseSensitivity:
|
116
117
|
Description: |
|
117
118
|
Specify :case_sensitivity option on use of UniquenessValidator.
|
@@ -166,3 +167,13 @@ Sevencop/RSpecMemoizedHelperBlockDelimiter:
|
|
166
167
|
VersionAdded: '0.27'
|
167
168
|
Include:
|
168
169
|
- spec/**/*
|
170
|
+
|
171
|
+
Sevencop/RSpecRailsResponseParsedBody:
|
172
|
+
Description: |
|
173
|
+
Prefer `response.parsed_body` to `JSON.parse(response.body)`.
|
174
|
+
Enabled: false
|
175
|
+
Safe: false
|
176
|
+
VersionAdded: '0.28'
|
177
|
+
Include:
|
178
|
+
- spec/controllers/**/*
|
179
|
+
- spec/requests/**/*
|
@@ -5,6 +5,9 @@ module RuboCop
|
|
5
5
|
module Sevencop
|
6
6
|
# Use only specific action names.
|
7
7
|
#
|
8
|
+
# It is good practice to separate controller classes rather than adding more actions as needed.
|
9
|
+
# By default, the 7 CRUD action names are specified that are generated by the Rails scaffold.
|
10
|
+
#
|
8
11
|
# @example
|
9
12
|
# # bad
|
10
13
|
# class UsersController < ApplicationController
|
@@ -17,7 +20,7 @@ module RuboCop
|
|
17
20
|
# def index
|
18
21
|
# end
|
19
22
|
# end
|
20
|
-
class
|
23
|
+
class RailsSpecificActionName < Base
|
21
24
|
include VisibilityHelp
|
22
25
|
|
23
26
|
MSG = 'Use only specific action names.'
|
@@ -27,7 +30,13 @@ module RuboCop
|
|
27
30
|
def on_def(node)
|
28
31
|
return unless bad?(node)
|
29
32
|
|
30
|
-
add_offense(
|
33
|
+
add_offense(
|
34
|
+
node.location.name,
|
35
|
+
message: format(
|
36
|
+
'Use only specific action names (%<action_names>s).',
|
37
|
+
action_names: configured_action_names.join(', ')
|
38
|
+
)
|
39
|
+
)
|
31
40
|
end
|
32
41
|
|
33
42
|
private
|
@@ -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
@@ -12,11 +12,11 @@ require_relative 'rubocop/cop/sevencop/method_definition_arguments_multiline'
|
|
12
12
|
require_relative 'rubocop/cop/sevencop/method_definition_in_included'
|
13
13
|
require_relative 'rubocop/cop/sevencop/method_definition_keyword_argument_ordered'
|
14
14
|
require_relative 'rubocop/cop/sevencop/method_definition_ordered'
|
15
|
-
require_relative 'rubocop/cop/sevencop/rails_action_name'
|
16
15
|
require_relative 'rubocop/cop/sevencop/rails_belongs_to_optional'
|
17
16
|
require_relative 'rubocop/cop/sevencop/rails_date_and_time_calculation'
|
18
17
|
require_relative 'rubocop/cop/sevencop/rails_inferred_spec_type'
|
19
18
|
require_relative 'rubocop/cop/sevencop/rails_order_field'
|
19
|
+
require_relative 'rubocop/cop/sevencop/rails_specific_action_name'
|
20
20
|
require_relative 'rubocop/cop/sevencop/rails_uniqueness_validator_explicit_case_sensitivity'
|
21
21
|
require_relative 'rubocop/cop/sevencop/rails_where_not'
|
22
22
|
require_relative 'rubocop/cop/sevencop/require_ordered'
|
@@ -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.29.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-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -64,11 +64,11 @@ files:
|
|
64
64
|
- lib/rubocop/cop/sevencop/method_definition_in_included.rb
|
65
65
|
- lib/rubocop/cop/sevencop/method_definition_keyword_argument_ordered.rb
|
66
66
|
- lib/rubocop/cop/sevencop/method_definition_ordered.rb
|
67
|
-
- lib/rubocop/cop/sevencop/rails_action_name.rb
|
68
67
|
- lib/rubocop/cop/sevencop/rails_belongs_to_optional.rb
|
69
68
|
- lib/rubocop/cop/sevencop/rails_date_and_time_calculation.rb
|
70
69
|
- lib/rubocop/cop/sevencop/rails_inferred_spec_type.rb
|
71
70
|
- lib/rubocop/cop/sevencop/rails_order_field.rb
|
71
|
+
- lib/rubocop/cop/sevencop/rails_specific_action_name.rb
|
72
72
|
- lib/rubocop/cop/sevencop/rails_uniqueness_validator_explicit_case_sensitivity.rb
|
73
73
|
- lib/rubocop/cop/sevencop/rails_where_not.rb
|
74
74
|
- lib/rubocop/cop/sevencop/require_ordered.rb
|
@@ -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
|