momocop 0.2.1 → 0.3.1
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/README.ja.md +25 -13
- data/README.ja.md.erb +5 -3
- data/README.md +25 -13
- data/README.md.erb +5 -3
- data/config/default.yml +14 -0
- data/lib/momocop/helpers/factory_bot_helper.rb +1 -1
- data/lib/momocop/version.rb +1 -1
- data/lib/rubocop/cop/momocop/factory_bot_single_factory_per_define.rb +11 -5
- data/lib/rubocop/cop/momocop/rbi_missing_extend_t_sig.rb +139 -0
- data/lib/rubocop/cop/momocop/rspec_context_wording.rb +34 -0
- data/lib/rubocop/cop/momocop/rspec_describe_wording.rb +34 -0
- data/lib/rubocop/cop/momocop/rspec_example_wording.rb +34 -0
- metadata +10 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bae3d0f2d4c1c038b116735e1a47744d090fdb07b911688893c7987ebf44597c
|
|
4
|
+
data.tar.gz: eca84c634dbf5a6374c2e0899647f50d0e1ec65e9c6b2485c1ffaeda6e283608
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fd489ae7183fe59a0437733743e3cf1a9af80e900ff0b4ac8b059eabf700aa45fc6a37e8cdf502426f17cc331cd01fbb6cd694c2d7b5ddcdda9da92b338bf079
|
|
7
|
+
data.tar.gz: 610e80f9e71629d3a7ca56a6111774fd6bed8eed874ddde5538d40f59d80a5c722752f6e638c1a3602f8aac88e9d9e50919e6fc23e1902636f2b8a37d56bc626
|
data/README.ja.md
CHANGED
|
@@ -48,23 +48,35 @@ Momocop/FactoryBotSingularFactoryName:
|
|
|
48
48
|
Enabled: true
|
|
49
49
|
Momocop/Layout/LeadingCommentSpace:
|
|
50
50
|
Enabled: true
|
|
51
|
+
Momocop/RbiMissingExtendTSig:
|
|
52
|
+
Enabled: true
|
|
53
|
+
Momocop/RspecContextWording:
|
|
54
|
+
Enabled: true
|
|
55
|
+
Momocop/RspecDescribeWording:
|
|
56
|
+
Enabled: true
|
|
57
|
+
Momocop/RspecExampleWording:
|
|
58
|
+
Enabled: true
|
|
51
59
|
```
|
|
52
60
|
|
|
53
61
|
## Cop一覧
|
|
54
62
|
|
|
55
|
-
|Cop|Rails|FactoryBot|
|
|
56
|
-
|
|
57
|
-
|[`Momocop/FactoryBotClassExistence`](lib/rubocop/cop/momocop/factory_bot_class_existence.rb)|:white_check_mark:|:white_check_mark
|
|
58
|
-
|[`Momocop/FactoryBotConsistentFileName`](lib/rubocop/cop/momocop/factory_bot_consistent_file_name.rb)|:white_check_mark:|:white_check_mark
|
|
59
|
-
|[`Momocop/FactoryBotInlineAssociation`](lib/rubocop/cop/momocop/factory_bot_inline_association.rb)|:white_check_mark:|:white_check_mark
|
|
60
|
-
|[`Momocop/FactoryBotMissingAssociations`](lib/rubocop/cop/momocop/factory_bot_missing_associations.rb)|:white_check_mark:|:white_check_mark
|
|
61
|
-
|[`Momocop/FactoryBotMissingClassOption`](lib/rubocop/cop/momocop/factory_bot_missing_class_option.rb)|:white_check_mark:|:white_check_mark
|
|
62
|
-
|[`Momocop/FactoryBotMissingProperties`](lib/rubocop/cop/momocop/factory_bot_missing_properties.rb)|:white_check_mark:|:white_check_mark
|
|
63
|
-
|[`Momocop/FactoryBotPropertyOrder`](lib/rubocop/cop/momocop/factory_bot_property_order.rb)|:white_check_mark:|:white_check_mark
|
|
64
|
-
|[`Momocop/FactoryBotSingleDefinePerFile`](lib/rubocop/cop/momocop/factory_bot_single_define_per_file.rb)|:white_check_mark:|:white_check_mark
|
|
65
|
-
|[`Momocop/FactoryBotSingleFactoryPerDefine`](lib/rubocop/cop/momocop/factory_bot_single_factory_per_define.rb)|:white_check_mark:|:white_check_mark
|
|
66
|
-
|[`Momocop/FactoryBotSingularFactoryName`](lib/rubocop/cop/momocop/factory_bot_singular_factory_name.rb)|:white_check_mark:|:white_check_mark
|
|
67
|
-
|[`Momocop/Layout/LeadingCommentSpace`](lib/rubocop/cop/momocop/layout/leading_comment_space.rb)
|
|
63
|
+
|Cop|Rails|FactoryBot|RSpec|
|
|
64
|
+
|---|:-:|:-:|:-:|
|
|
65
|
+
|[`Momocop/FactoryBotClassExistence`](lib/rubocop/cop/momocop/factory_bot_class_existence.rb)|:white_check_mark:|:white_check_mark:||
|
|
66
|
+
|[`Momocop/FactoryBotConsistentFileName`](lib/rubocop/cop/momocop/factory_bot_consistent_file_name.rb)|:white_check_mark:|:white_check_mark:||
|
|
67
|
+
|[`Momocop/FactoryBotInlineAssociation`](lib/rubocop/cop/momocop/factory_bot_inline_association.rb)|:white_check_mark:|:white_check_mark:||
|
|
68
|
+
|[`Momocop/FactoryBotMissingAssociations`](lib/rubocop/cop/momocop/factory_bot_missing_associations.rb)|:white_check_mark:|:white_check_mark:||
|
|
69
|
+
|[`Momocop/FactoryBotMissingClassOption`](lib/rubocop/cop/momocop/factory_bot_missing_class_option.rb)|:white_check_mark:|:white_check_mark:||
|
|
70
|
+
|[`Momocop/FactoryBotMissingProperties`](lib/rubocop/cop/momocop/factory_bot_missing_properties.rb)|:white_check_mark:|:white_check_mark:||
|
|
71
|
+
|[`Momocop/FactoryBotPropertyOrder`](lib/rubocop/cop/momocop/factory_bot_property_order.rb)|:white_check_mark:|:white_check_mark:||
|
|
72
|
+
|[`Momocop/FactoryBotSingleDefinePerFile`](lib/rubocop/cop/momocop/factory_bot_single_define_per_file.rb)|:white_check_mark:|:white_check_mark:||
|
|
73
|
+
|[`Momocop/FactoryBotSingleFactoryPerDefine`](lib/rubocop/cop/momocop/factory_bot_single_factory_per_define.rb)|:white_check_mark:|:white_check_mark:||
|
|
74
|
+
|[`Momocop/FactoryBotSingularFactoryName`](lib/rubocop/cop/momocop/factory_bot_singular_factory_name.rb)|:white_check_mark:|:white_check_mark:||
|
|
75
|
+
|[`Momocop/Layout/LeadingCommentSpace`](lib/rubocop/cop/momocop/layout/leading_comment_space.rb)||||
|
|
76
|
+
|[`Momocop/RbiMissingExtendTSig`](lib/rubocop/cop/momocop/rbi_missing_extend_t_sig.rb)||||
|
|
77
|
+
|[`Momocop/RspecContextWording`](lib/rubocop/cop/momocop/rspec_context_wording.rb)|||:white_check_mark:|
|
|
78
|
+
|[`Momocop/RspecDescribeWording`](lib/rubocop/cop/momocop/rspec_describe_wording.rb)|||:white_check_mark:|
|
|
79
|
+
|[`Momocop/RspecExampleWording`](lib/rubocop/cop/momocop/rspec_example_wording.rb)|||:white_check_mark:|
|
|
68
80
|
|
|
69
81
|
## 貢献
|
|
70
82
|
|
data/README.ja.md.erb
CHANGED
|
@@ -41,8 +41,8 @@ require:
|
|
|
41
41
|
|
|
42
42
|
## Cop一覧
|
|
43
43
|
|
|
44
|
-
|Cop|Rails|FactoryBot|
|
|
45
|
-
|
|
44
|
+
|Cop|Rails|FactoryBot|RSpec|
|
|
45
|
+
|---|:-:|:-:|:-:|
|
|
46
46
|
<%
|
|
47
47
|
files = Dir.glob('lib/rubocop/cop/momocop/**/*.rb').sort_by { |f| File.basename(f)}
|
|
48
48
|
files.each do |cop_file_path|
|
|
@@ -51,10 +51,12 @@ require:
|
|
|
51
51
|
cop_class_name = "#{namespace}/#{base_name.camelize}"
|
|
52
52
|
is_factory_cop = cop_file_path.include?('factory_bot_')
|
|
53
53
|
is_rails_cop = cop_file_path.match?(/(factory_bot_|rails_)/)
|
|
54
|
+
is_rspec_cop = cop_file_path.match?(/(rspec_)/)
|
|
54
55
|
rails_mark = is_rails_cop ? ':white_check_mark:' : ''
|
|
55
56
|
factory_bot_mark = is_factory_cop ? ':white_check_mark:' : ''
|
|
57
|
+
rspec_mark = is_rspec_cop ? ':white_check_mark:' : ''
|
|
56
58
|
|
|
57
|
-
table_row = "|[`#{cop_class_name}`](#{cop_file_path})|#{rails_mark}|#{factory_bot_mark}|"
|
|
59
|
+
table_row = "|[`#{cop_class_name}`](#{cop_file_path})|#{rails_mark}|#{factory_bot_mark}|#{rspec_mark}|"
|
|
58
60
|
-%>
|
|
59
61
|
<%= table_row %>
|
|
60
62
|
<% end -%>
|
data/README.md
CHANGED
|
@@ -48,23 +48,35 @@ Momocop/FactoryBotSingularFactoryName:
|
|
|
48
48
|
Enabled: true
|
|
49
49
|
Momocop/Layout/LeadingCommentSpace:
|
|
50
50
|
Enabled: true
|
|
51
|
+
Momocop/RbiMissingExtendTSig:
|
|
52
|
+
Enabled: true
|
|
53
|
+
Momocop/RspecContextWording:
|
|
54
|
+
Enabled: true
|
|
55
|
+
Momocop/RspecDescribeWording:
|
|
56
|
+
Enabled: true
|
|
57
|
+
Momocop/RspecExampleWording:
|
|
58
|
+
Enabled: true
|
|
51
59
|
```
|
|
52
60
|
|
|
53
61
|
## Cops
|
|
54
62
|
|
|
55
|
-
|Cop|Rails|FactoryBot|
|
|
56
|
-
|
|
57
|
-
|[`Momocop/FactoryBotClassExistence`](lib/rubocop/cop/momocop/factory_bot_class_existence.rb)|:white_check_mark:|:white_check_mark
|
|
58
|
-
|[`Momocop/FactoryBotConsistentFileName`](lib/rubocop/cop/momocop/factory_bot_consistent_file_name.rb)|:white_check_mark:|:white_check_mark
|
|
59
|
-
|[`Momocop/FactoryBotInlineAssociation`](lib/rubocop/cop/momocop/factory_bot_inline_association.rb)|:white_check_mark:|:white_check_mark
|
|
60
|
-
|[`Momocop/FactoryBotMissingAssociations`](lib/rubocop/cop/momocop/factory_bot_missing_associations.rb)|:white_check_mark:|:white_check_mark
|
|
61
|
-
|[`Momocop/FactoryBotMissingClassOption`](lib/rubocop/cop/momocop/factory_bot_missing_class_option.rb)|:white_check_mark:|:white_check_mark
|
|
62
|
-
|[`Momocop/FactoryBotMissingProperties`](lib/rubocop/cop/momocop/factory_bot_missing_properties.rb)|:white_check_mark:|:white_check_mark
|
|
63
|
-
|[`Momocop/FactoryBotPropertyOrder`](lib/rubocop/cop/momocop/factory_bot_property_order.rb)|:white_check_mark:|:white_check_mark
|
|
64
|
-
|[`Momocop/FactoryBotSingleDefinePerFile`](lib/rubocop/cop/momocop/factory_bot_single_define_per_file.rb)|:white_check_mark:|:white_check_mark
|
|
65
|
-
|[`Momocop/FactoryBotSingleFactoryPerDefine`](lib/rubocop/cop/momocop/factory_bot_single_factory_per_define.rb)|:white_check_mark:|:white_check_mark
|
|
66
|
-
|[`Momocop/FactoryBotSingularFactoryName`](lib/rubocop/cop/momocop/factory_bot_singular_factory_name.rb)|:white_check_mark:|:white_check_mark
|
|
67
|
-
|[`Momocop/Layout/LeadingCommentSpace`](lib/rubocop/cop/momocop/layout/leading_comment_space.rb)
|
|
63
|
+
|Cop|Rails|FactoryBot|RSpec|
|
|
64
|
+
|---|:-:|:-:|:-:|
|
|
65
|
+
|[`Momocop/FactoryBotClassExistence`](lib/rubocop/cop/momocop/factory_bot_class_existence.rb)|:white_check_mark:|:white_check_mark:||
|
|
66
|
+
|[`Momocop/FactoryBotConsistentFileName`](lib/rubocop/cop/momocop/factory_bot_consistent_file_name.rb)|:white_check_mark:|:white_check_mark:||
|
|
67
|
+
|[`Momocop/FactoryBotInlineAssociation`](lib/rubocop/cop/momocop/factory_bot_inline_association.rb)|:white_check_mark:|:white_check_mark:||
|
|
68
|
+
|[`Momocop/FactoryBotMissingAssociations`](lib/rubocop/cop/momocop/factory_bot_missing_associations.rb)|:white_check_mark:|:white_check_mark:||
|
|
69
|
+
|[`Momocop/FactoryBotMissingClassOption`](lib/rubocop/cop/momocop/factory_bot_missing_class_option.rb)|:white_check_mark:|:white_check_mark:||
|
|
70
|
+
|[`Momocop/FactoryBotMissingProperties`](lib/rubocop/cop/momocop/factory_bot_missing_properties.rb)|:white_check_mark:|:white_check_mark:||
|
|
71
|
+
|[`Momocop/FactoryBotPropertyOrder`](lib/rubocop/cop/momocop/factory_bot_property_order.rb)|:white_check_mark:|:white_check_mark:||
|
|
72
|
+
|[`Momocop/FactoryBotSingleDefinePerFile`](lib/rubocop/cop/momocop/factory_bot_single_define_per_file.rb)|:white_check_mark:|:white_check_mark:||
|
|
73
|
+
|[`Momocop/FactoryBotSingleFactoryPerDefine`](lib/rubocop/cop/momocop/factory_bot_single_factory_per_define.rb)|:white_check_mark:|:white_check_mark:||
|
|
74
|
+
|[`Momocop/FactoryBotSingularFactoryName`](lib/rubocop/cop/momocop/factory_bot_singular_factory_name.rb)|:white_check_mark:|:white_check_mark:||
|
|
75
|
+
|[`Momocop/Layout/LeadingCommentSpace`](lib/rubocop/cop/momocop/layout/leading_comment_space.rb)||||
|
|
76
|
+
|[`Momocop/RbiMissingExtendTSig`](lib/rubocop/cop/momocop/rbi_missing_extend_t_sig.rb)||||
|
|
77
|
+
|[`Momocop/RspecContextWording`](lib/rubocop/cop/momocop/rspec_context_wording.rb)|||:white_check_mark:|
|
|
78
|
+
|[`Momocop/RspecDescribeWording`](lib/rubocop/cop/momocop/rspec_describe_wording.rb)|||:white_check_mark:|
|
|
79
|
+
|[`Momocop/RspecExampleWording`](lib/rubocop/cop/momocop/rspec_example_wording.rb)|||:white_check_mark:|
|
|
68
80
|
|
|
69
81
|
## Contributing
|
|
70
82
|
|
data/README.md.erb
CHANGED
|
@@ -41,8 +41,8 @@ require:
|
|
|
41
41
|
|
|
42
42
|
## Cops
|
|
43
43
|
|
|
44
|
-
|Cop|Rails|FactoryBot|
|
|
45
|
-
|
|
44
|
+
|Cop|Rails|FactoryBot|RSpec|
|
|
45
|
+
|---|:-:|:-:|:-:|
|
|
46
46
|
<%
|
|
47
47
|
files = Dir.glob('lib/rubocop/cop/momocop/**/*.rb').sort_by { |f| File.basename(f)}
|
|
48
48
|
files.each do |cop_file_path|
|
|
@@ -51,10 +51,12 @@ require:
|
|
|
51
51
|
cop_class_name = "#{namespace}/#{base_name.camelize}"
|
|
52
52
|
is_factory_cop = cop_file_path.include?('factory_bot_')
|
|
53
53
|
is_rails_cop = cop_file_path.match?(/(factory_bot_|rails_)/)
|
|
54
|
+
is_rspec_cop = cop_file_path.match?(/(rspec_)/)
|
|
54
55
|
rails_mark = is_rails_cop ? ':white_check_mark:' : ''
|
|
55
56
|
factory_bot_mark = is_factory_cop ? ':white_check_mark:' : ''
|
|
57
|
+
rspec_mark = is_rspec_cop ? ':white_check_mark:' : ''
|
|
56
58
|
|
|
57
|
-
table_row = "|[`#{cop_class_name}`](#{cop_file_path})|#{rails_mark}|#{factory_bot_mark}|"
|
|
59
|
+
table_row = "|[`#{cop_class_name}`](#{cop_file_path})|#{rails_mark}|#{factory_bot_mark}|#{rspec_mark}|"
|
|
58
60
|
-%>
|
|
59
61
|
<%= table_row %>
|
|
60
62
|
<% end -%>
|
data/config/default.yml
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Momocop/RSpecDescribeWording:
|
|
2
|
+
Description: 'Ensures that RSpec describe text matches the configured pattern'
|
|
3
|
+
Enabled: true
|
|
4
|
+
RequiredPattern: '^(?!When ).+'
|
|
5
|
+
|
|
6
|
+
Momocop/RSpecContextWording:
|
|
7
|
+
Description: 'Ensures that RSpec context text starts with When or If'
|
|
8
|
+
Enabled: true
|
|
9
|
+
RequiredPattern: '^(When|If) .+'
|
|
10
|
+
|
|
11
|
+
Momocop/RSpecItWording:
|
|
12
|
+
Description: 'Ensures that RSpec it block text matches the configured pattern'
|
|
13
|
+
Enabled: true
|
|
14
|
+
RequiredPattern: '^(should|will) .+$'
|
|
@@ -75,7 +75,7 @@ module Momocop
|
|
|
75
75
|
|
|
76
76
|
# begin
|
|
77
77
|
if body_node.begin_type?
|
|
78
|
-
body_node&.children&.select { |
|
|
78
|
+
body_node&.children&.select { |child_node| definition_node?(child_node) } || []
|
|
79
79
|
# block
|
|
80
80
|
elsif body_node.send_type? && definition_node?(body_node)
|
|
81
81
|
[body_node]
|
data/lib/momocop/version.rb
CHANGED
|
@@ -65,12 +65,18 @@ module RuboCop
|
|
|
65
65
|
|
|
66
66
|
# Returns all top-level factories within a FactoryBot.define block.
|
|
67
67
|
private def top_level_factories(node)
|
|
68
|
+
block = node.block_node
|
|
69
|
+
return [] unless block
|
|
70
|
+
|
|
71
|
+
body = block.body
|
|
72
|
+
return [] unless body
|
|
73
|
+
|
|
68
74
|
factory_nodes =
|
|
69
|
-
|
|
70
|
-
.
|
|
71
|
-
.body.each_descendant(:send)
|
|
75
|
+
body
|
|
76
|
+
.each_descendant(:send)
|
|
72
77
|
.select { |n| n.method_name == :factory }
|
|
73
|
-
|
|
78
|
+
|
|
79
|
+
factory_nodes.select do |factory_node|
|
|
74
80
|
base_node = factory_node.block_node || factory_node
|
|
75
81
|
context =
|
|
76
82
|
base_node
|
|
@@ -78,7 +84,7 @@ module RuboCop
|
|
|
78
84
|
.map { _1.send_node&.method_name&.to_sym }
|
|
79
85
|
.find { %i[define factory].include? _1 }
|
|
80
86
|
context == :define
|
|
81
|
-
|
|
87
|
+
end
|
|
82
88
|
end
|
|
83
89
|
end
|
|
84
90
|
end
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Momocop
|
|
6
|
+
# Ensures that Sorbet signature declarations are accompanied by `extend T::Sig`.
|
|
7
|
+
#
|
|
8
|
+
# sig calls must be block-form invocations that appear immediately above a
|
|
9
|
+
# method definition to be considered.
|
|
10
|
+
#
|
|
11
|
+
# @example
|
|
12
|
+
# # bad
|
|
13
|
+
# class User
|
|
14
|
+
# sig { void }
|
|
15
|
+
# def call; end
|
|
16
|
+
# end
|
|
17
|
+
#
|
|
18
|
+
# # good
|
|
19
|
+
# class User
|
|
20
|
+
# extend T::Sig
|
|
21
|
+
#
|
|
22
|
+
# sig { void }
|
|
23
|
+
# def call; end
|
|
24
|
+
# end
|
|
25
|
+
class RbiMissingExtendTSig < RuboCop::Cop::Base
|
|
26
|
+
extend AutoCorrector
|
|
27
|
+
include RangeHelp
|
|
28
|
+
|
|
29
|
+
MSG = 'Add `extend T::Sig` when using `sig` to type methods.'
|
|
30
|
+
|
|
31
|
+
def_node_matcher :extend_t_sig_call?, <<~PATTERN
|
|
32
|
+
(send nil? :extend <(const (const nil? :T) :Sig) ...>)
|
|
33
|
+
PATTERN
|
|
34
|
+
|
|
35
|
+
def_node_matcher :sig_block_call?, <<~PATTERN
|
|
36
|
+
(block (send nil? :sig ...) ...)
|
|
37
|
+
PATTERN
|
|
38
|
+
|
|
39
|
+
def on_class(node)
|
|
40
|
+
check_node(node, body_nodes(node), node.loc.keyword)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def on_module(node)
|
|
44
|
+
check_node(node, body_nodes(node), node.loc.keyword)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def on_new_investigation
|
|
48
|
+
return unless processed_source.ast
|
|
49
|
+
|
|
50
|
+
top_level_nodes = top_level_body_nodes(processed_source.ast)
|
|
51
|
+
check_node(nil, top_level_nodes, top_level_offense_location(top_level_nodes))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private def check_node(node, nodes, offense_location)
|
|
55
|
+
sig_node = sig_before_method_definition(nodes)
|
|
56
|
+
return unless sig_node
|
|
57
|
+
return if extend_t_sig?(nodes)
|
|
58
|
+
|
|
59
|
+
add_offense(offense_location || sig_location(sig_node)) do |corrector|
|
|
60
|
+
autocorrect(corrector, nodes)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private def sig_before_method_definition(nodes)
|
|
65
|
+
nodes.each_cons(2) do |previous, current|
|
|
66
|
+
next unless sig_block_call?(previous)
|
|
67
|
+
next unless method_definition?(current)
|
|
68
|
+
next unless consecutive_lines?(previous, current)
|
|
69
|
+
|
|
70
|
+
return previous
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
nil
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private def extend_t_sig?(nodes)
|
|
77
|
+
nodes.any? do |child|
|
|
78
|
+
extend_t_sig_call?(child)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
private def body_nodes(node)
|
|
83
|
+
body = node.body
|
|
84
|
+
return [] unless body
|
|
85
|
+
|
|
86
|
+
if body.begin_type?
|
|
87
|
+
body.children
|
|
88
|
+
else
|
|
89
|
+
[body]
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
private def top_level_body_nodes(ast)
|
|
94
|
+
return [] unless ast
|
|
95
|
+
|
|
96
|
+
if ast.begin_type?
|
|
97
|
+
ast.children
|
|
98
|
+
else
|
|
99
|
+
[ast]
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
private def top_level_offense_location(_nodes)
|
|
104
|
+
nil
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
private def method_definition?(node)
|
|
108
|
+
node.def_type? || node.defs_type?
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
private def consecutive_lines?(first_node, second_node)
|
|
112
|
+
first_node.loc.last_line + 1 == second_node.loc.line
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
private def sig_location(sig_node)
|
|
116
|
+
sig_node.send_node&.loc&.selector || sig_node.loc.expression
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
private def autocorrect(corrector, nodes)
|
|
120
|
+
first_child = nodes.first
|
|
121
|
+
return unless first_child
|
|
122
|
+
|
|
123
|
+
indentation = indentation_for(first_child)
|
|
124
|
+
insert_before_line_start(corrector, first_child, "#{indentation}extend T::Sig\n")
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
private def insert_before_line_start(corrector, node, text)
|
|
128
|
+
line_start = node.source_range.begin_pos - node.loc.column
|
|
129
|
+
insertion_range = range_between(line_start, line_start)
|
|
130
|
+
corrector.insert_before(insertion_range, text)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
private def indentation_for(first_child)
|
|
134
|
+
' ' * first_child.loc.column
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Momocop
|
|
6
|
+
class RSpecContextWording < Base
|
|
7
|
+
extend AutoCorrector
|
|
8
|
+
include RangeHelp
|
|
9
|
+
|
|
10
|
+
MSG = 'RSpec context text must match pattern: %<pattern>s'
|
|
11
|
+
|
|
12
|
+
def_node_matcher :context_block?, <<~PATTERN
|
|
13
|
+
(send nil? :context ...)
|
|
14
|
+
PATTERN
|
|
15
|
+
|
|
16
|
+
def on_send(node)
|
|
17
|
+
return unless context_block?(node)
|
|
18
|
+
|
|
19
|
+
arg = node.first_argument
|
|
20
|
+
return unless arg&.str_type?
|
|
21
|
+
|
|
22
|
+
text = arg.value.to_s
|
|
23
|
+
pattern = cop_config['RequiredPattern']
|
|
24
|
+
return if text.match?(Regexp.new(pattern))
|
|
25
|
+
|
|
26
|
+
add_offense(
|
|
27
|
+
node.first_argument.source_range,
|
|
28
|
+
message: format(MSG, pattern:)
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Momocop
|
|
6
|
+
class RSpecDescribeWording < Base
|
|
7
|
+
extend AutoCorrector
|
|
8
|
+
include RangeHelp
|
|
9
|
+
|
|
10
|
+
MSG = 'RSpec describe text must match pattern: %<pattern>s'
|
|
11
|
+
|
|
12
|
+
def_node_matcher :describe_block?, <<~PATTERN
|
|
13
|
+
(send nil? :describe ...)
|
|
14
|
+
PATTERN
|
|
15
|
+
|
|
16
|
+
def on_send(node)
|
|
17
|
+
return unless describe_block?(node)
|
|
18
|
+
|
|
19
|
+
arg = node.first_argument
|
|
20
|
+
return unless arg&.str_type?
|
|
21
|
+
|
|
22
|
+
text = arg.value.to_s
|
|
23
|
+
pattern = cop_config['RequiredPattern']
|
|
24
|
+
return if text.match?(Regexp.new(pattern))
|
|
25
|
+
|
|
26
|
+
add_offense(
|
|
27
|
+
node.first_argument.loc.expression,
|
|
28
|
+
message: format(MSG, pattern:)
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Momocop
|
|
6
|
+
class RSpecExampleWording < Base
|
|
7
|
+
extend AutoCorrector
|
|
8
|
+
include RangeHelp
|
|
9
|
+
|
|
10
|
+
MSG = 'RSpec it block text must match pattern: %<pattern>s'
|
|
11
|
+
|
|
12
|
+
def_node_matcher :it_block?, <<~PATTERN
|
|
13
|
+
(send nil? :it ...)
|
|
14
|
+
PATTERN
|
|
15
|
+
|
|
16
|
+
def on_send(node)
|
|
17
|
+
return unless it_block?(node)
|
|
18
|
+
|
|
19
|
+
arg = node.first_argument
|
|
20
|
+
return unless arg&.str_type?
|
|
21
|
+
|
|
22
|
+
text = arg.value.to_s
|
|
23
|
+
pattern = cop_config['RequiredPattern']
|
|
24
|
+
return if text.match?(Regexp.new(pattern))
|
|
25
|
+
|
|
26
|
+
add_offense(
|
|
27
|
+
node.first_argument.loc.expression,
|
|
28
|
+
message: format(MSG, pattern:)
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: momocop
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- supermomonga
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-11-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -104,6 +104,10 @@ files:
|
|
|
104
104
|
- lib/rubocop/cop/momocop/factory_bot_single_factory_per_define.rb
|
|
105
105
|
- lib/rubocop/cop/momocop/factory_bot_singular_factory_name.rb
|
|
106
106
|
- lib/rubocop/cop/momocop/layout/leading_comment_space.rb
|
|
107
|
+
- lib/rubocop/cop/momocop/rbi_missing_extend_t_sig.rb
|
|
108
|
+
- lib/rubocop/cop/momocop/rspec_context_wording.rb
|
|
109
|
+
- lib/rubocop/cop/momocop/rspec_describe_wording.rb
|
|
110
|
+
- lib/rubocop/cop/momocop/rspec_example_wording.rb
|
|
107
111
|
- sig/momocop.rbs
|
|
108
112
|
homepage: https://github.com/supermomonga/momocop
|
|
109
113
|
licenses:
|
|
@@ -112,7 +116,7 @@ metadata:
|
|
|
112
116
|
homepage_uri: https://github.com/supermomonga/momocop
|
|
113
117
|
source_code_uri: https://github.com/supermomonga/momocop
|
|
114
118
|
changelog_uri: https://github.com/supermomonga/momocop/releases
|
|
115
|
-
post_install_message:
|
|
119
|
+
post_install_message:
|
|
116
120
|
rdoc_options: []
|
|
117
121
|
require_paths:
|
|
118
122
|
- lib
|
|
@@ -127,8 +131,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
127
131
|
- !ruby/object:Gem::Version
|
|
128
132
|
version: '0'
|
|
129
133
|
requirements: []
|
|
130
|
-
rubygems_version: 3.
|
|
131
|
-
signing_key:
|
|
134
|
+
rubygems_version: 3.4.19
|
|
135
|
+
signing_key:
|
|
132
136
|
specification_version: 4
|
|
133
137
|
summary: Convention focused opinionated custom cops for RuboCop.
|
|
134
138
|
test_files: []
|