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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbc69dbb07ae8301f42c5557d118a425db2515a45e7a936e1a888cf3198b3af7
4
- data.tar.gz: caccd680fe6a7627cf5c36e9c3f1ef8b33d1bfcba3dd5fea816451a199f6cd3f
3
+ metadata.gz: cfcbb5a9b7f1801390f8a8910a7dec92bf7e3cc454fe4cc9218ffb8dc2a89141
4
+ data.tar.gz: e86b98c1b0c6454c0555a249907598d7bc3d838505e7aa801449acc86c5b42d1
5
5
  SHA512:
6
- metadata.gz: d2a0660e8de73f327c9b54489dad658cc7491559a188f967b9b8685ad47248d45dc88acdb559547d9ef4d7a8c9533c2d9ee1afcc7964cb8bd45d16614e463c57
7
- data.tar.gz: 468975150ed369b476f250b10a5d1a522ec5d9cb1fb3223465bad57ea75926c7f36226941f3cff05af2d573d41cf54510dda3a41b11878291ae1e722c961d78c
6
+ metadata.gz: 04d59e451c73ea5750e6f290bc34f5a6b0b15c89cf3b490064e363f913f87474d701ed2c1b52b34a13413855957fa7cb0e89341dace3931b9e2f824076abfa80
7
+ data.tar.gz: a6fe75c7c841d0a9accd471b86fab6220d6aa80f5b7cfd5ca05a18c9c83d6af5e6c9e0f183425efb909cc4bb7bc68ace4f006348e7eb8d9ea6d935ee8dfe5063
data/README.md CHANGED
@@ -1,35 +1,40 @@
1
- # RuboCop::RspecEnforceDescription
1
+ # rubocop-rspec_enforce_description
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ RSpecの各ブロックの説明文のルールを提供する[RuboCop](https://github.com/rubocop/rubocop)用のGemです。
4
+ テスト記述の統一や可読性向上に役立ちます。
4
5
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rubocop/rspec_enforce_description`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+ # インストール
6
7
 
7
- ## Installation
8
+ ```sh
9
+ bundle add rubocop-rspec_enforce_description
10
+ ```
8
11
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
12
+ .rubocop.ymlへの設定例
10
13
 
11
- Install the gem and add to the application's Gemfile by executing:
14
+ ```yaml
15
+ require:
16
+ - rubocop/rspec_enforce_description
12
17
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG --require=false
18
+ RSpec/EnforceDescription:
19
+ Enabled: true
20
+ ```
14
21
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
22
+ # ルール
16
23
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
24
+ ## contectの説明文の最後が「場合」になっていること
18
25
 
19
- ## Usage
26
+ ```ruby
27
+ context 'ログインしているとき' do
28
+ # ...
29
+ end
30
+ # ↑ 警告: Context description should end with [場合].
31
+ ```
20
32
 
21
- TODO: Write usage instructions here
33
+ ## itの説明文の最後が「こと」になっていること
22
34
 
23
- ## Development
24
-
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
-
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
- MSG = "Context description should end with [場合].".freeze
6
- # `on_send`メソッドが呼び出されるノードの種類を制限します。
7
- # ここでは`:context`メソッドの呼び出しに限定しています。
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
- # `send`ノード(メソッド呼び出し)が検出されたときに呼び出されます。
20
- # このコップは`RESTRICT_ON_SEND`で`:context`に制限されているため、
21
- # `context`メソッドの呼び出しに対してのみ実行されます。
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
- # `node.first_argument.loc.expression`は、`context`メソッドの最初の引数(説明文字列)の
31
- # ソースコード上の位置を指します。
32
- add_offense(node.first_argument.loc.expression, message: MSG)
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
- # `csend`ノード(条件付きメソッド呼び出し、例: `obj&.method`)に対しても
36
- # `on_send`と同じロジックを適用します。
31
+
37
32
  alias on_csend on_send
38
33
  end
39
34
  end
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module RspecEnforceDescription
3
- VERSION = "0.1.0".freeze
3
+ VERSION = "0.2.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rspec_enforce_description
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thr3a