momocop 0.2.0 → 0.3.0
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 +9 -0
- data/README.md +9 -0
- 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_define_per_file.rb +2 -0
- data/lib/rubocop/cop/momocop/rspec_context_text_pattern.rb +34 -0
- data/lib/rubocop/cop/momocop/rspec_describe_text_pattern.rb +34 -0
- data/lib/rubocop/cop/momocop/rspec_it_text_pattern.rb +34 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47c9203f322466a1799ecd615eace3f9c0112d959b560211bfc7b1e433d6697b
|
4
|
+
data.tar.gz: 1d63e00519322bf145ad906d40893cbab601dcdc447cd2ae4e7f3910da46e4ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ada13b67eda1015615e5ee8725580a595f20125458ff68d35f9a6b9929e6391c6ee7baad478671cd4885dbf31a6f59e529d00b400dd36deabf9d99eb4b9a36a9
|
7
|
+
data.tar.gz: 42dfc6d561aa4e6d80c468e6c3eb3da490a1843b8d5f1b78b992359d7f30279c780190bcc32a5034815d82fb301d88230f05547650587449823b980a44cbc0e3
|
data/README.ja.md
CHANGED
@@ -48,6 +48,12 @@ Momocop/FactoryBotSingularFactoryName:
|
|
48
48
|
Enabled: true
|
49
49
|
Momocop/Layout/LeadingCommentSpace:
|
50
50
|
Enabled: true
|
51
|
+
Momocop/RspecContextTextPattern:
|
52
|
+
Enabled: true
|
53
|
+
Momocop/RspecDescribeTextPattern:
|
54
|
+
Enabled: true
|
55
|
+
Momocop/RspecItTextPattern:
|
56
|
+
Enabled: true
|
51
57
|
```
|
52
58
|
|
53
59
|
## Cop一覧
|
@@ -65,6 +71,9 @@ Momocop/Layout/LeadingCommentSpace:
|
|
65
71
|
|[`Momocop/FactoryBotSingleFactoryPerDefine`](lib/rubocop/cop/momocop/factory_bot_single_factory_per_define.rb)|:white_check_mark:|:white_check_mark:|
|
66
72
|
|[`Momocop/FactoryBotSingularFactoryName`](lib/rubocop/cop/momocop/factory_bot_singular_factory_name.rb)|:white_check_mark:|:white_check_mark:|
|
67
73
|
|[`Momocop/Layout/LeadingCommentSpace`](lib/rubocop/cop/momocop/layout/leading_comment_space.rb)|||
|
74
|
+
|[`Momocop/RspecContextTextPattern`](lib/rubocop/cop/momocop/rspec_context_text_pattern.rb)|||
|
75
|
+
|[`Momocop/RspecDescribeTextPattern`](lib/rubocop/cop/momocop/rspec_describe_text_pattern.rb)|||
|
76
|
+
|[`Momocop/RspecItTextPattern`](lib/rubocop/cop/momocop/rspec_it_text_pattern.rb)|||
|
68
77
|
|
69
78
|
## 貢献
|
70
79
|
|
data/README.md
CHANGED
@@ -48,6 +48,12 @@ Momocop/FactoryBotSingularFactoryName:
|
|
48
48
|
Enabled: true
|
49
49
|
Momocop/Layout/LeadingCommentSpace:
|
50
50
|
Enabled: true
|
51
|
+
Momocop/RspecContextTextPattern:
|
52
|
+
Enabled: true
|
53
|
+
Momocop/RspecDescribeTextPattern:
|
54
|
+
Enabled: true
|
55
|
+
Momocop/RspecItTextPattern:
|
56
|
+
Enabled: true
|
51
57
|
```
|
52
58
|
|
53
59
|
## Cops
|
@@ -65,6 +71,9 @@ Momocop/Layout/LeadingCommentSpace:
|
|
65
71
|
|[`Momocop/FactoryBotSingleFactoryPerDefine`](lib/rubocop/cop/momocop/factory_bot_single_factory_per_define.rb)|:white_check_mark:|:white_check_mark:|
|
66
72
|
|[`Momocop/FactoryBotSingularFactoryName`](lib/rubocop/cop/momocop/factory_bot_singular_factory_name.rb)|:white_check_mark:|:white_check_mark:|
|
67
73
|
|[`Momocop/Layout/LeadingCommentSpace`](lib/rubocop/cop/momocop/layout/leading_comment_space.rb)|||
|
74
|
+
|[`Momocop/RspecContextTextPattern`](lib/rubocop/cop/momocop/rspec_context_text_pattern.rb)|||
|
75
|
+
|[`Momocop/RspecDescribeTextPattern`](lib/rubocop/cop/momocop/rspec_describe_text_pattern.rb)|||
|
76
|
+
|[`Momocop/RspecItTextPattern`](lib/rubocop/cop/momocop/rspec_it_text_pattern.rb)|||
|
68
77
|
|
69
78
|
## Contributing
|
70
79
|
|
data/config/default.yml
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
Momocop/RSpecDescribeTextPattern:
|
2
|
+
Description: 'Ensures that RSpec describe text matches the configured pattern'
|
3
|
+
Enabled: true
|
4
|
+
RequiredPattern: '^(?!When ).+'
|
5
|
+
|
6
|
+
Momocop/RSpecContextTextPattern:
|
7
|
+
Description: 'Ensures that RSpec context text starts with When or If'
|
8
|
+
Enabled: true
|
9
|
+
RequiredPattern: '^(When|If) .+'
|
10
|
+
|
11
|
+
Momocop/RSpecItTextPattern:
|
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
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Momocop
|
6
|
+
class RSpecContextTextPattern < 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 RSpecDescribeTextPattern < 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 RSpecItTextPattern < 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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- supermomonga
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -104,6 +104,9 @@ 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/rspec_context_text_pattern.rb
|
108
|
+
- lib/rubocop/cop/momocop/rspec_describe_text_pattern.rb
|
109
|
+
- lib/rubocop/cop/momocop/rspec_it_text_pattern.rb
|
107
110
|
- sig/momocop.rbs
|
108
111
|
homepage: https://github.com/supermomonga/momocop
|
109
112
|
licenses:
|