rubocop-rspec_enforce_description 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dbc69dbb07ae8301f42c5557d118a425db2515a45e7a936e1a888cf3198b3af7
4
+ data.tar.gz: caccd680fe6a7627cf5c36e9c3f1ef8b33d1bfcba3dd5fea816451a199f6cd3f
5
+ SHA512:
6
+ metadata.gz: d2a0660e8de73f327c9b54489dad658cc7491559a188f967b9b8685ad47248d45dc88acdb559547d9ef4d7a8c9533c2d9ee1afcc7964cb8bd45d16614e463c57
7
+ data.tar.gz: 468975150ed369b476f250b10a5d1a522ec5d9cb1fb3223465bad57ea75926c7f36226941f3cff05af2d573d41cf54510dda3a41b11878291ae1e722c961d78c
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,145 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ DisplayCopNames: true
4
+ SuggestExtensions: false
5
+
6
+ # 日本語のコメントを許可する
7
+ Style/AsciiComments:
8
+ Enabled: false
9
+
10
+ # self.xx を許可
11
+ Style/RedundantSelf:
12
+ Enabled: false
13
+
14
+ # ダブルクォーテーション
15
+ Style/StringLiterals:
16
+ EnforcedStyle: double_quotes
17
+
18
+ # 行数チェックは無効化
19
+ Layout/LineLength:
20
+ Enabled: false
21
+
22
+ # トップレベルのクラスのドキュメントコメントがありませんを無効化
23
+ Style/Documentation:
24
+ Enabled: false
25
+
26
+ # %w()とかで統一する
27
+ Style/PercentLiteralDelimiters:
28
+ PreferredDelimiters:
29
+ "%": ()
30
+ "%i": ()
31
+ "%q": ()
32
+ "%Q": ()
33
+ "%r": ()
34
+ "%s": ()
35
+ "%w": ()
36
+ "%W": ()
37
+ "%x": ()
38
+
39
+ # ifかunlessかは場合によって選びたい
40
+ Style/IfUnlessModifier:
41
+ Enabled: false
42
+
43
+ # if!とunlessは別物
44
+ Style/NegatedIf:
45
+ Enabled: false
46
+
47
+ # rakeタスクとかで困る
48
+ Lint/UnusedBlockArgument:
49
+ Enabled: false
50
+
51
+ # https://qiita.com/rorensu2236/items/d0d685307b75bdaf179f
52
+ Style/HashEachMethods:
53
+ Enabled: true
54
+ Style/HashTransformKeys:
55
+ Enabled: true
56
+ Style/HashTransformValues:
57
+ Enabled: true
58
+
59
+ # メトリクス系は一旦全無視で
60
+ Metrics/AbcSize:
61
+ Enabled: false
62
+ Metrics/BlockLength:
63
+ Enabled: false
64
+ Metrics/BlockNesting:
65
+ Enabled: false
66
+ Metrics/ClassLength:
67
+ Enabled: false
68
+ Metrics/CyclomaticComplexity:
69
+ Enabled: false
70
+ Metrics/MethodLength:
71
+ Enabled: false
72
+ Metrics/ModuleLength:
73
+ Enabled: false
74
+ Metrics/ParameterLists:
75
+ Enabled: false
76
+ Metrics/PerceivedComplexity:
77
+ Enabled: false
78
+
79
+ # frozen_string_literal記述不可
80
+ Style/FrozenStringLiteralComment:
81
+ EnforcedStyle: never
82
+
83
+ # 空メソッドも複数行で書くべき
84
+ Style/EmptyMethod:
85
+ EnforcedStyle: expanded
86
+
87
+ # あとで考える
88
+ Style/GuardClause:
89
+ Enabled: false
90
+
91
+ # n > 0 使いたい
92
+ Style/NumericPredicate:
93
+ Enabled: false
94
+
95
+ # 7桁以上なら数字に_必須
96
+ Style/NumericLiterals:
97
+ Enabled: false
98
+
99
+ # rescue => e で書きたい
100
+ Style/RescueStandardError:
101
+ EnforcedStyle: implicit
102
+
103
+ # === 使いたい
104
+ Style/CaseEquality:
105
+ Enabled: false
106
+
107
+ # 大量引数は避けるべきだがしゃーないときもある
108
+ Naming/MethodParameterName:
109
+ Enabled: false
110
+
111
+ # rescue nilを1行で書きたい
112
+ Style/RescueModifier:
113
+ Enabled: false
114
+
115
+ # do endブロックをいい感じに
116
+ Layout/BlockAlignment:
117
+ EnforcedStyleAlignWith: start_of_block
118
+
119
+ # 複数行ハッシュで無駄なスペース作らないように
120
+ Layout/FirstArrayElementIndentation:
121
+ EnforcedStyle: consistent
122
+ Layout/FirstHashElementIndentation:
123
+ EnforcedStyle: consistent
124
+
125
+ Layout/MultilineMethodCallIndentation:
126
+ EnforcedStyle: indented_relative_to_receiver
127
+
128
+ # Lambdaは ->(x) { x } で書く
129
+ Style/Lambda:
130
+ EnforcedStyle: literal
131
+
132
+ # 三項演算子のカッコ統一
133
+ Style/TernaryParentheses:
134
+ EnforcedStyle: require_parentheses_when_complex
135
+
136
+ # 三項演算子の場合もスタイルを統一しようとするので無効化
137
+ Style/ConditionalAssignment:
138
+ Enabled: false
139
+
140
+ # 最初のパラメータに位置を合わせるではなくメソッド呼び出しの行から1段階インデント
141
+ Layout/ArgumentAlignment:
142
+ EnforcedStyle: with_fixed_indentation
143
+
144
+ Naming/FileName:
145
+ Enabled: false
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 thr3a
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # RuboCop::RspecEnforceDescription
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
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
+
7
+ ## Installation
8
+
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.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG --require=false
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
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).
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require "rubocop/rake_task"
7
+
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: %i(spec rubocop)
11
+
12
+ RSpec::Core::RakeTask.new(:spec) do |spec|
13
+ spec.pattern = FileList["spec/**/*_spec.rb"]
14
+ end
15
+
16
+ desc "Generate a new cop with a template"
17
+ task :new_cop, [:cop] do |_task, args|
18
+ require "rubocop"
19
+
20
+ cop_name = args.fetch(:cop) do
21
+ warn "usage: bundle exec rake new_cop[Department/Name]"
22
+ exit!
23
+ end
24
+
25
+ generator = RuboCop::Cop::Generator.new(cop_name)
26
+
27
+ generator.write_source
28
+ generator.write_spec
29
+ generator.inject_require(root_file_path: "lib/rubocop/cop/rspec_enforce_description_cops.rb")
30
+ generator.inject_config(config_file_path: "config/default.yml")
31
+
32
+ puts generator.todo
33
+ end
@@ -0,0 +1,4 @@
1
+ RSpec/EnforceDescription:
2
+ Description: "RSpecのcontextのdescriptionが「場合」で終わることを強制します。"
3
+ Enabled: true
4
+ VersionAdded: "0.1.0"
@@ -0,0 +1,41 @@
1
+ module RuboCop
2
+ module Cop
3
+ module RSpec
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
+ # `$_` はその文字列リテラルの値をキャプチャします。
15
+ def_node_matcher :context_with_description?, <<~PATTERN
16
+ (send nil? :context (str $_) ...)
17
+ PATTERN
18
+
19
+ # `send`ノード(メソッド呼び出し)が検出されたときに呼び出されます。
20
+ # このコップは`RESTRICT_ON_SEND`で`:context`に制限されているため、
21
+ # `context`メソッドの呼び出しに対してのみ実行されます。
22
+ def on_send(node)
23
+ # `context_with_description?`マッチャーを使用して、ノードが`context`ブロックであり、
24
+ # その説明を抽出できるかを確認します。
25
+ context_with_description?(node) do |description|
26
+ # 説明が「場合」で終わっている場合は、違反ではないため処理を終了します。
27
+ return if description.end_with?("場合")
28
+
29
+ # 説明が「場合」で終わっていない場合、違反として報告します。
30
+ # `node.first_argument.loc.expression`は、`context`メソッドの最初の引数(説明文字列)の
31
+ # ソースコード上の位置を指します。
32
+ add_offense(node.first_argument.loc.expression, message: MSG)
33
+ end
34
+ end
35
+ # `csend`ノード(条件付きメソッド呼び出し、例: `obj&.method`)に対しても
36
+ # `on_send`と同じロジックを適用します。
37
+ alias on_csend on_send
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1 @@
1
+ require_relative "rspec/enforce_description"
@@ -0,0 +1,29 @@
1
+ require "lint_roller"
2
+
3
+ module RuboCop
4
+ module RspecEnforceDescription
5
+ # A plugin that integrates rubocop-rspec_enforce_description with RuboCop's plugin system.
6
+ class Plugin < LintRoller::Plugin
7
+ def about
8
+ LintRoller::About.new(
9
+ name: "rubocop-rspec_enforce_description",
10
+ version: VERSION,
11
+ homepage: "TODO: Put your plugin's homepage URL here.",
12
+ description: "TODO: Put your plugin's description here."
13
+ )
14
+ end
15
+
16
+ def supported?(context)
17
+ context.engine == :rubocop
18
+ end
19
+
20
+ def rules(_context)
21
+ LintRoller::Rules.new(
22
+ type: :path,
23
+ config_format: :rubocop,
24
+ value: Pathname.new(__dir__).join("../../../config/default.yml")
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module RuboCop
2
+ module RspecEnforceDescription
3
+ VERSION = "0.1.0".freeze
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require_relative "rspec_enforce_description/version"
2
+
3
+ module RuboCop
4
+ module RspecEnforceDescription
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ require "rubocop"
2
+
3
+ require_relative "rubocop/rspec_enforce_description"
4
+ require_relative "rubocop/rspec_enforce_description/version"
5
+ require_relative "rubocop/rspec_enforce_description/plugin"
6
+
7
+ require_relative "rubocop/cop/rspec_enforce_description_cops"
data/memo.md ADDED
@@ -0,0 +1,30 @@
1
+ ```
2
+ ❯ bundle exec rake new_cop -T
3
+ rake build # Build rubocop-rspec_enforce_description-0.1.0.gem into the pkg directory
4
+ rake build:checksum # Generate SHA512 checksum of rubocop-rspec_enforce_description-0.1.0.gem into the checksums directory
5
+ rake clean # Remove any temporary products
6
+ rake clobber # Remove any generated files
7
+ rake install # Build and install rubocop-rspec_enforce_description-0.1.0.gem into system gems
8
+ rake install:local # Build and install rubocop-rspec_enforce_description-0.1.0.gem into system gems without network access
9
+ rake new_cop[cop] # Generate a new cop with a template
10
+ rake release[remote] # Create tag v0.1.0 and build and push rubocop-rspec_enforce_description-0.1.0.gem to rubygems.org
11
+ rake rubocop # Run RuboCop
12
+ rake rubocop:autocorrect # Autocorrect RuboCop offenses (only when it's safe)
13
+ rake rubocop:autocorrect_all # Autocorrect RuboCop offenses (safe and unsafe)
14
+ rake spec # Run RSpec code examples
15
+ ```
16
+
17
+ ```
18
+ ❯ bundle exec rake 'new_cop[RSpec/enforce_description]'
19
+ [create] lib/rubocop/cop/rspec/enforce_description.rb
20
+ [create] spec/rubocop/cop/rspec/enforce_description_spec.rb
21
+ [modify] lib/rubocop/cop/rspec_enforce_description_cops.rb - `require_relative 'rspec/enforce_description'` was injected.
22
+ [modify] A configuration for the cop is added into config/default.yml.
23
+ Do 4 steps:
24
+ 1. Modify the description of RSpec/EnforceDescription in config/default.yml
25
+ 2. Implement your new cop in the generated file!
26
+ 3. Commit your new cop with a message such as
27
+ e.g. "Add new `RSpec/EnforceDescription` cop"
28
+ 4. Run `bundle exec rake changelog:new` to generate a changelog entry
29
+ for your new cop.
30
+ ```
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-rspec_enforce_description
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - thr3a
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-05-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lint_roller
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.72.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.72.2
41
+ description:
42
+ email:
43
+ - thr3a@example.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec"
49
+ - ".rubocop.yml"
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - config/default.yml
54
+ - lib/rubocop-rspec_enforce_description.rb
55
+ - lib/rubocop/cop/rspec/enforce_description.rb
56
+ - lib/rubocop/cop/rspec_enforce_description_cops.rb
57
+ - lib/rubocop/rspec_enforce_description.rb
58
+ - lib/rubocop/rspec_enforce_description/plugin.rb
59
+ - lib/rubocop/rspec_enforce_description/version.rb
60
+ - memo.md
61
+ homepage: https://github.com/thr3a/rubocop-rspec_enforce_description
62
+ licenses:
63
+ - MIT
64
+ metadata:
65
+ homepage_uri: https://github.com/thr3a/rubocop-rspec_enforce_description
66
+ source_code_uri: https://github.com/thr3a/rubocop-rspec_enforce_description
67
+ default_lint_roller_plugin: RuboCop::RspecEnforceDescription::Plugin
68
+ rubygems_mfa_required: 'true'
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 2.7.0
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 3.5.11
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Custom cops that define rules for rspec descriptions
88
+ test_files: []