rubocop-rspec_enforce_description 0.1.0 → 0.2.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.md +29 -24
- data/lib/rubocop/cop/rspec/enforce_description.rb +17 -22
- data/lib/rubocop/rspec_enforce_description/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfcbb5a9b7f1801390f8a8910a7dec92bf7e3cc454fe4cc9218ffb8dc2a89141
|
4
|
+
data.tar.gz: e86b98c1b0c6454c0555a249907598d7bc3d838505e7aa801449acc86c5b42d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04d59e451c73ea5750e6f290bc34f5a6b0b15c89cf3b490064e363f913f87474d701ed2c1b52b34a13413855957fa7cb0e89341dace3931b9e2f824076abfa80
|
7
|
+
data.tar.gz: a6fe75c7c841d0a9accd471b86fab6220d6aa80f5b7cfd5ca05a18c9c83d6af5e6c9e0f183425efb909cc4bb7bc68ace4f006348e7eb8d9ea6d935ee8dfe5063
|
data/README.md
CHANGED
@@ -1,35 +1,40 @@
|
|
1
|
-
#
|
1
|
+
# rubocop-rspec_enforce_description
|
2
2
|
|
3
|
-
|
3
|
+
RSpecの各ブロックの説明文のルールを提供する[RuboCop](https://github.com/rubocop/rubocop)用のGemです。
|
4
|
+
テスト記述の統一や可読性向上に役立ちます。
|
4
5
|
|
5
|
-
|
6
|
+
# インストール
|
6
7
|
|
7
|
-
|
8
|
+
```sh
|
9
|
+
bundle add rubocop-rspec_enforce_description
|
10
|
+
```
|
8
11
|
|
9
|
-
|
12
|
+
.rubocop.ymlへの設定例
|
10
13
|
|
11
|
-
|
14
|
+
```yaml
|
15
|
+
require:
|
16
|
+
- rubocop/rspec_enforce_description
|
12
17
|
|
13
|
-
|
18
|
+
RSpec/EnforceDescription:
|
19
|
+
Enabled: true
|
20
|
+
```
|
14
21
|
|
15
|
-
|
22
|
+
# ルール
|
16
23
|
|
17
|
-
|
24
|
+
## contectの説明文の最後が「場合」になっていること
|
18
25
|
|
19
|
-
|
26
|
+
```ruby
|
27
|
+
context 'ログインしているとき' do
|
28
|
+
# ...
|
29
|
+
end
|
30
|
+
# ↑ 警告: Context description should end with [場合].
|
31
|
+
```
|
20
32
|
|
21
|
-
|
33
|
+
## itの説明文の最後が「こと」になっていること
|
22
34
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
## Contributing
|
30
|
-
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rubocop-rspec_enforce_description.
|
32
|
-
|
33
|
-
## License
|
34
|
-
|
35
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
35
|
+
```ruby
|
36
|
+
it '大文字になります' do
|
37
|
+
# ...
|
38
|
+
end
|
39
|
+
# ↑ 警告: It description should end with [こと].
|
40
|
+
```
|
@@ -2,38 +2,33 @@ module RuboCop
|
|
2
2
|
module Cop
|
3
3
|
module RSpec
|
4
4
|
class EnforceDescription < Base
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
RESTRICT_ON_SEND = %i(context).freeze
|
9
|
-
|
10
|
-
# `context`メソッド呼び出しとその説明を抽出するためのノードマッチャーを定義します。
|
11
|
-
# `(send nil? :context (str $_) ...)` は、
|
12
|
-
# レシーバなしで`:context`メソッドが呼び出され、
|
13
|
-
# その最初の引数が文字列リテラルであるパターンにマッチします。
|
14
|
-
# `$_` はその文字列リテラルの値をキャプチャします。
|
5
|
+
MSG_CONTEXT = "Context description should end with [場合].".freeze
|
6
|
+
MSG_IT = "Example description should end with [こと].".freeze
|
7
|
+
|
8
|
+
RESTRICT_ON_SEND = %i(context it).freeze
|
9
|
+
|
15
10
|
def_node_matcher :context_with_description?, <<~PATTERN
|
16
11
|
(send nil? :context (str $_) ...)
|
17
12
|
PATTERN
|
18
13
|
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
def_node_matcher :it_with_description?, <<~PATTERN
|
15
|
+
(send nil? :it (str $_) ...)
|
16
|
+
PATTERN
|
17
|
+
|
22
18
|
def on_send(node)
|
23
|
-
# `context_with_description?`マッチャーを使用して、ノードが`context`ブロックであり、
|
24
|
-
# その説明を抽出できるかを確認します。
|
25
19
|
context_with_description?(node) do |description|
|
26
|
-
# 説明が「場合」で終わっている場合は、違反ではないため処理を終了します。
|
27
20
|
return if description.end_with?("場合")
|
28
21
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
add_offense(node.first_argument.loc.expression, message: MSG_CONTEXT)
|
23
|
+
end
|
24
|
+
|
25
|
+
it_with_description?(node) do |description|
|
26
|
+
return if description.end_with?("こと")
|
27
|
+
|
28
|
+
add_offense(node.first_argument.loc.expression, message: MSG_IT)
|
33
29
|
end
|
34
30
|
end
|
35
|
-
|
36
|
-
# `on_send`と同じロジックを適用します。
|
31
|
+
|
37
32
|
alias on_csend on_send
|
38
33
|
end
|
39
34
|
end
|