sevencop 0.23.0 → 0.24.2
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 +4 -4
- data/.rubocop.yml +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +5 -0
- data/config/default.yml +16 -0
- data/lib/rubocop/cop/sevencop/rails_action_name.rb +61 -0
- data/lib/rubocop/cop/sevencop/rspec_describe_http_endpoint.rb +23 -10
- 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: 47139f7d9fb3b1e73416958e9f2f87ccafa4145864e046a1539ffd33018bd603
|
4
|
+
data.tar.gz: f9c759a3adbbf7e25b327755c8d5fc0a00d5f6438f79b4df3e33d138ca296fb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e43613b26de17bca55c264a4892a3c20684fcc5c6e285c2407249c6369218d82650bdfb0e8963fd43c19c25a5fe24d885c4074894c8bc28fc105a0ba2dbfbb6e
|
7
|
+
data.tar.gz: 4697e89105ef1bcd388a72af2505d3b1d19ea5fa0f1c3867d3fca0313d0c470d38b92eb89fa477e6782fbd83dff3e32300cfd812b67dd06b472fd6747480b10a
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -36,6 +36,7 @@ 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)
|
39
40
|
- [Sevencop/RailsBelongsToOptional](lib/rubocop/cop/sevencop/rails_belongs_to_optional.rb)
|
40
41
|
- [Sevencop/RailsInferredSpecType](lib/rubocop/cop/sevencop/rails_inferred_spec_type.rb)
|
41
42
|
- [Sevencop/RailsOrderField](lib/rubocop/cop/sevencop/rails_order_field.rb)
|
@@ -44,3 +45,7 @@ Note that all cops are `Enabled: false` by default.
|
|
44
45
|
- [Sevencop/RequireOrdered](lib/rubocop/cop/sevencop/require_ordered.rb)
|
45
46
|
- [Sevencop/RSpecDescribeHttpEndpoint](lib/rubocop/cop/sevencop/rspec_describe_http_endpoint.rb)
|
46
47
|
- [Sevencop/RSpecExamplesInSameGroup](lib/rubocop/cop/sevencop/rspec_examples_in_same_group.rb)
|
48
|
+
|
49
|
+
## Notes
|
50
|
+
|
51
|
+
All migration related cops are moved to [r7kamura/rubocop-migration](https://github.com/r7kamura/rubocop-migration).
|
data/config/default.yml
CHANGED
@@ -68,6 +68,22 @@ 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
|
+
|
71
87
|
Sevencop/RailsBelongsToOptional:
|
72
88
|
Description: |
|
73
89
|
Force `belongs_to` with `optional: true` option.
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Sevencop
|
6
|
+
# Use only specific action names.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# class UsersController < ApplicationController
|
11
|
+
# def articles
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
# class UserArticlesController < ApplicationController
|
17
|
+
# def index
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
class RailsActionName < Base
|
21
|
+
include VisibilityHelp
|
22
|
+
|
23
|
+
MSG = 'Use only specific action names.'
|
24
|
+
|
25
|
+
# @param node [RuboCop::AST::DefNode]
|
26
|
+
# @return [void]
|
27
|
+
def on_def(node)
|
28
|
+
return unless bad?(node)
|
29
|
+
|
30
|
+
add_offense(node.location.name)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# @param node [RuboCop::AST::DefNode]
|
36
|
+
# @return [Boolean]
|
37
|
+
def action?(node)
|
38
|
+
node_visibility(node) == :public
|
39
|
+
end
|
40
|
+
|
41
|
+
# @param node [RuboCop::AST::DefNode]
|
42
|
+
# @return [Boolean]
|
43
|
+
def bad?(node)
|
44
|
+
action?(node) &&
|
45
|
+
!configured_action_name?(node)
|
46
|
+
end
|
47
|
+
|
48
|
+
# @param node [RuboCop::AST::DefNode]
|
49
|
+
# @return [Boolean]
|
50
|
+
def configured_action_name?(node)
|
51
|
+
configured_action_names.include?(node.method_name.to_s)
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Array<String>]
|
55
|
+
def configured_action_names
|
56
|
+
cop_config['ActionNames']
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -33,30 +33,43 @@ module RuboCop
|
|
33
33
|
# @param node [RuboCop::AST::SendNode]
|
34
34
|
# @return [void]
|
35
35
|
def on_send(node)
|
36
|
-
return unless
|
37
|
-
return unless node.first_argument
|
38
|
-
return if http_endpoint_identifier?(node.first_argument)
|
36
|
+
return unless bad?(node)
|
39
37
|
|
40
38
|
add_offense(node.first_argument)
|
41
39
|
end
|
42
40
|
|
43
41
|
private
|
44
42
|
|
45
|
-
# @!method
|
43
|
+
# @!method describing_http_endpoint_identifier?(node)
|
46
44
|
# @param node [RuboCop::AST::SendNode]
|
47
45
|
# @return [Boolean]
|
48
|
-
def_node_matcher :
|
46
|
+
def_node_matcher :describing_http_endpoint_identifier?, <<~PATTERN
|
49
47
|
(send
|
50
|
-
|
48
|
+
_
|
51
49
|
:describe
|
50
|
+
(str DESCRIPTION_PATTERN)
|
52
51
|
...
|
53
52
|
)
|
54
53
|
PATTERN
|
55
54
|
|
56
|
-
#
|
57
|
-
#
|
58
|
-
|
59
|
-
|
55
|
+
# @!method describing_at_top_level?(node)
|
56
|
+
# @param node [RuboCop::AST::SendNode]
|
57
|
+
# @return [Boolean]
|
58
|
+
def_node_matcher :describing_at_top_level?, <<~PATTERN
|
59
|
+
(send
|
60
|
+
(const
|
61
|
+
{nil? cbase}
|
62
|
+
:RSpec
|
63
|
+
)
|
64
|
+
:describe
|
65
|
+
...
|
66
|
+
)
|
67
|
+
PATTERN
|
68
|
+
|
69
|
+
# @param node [RuboCop::AST::SendNode]
|
70
|
+
def bad?(node)
|
71
|
+
describing_at_top_level?(node) &&
|
72
|
+
!describing_http_endpoint_identifier?(node)
|
60
73
|
end
|
61
74
|
end
|
62
75
|
end
|
data/lib/sevencop/version.rb
CHANGED
data/lib/sevencop.rb
CHANGED
@@ -12,6 +12,7 @@ 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'
|
15
16
|
require_relative 'rubocop/cop/sevencop/rails_belongs_to_optional'
|
16
17
|
require_relative 'rubocop/cop/sevencop/rails_inferred_spec_type'
|
17
18
|
require_relative 'rubocop/cop/sevencop/rails_order_field'
|
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.24.2
|
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-10-
|
11
|
+
date: 2022-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -64,6 +64,7 @@ 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
|
67
68
|
- lib/rubocop/cop/sevencop/rails_belongs_to_optional.rb
|
68
69
|
- lib/rubocop/cop/sevencop/rails_inferred_spec_type.rb
|
69
70
|
- lib/rubocop/cop/sevencop/rails_order_field.rb
|