rubocop-discourse 3.13.3 → 3.14.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 +35 -3
- data/lib/rubocop/cop/discourse/plugins/call_requires_plugin.rb +1 -2
- data/lib/rubocop/cop/discourse/plugins/no_monkey_patching.rb +5 -12
- data/lib/rubocop/cop/discourse/plugins/use_plugin_instance_on.rb +1 -2
- data/lib/rubocop/cop/discourse/services/empty_lines_around_blocks.rb +6 -12
- data/lib/rubocop/cop/discourse/services/group_keywords.rb +2 -7
- data/lib/rubocop/discourse/version.rb +1 -1
- data/rubocop-core.yml +2 -143
- data/rubocop-discourse.gemspec +15 -2
- data/rubocop-layout.yml +2 -80
- data/rubocop-rspec.yml +9 -215
- metadata +5 -35
- data/.github/workflows/ci.yml +0 -41
- data/.gitignore +0 -1
- data/.rspec +0 -1
- data/.rubocop.yml +0 -9
- data/.streerc +0 -2
- data/Gemfile +0 -11
- data/Rakefile +0 -8
- data/spec/fixtures/controllers/bad_controller.rb +0 -5
- data/spec/fixtures/controllers/base_controller.rb +0 -11
- data/spec/fixtures/controllers/good_controller.rb +0 -4
- data/spec/fixtures/controllers/inherit_from_outside_controller.rb +0 -5
- data/spec/fixtures/controllers/namespaced_parent_controller.rb +0 -5
- data/spec/fixtures/controllers/no_requires_plugin_controller.rb +0 -5
- data/spec/fixtures/controllers/requires_plugin_controller.rb +0 -6
- data/spec/lib/rubocop/cop/discourse/services/empty_lines_around_blocks_spec.rb +0 -309
- data/spec/lib/rubocop/cop/discourse/services/group_keywords_spec.rb +0 -137
- data/spec/lib/rubocop/cop/fabricator_shorthand_spec.rb +0 -71
- data/spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb +0 -47
- data/spec/lib/rubocop/cop/no_mixing_multisite_and_standard_specs_spec.rb +0 -68
- data/spec/lib/rubocop/cop/no_mocking_jobs_enqueue_spec.rb +0 -31
- data/spec/lib/rubocop/cop/no_reset_column_information_migrations_spec.rb +0 -33
- data/spec/lib/rubocop/cop/only_top_level_multisite_specs_spec.rb +0 -78
- data/spec/lib/rubocop/cop/plugins/call_requires_plugin_spec.rb +0 -79
- data/spec/lib/rubocop/cop/plugins/namespace_constants_spec.rb +0 -40
- data/spec/lib/rubocop/cop/plugins/namespace_methods_spec.rb +0 -84
- data/spec/lib/rubocop/cop/plugins/no_monkey_patching_spec.rb +0 -91
- data/spec/lib/rubocop/cop/plugins/use_plugin_instance_on_spec.rb +0 -37
- data/spec/lib/rubocop/cop/plugins/use_require_relative_spec.rb +0 -24
- data/spec/lib/rubocop/cop/time_eq_matcher_spec.rb +0 -23
- data/spec/spec_helper.rb +0 -15
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-discourse
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Discourse Team
|
|
@@ -24,19 +24,19 @@ dependencies:
|
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '6.1'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
|
-
name: rubocop
|
|
27
|
+
name: rubocop-discourse-base
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: 1.
|
|
32
|
+
version: 1.0.0
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: 1.
|
|
39
|
+
version: 1.0.0
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: rubocop-rspec
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -153,15 +153,8 @@ executables: []
|
|
|
153
153
|
extensions: []
|
|
154
154
|
extra_rdoc_files: []
|
|
155
155
|
files:
|
|
156
|
-
- ".github/workflows/ci.yml"
|
|
157
|
-
- ".gitignore"
|
|
158
|
-
- ".rspec"
|
|
159
|
-
- ".rubocop.yml"
|
|
160
|
-
- ".streerc"
|
|
161
|
-
- Gemfile
|
|
162
156
|
- LICENSE
|
|
163
157
|
- README.md
|
|
164
|
-
- Rakefile
|
|
165
158
|
- config/default.yml
|
|
166
159
|
- default.yml
|
|
167
160
|
- lib/rubocop-discourse.rb
|
|
@@ -196,29 +189,6 @@ files:
|
|
|
196
189
|
- rubocop-layout.yml
|
|
197
190
|
- rubocop-rails.yml
|
|
198
191
|
- rubocop-rspec.yml
|
|
199
|
-
- spec/fixtures/controllers/bad_controller.rb
|
|
200
|
-
- spec/fixtures/controllers/base_controller.rb
|
|
201
|
-
- spec/fixtures/controllers/good_controller.rb
|
|
202
|
-
- spec/fixtures/controllers/inherit_from_outside_controller.rb
|
|
203
|
-
- spec/fixtures/controllers/namespaced_parent_controller.rb
|
|
204
|
-
- spec/fixtures/controllers/no_requires_plugin_controller.rb
|
|
205
|
-
- spec/fixtures/controllers/requires_plugin_controller.rb
|
|
206
|
-
- spec/lib/rubocop/cop/discourse/services/empty_lines_around_blocks_spec.rb
|
|
207
|
-
- spec/lib/rubocop/cop/discourse/services/group_keywords_spec.rb
|
|
208
|
-
- spec/lib/rubocop/cop/fabricator_shorthand_spec.rb
|
|
209
|
-
- spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb
|
|
210
|
-
- spec/lib/rubocop/cop/no_mixing_multisite_and_standard_specs_spec.rb
|
|
211
|
-
- spec/lib/rubocop/cop/no_mocking_jobs_enqueue_spec.rb
|
|
212
|
-
- spec/lib/rubocop/cop/no_reset_column_information_migrations_spec.rb
|
|
213
|
-
- spec/lib/rubocop/cop/only_top_level_multisite_specs_spec.rb
|
|
214
|
-
- spec/lib/rubocop/cop/plugins/call_requires_plugin_spec.rb
|
|
215
|
-
- spec/lib/rubocop/cop/plugins/namespace_constants_spec.rb
|
|
216
|
-
- spec/lib/rubocop/cop/plugins/namespace_methods_spec.rb
|
|
217
|
-
- spec/lib/rubocop/cop/plugins/no_monkey_patching_spec.rb
|
|
218
|
-
- spec/lib/rubocop/cop/plugins/use_plugin_instance_on_spec.rb
|
|
219
|
-
- spec/lib/rubocop/cop/plugins/use_require_relative_spec.rb
|
|
220
|
-
- spec/lib/rubocop/cop/time_eq_matcher_spec.rb
|
|
221
|
-
- spec/spec_helper.rb
|
|
222
192
|
- stree-compat.yml
|
|
223
193
|
homepage: https://github.com/discourse/rubocop-discourse
|
|
224
194
|
licenses:
|
|
@@ -232,7 +202,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
232
202
|
requirements:
|
|
233
203
|
- - ">="
|
|
234
204
|
- !ruby/object:Gem::Version
|
|
235
|
-
version: '0'
|
|
205
|
+
version: '3.0'
|
|
236
206
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
207
|
requirements:
|
|
238
208
|
- - ">="
|
data/.github/workflows/ci.yml
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
push:
|
|
6
|
-
branches:
|
|
7
|
-
- main
|
|
8
|
-
|
|
9
|
-
jobs:
|
|
10
|
-
build:
|
|
11
|
-
runs-on: ubuntu-latest
|
|
12
|
-
|
|
13
|
-
steps:
|
|
14
|
-
- uses: actions/checkout@v4
|
|
15
|
-
|
|
16
|
-
- name: Setup ruby
|
|
17
|
-
uses: ruby/setup-ruby@v1
|
|
18
|
-
with:
|
|
19
|
-
ruby-version: "3.3"
|
|
20
|
-
bundler-cache: true
|
|
21
|
-
|
|
22
|
-
- name: Rubocop
|
|
23
|
-
run: bundle exec rubocop
|
|
24
|
-
|
|
25
|
-
- name: Rspec
|
|
26
|
-
run: bundle exec rspec spec
|
|
27
|
-
|
|
28
|
-
publish:
|
|
29
|
-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
30
|
-
needs: build
|
|
31
|
-
runs-on: ubuntu-latest
|
|
32
|
-
|
|
33
|
-
steps:
|
|
34
|
-
- uses: actions/checkout@v4
|
|
35
|
-
|
|
36
|
-
- name: Release Gem
|
|
37
|
-
uses: discourse/publish-rubygems-action@v3
|
|
38
|
-
env:
|
|
39
|
-
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
|
|
40
|
-
GIT_EMAIL: team@discourse.org
|
|
41
|
-
GIT_NAME: discoursebot
|
data/.gitignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Gemfile.lock
|
data/.rspec
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
--require 'spec_helper'
|
data/.rubocop.yml
DELETED
data/.streerc
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class BadController < NoRequiresPluginController
|
|
4
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/Plugins/CallRequiresPlugin: Use `requires_plugin` in controllers to prevent routes from being accessible when plugin is disabled.
|
|
5
|
-
end
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class InheritFromOutsideController < ApplicationController
|
|
4
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/Plugins/CallRequiresPlugin: Use `requires_plugin` in controllers to prevent routes from being accessible when plugin is disabled.
|
|
5
|
-
end
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class InheritFromOutsideController < MyPlugin::ApplicationController
|
|
4
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/Plugins/CallRequiresPlugin: Use `requires_plugin` in controllers to prevent routes from being accessible when plugin is disabled.
|
|
5
|
-
end
|
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe RuboCop::Cop::Discourse::Services::EmptyLinesAroundBlocks,
|
|
4
|
-
:config do
|
|
5
|
-
subject(:cop) { described_class.new(config) }
|
|
6
|
-
|
|
7
|
-
let(:config) { RuboCop::Config.new }
|
|
8
|
-
|
|
9
|
-
context "when not in a service class" do
|
|
10
|
-
it "does nothing" do
|
|
11
|
-
expect_no_offenses(<<~RUBY)
|
|
12
|
-
class NotAService
|
|
13
|
-
step :first_step
|
|
14
|
-
params do
|
|
15
|
-
attribute :my_attribute
|
|
16
|
-
end
|
|
17
|
-
step :another_step
|
|
18
|
-
end
|
|
19
|
-
RUBY
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
context "when in a service class" do
|
|
24
|
-
context "when a blank line is missing before a block" do
|
|
25
|
-
it "registers an offense" do
|
|
26
|
-
expect_offense(<<~RUBY)
|
|
27
|
-
class MyService
|
|
28
|
-
include Service::Base
|
|
29
|
-
|
|
30
|
-
step :first_step
|
|
31
|
-
params do
|
|
32
|
-
^^^^^^^^^ Discourse/Services/EmptyLinesAroundBlocks: Add empty lines around a step block.
|
|
33
|
-
attribute :my_attribute
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
RUBY
|
|
37
|
-
|
|
38
|
-
expect_correction(<<~RUBY)
|
|
39
|
-
class MyService
|
|
40
|
-
include Service::Base
|
|
41
|
-
|
|
42
|
-
step :first_step
|
|
43
|
-
|
|
44
|
-
params do
|
|
45
|
-
attribute :my_attribute
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
RUBY
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
context "when a blank line is missing after a block" do
|
|
53
|
-
it "registers an offense" do
|
|
54
|
-
expect_offense(<<~RUBY)
|
|
55
|
-
class MyService
|
|
56
|
-
include Service::Base
|
|
57
|
-
|
|
58
|
-
params do
|
|
59
|
-
^^^^^^^^^ Discourse/Services/EmptyLinesAroundBlocks: Add empty lines around a step block.
|
|
60
|
-
attribute :my_attribute
|
|
61
|
-
end
|
|
62
|
-
step :last_step
|
|
63
|
-
end
|
|
64
|
-
RUBY
|
|
65
|
-
|
|
66
|
-
expect_correction(<<~RUBY)
|
|
67
|
-
class MyService
|
|
68
|
-
include Service::Base
|
|
69
|
-
|
|
70
|
-
params do
|
|
71
|
-
attribute :my_attribute
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
step :last_step
|
|
75
|
-
end
|
|
76
|
-
RUBY
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
context "when two blocks are next to each other" do
|
|
81
|
-
it "registers an offense" do
|
|
82
|
-
expect_offense(<<~RUBY)
|
|
83
|
-
class MyService
|
|
84
|
-
include Service::Base
|
|
85
|
-
|
|
86
|
-
params do
|
|
87
|
-
^^^^^^^^^ Discourse/Services/EmptyLinesAroundBlocks: Add empty lines around a step block.
|
|
88
|
-
attribute :attribute
|
|
89
|
-
validates :attribute, presence: true
|
|
90
|
-
end
|
|
91
|
-
transaction do
|
|
92
|
-
^^^^^^^^^^^^^^ Discourse/Services/EmptyLinesAroundBlocks: Add empty lines around a step block.
|
|
93
|
-
step :first
|
|
94
|
-
step :second
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
RUBY
|
|
98
|
-
|
|
99
|
-
expect_correction(<<~RUBY)
|
|
100
|
-
class MyService
|
|
101
|
-
include Service::Base
|
|
102
|
-
|
|
103
|
-
params do
|
|
104
|
-
attribute :attribute
|
|
105
|
-
validates :attribute, presence: true
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
transaction do
|
|
109
|
-
step :first
|
|
110
|
-
step :second
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
RUBY
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
context "when a block is a one-liner" do
|
|
118
|
-
it "does not register an offense" do
|
|
119
|
-
expect_no_offenses(<<~RUBY)
|
|
120
|
-
class MyService
|
|
121
|
-
include Service::Base
|
|
122
|
-
|
|
123
|
-
try { step :might_raise }
|
|
124
|
-
step :last_step
|
|
125
|
-
end
|
|
126
|
-
RUBY
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
context "when blocks are nested" do
|
|
131
|
-
context "when there is just one nested block" do
|
|
132
|
-
it "does not register an offense" do
|
|
133
|
-
expect_no_offenses(<<~RUBY)
|
|
134
|
-
class MyService
|
|
135
|
-
include Service::Base
|
|
136
|
-
|
|
137
|
-
transaction do
|
|
138
|
-
try do
|
|
139
|
-
step :first_step
|
|
140
|
-
step :second_step
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
RUBY
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
context "when the nested block is in the first position" do
|
|
149
|
-
context "when there is no empty line before" do
|
|
150
|
-
it "does not register an offense" do
|
|
151
|
-
expect_no_offenses(<<~RUBY)
|
|
152
|
-
class MyService
|
|
153
|
-
include Service::Base
|
|
154
|
-
|
|
155
|
-
transaction do
|
|
156
|
-
try do
|
|
157
|
-
step :first_step
|
|
158
|
-
step :second_step
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
step :third_step
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
RUBY
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
context "when there is no empty line after" do
|
|
169
|
-
it "registers an offense" do
|
|
170
|
-
expect_offense(<<~RUBY)
|
|
171
|
-
class MyService
|
|
172
|
-
include Service::Base
|
|
173
|
-
|
|
174
|
-
transaction do
|
|
175
|
-
try do
|
|
176
|
-
^^^^^^ Discourse/Services/EmptyLinesAroundBlocks: Add empty lines around a step block.
|
|
177
|
-
step :first_step
|
|
178
|
-
step :second_step
|
|
179
|
-
end
|
|
180
|
-
step :third_step
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
RUBY
|
|
184
|
-
|
|
185
|
-
expect_correction(<<~RUBY)
|
|
186
|
-
class MyService
|
|
187
|
-
include Service::Base
|
|
188
|
-
|
|
189
|
-
transaction do
|
|
190
|
-
try do
|
|
191
|
-
step :first_step
|
|
192
|
-
step :second_step
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
step :third_step
|
|
196
|
-
end
|
|
197
|
-
end
|
|
198
|
-
RUBY
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
context "when the nested block is in the last position" do
|
|
204
|
-
context "when there is no empty line after" do
|
|
205
|
-
it "does not register an offense" do
|
|
206
|
-
expect_no_offenses(<<~RUBY)
|
|
207
|
-
class MyService
|
|
208
|
-
include Service::Base
|
|
209
|
-
|
|
210
|
-
transaction do
|
|
211
|
-
step :first_step
|
|
212
|
-
|
|
213
|
-
try do
|
|
214
|
-
step :second_step
|
|
215
|
-
step :third_step
|
|
216
|
-
end
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
RUBY
|
|
220
|
-
end
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
context "when there is no empty line before" do
|
|
224
|
-
it "registers an offense" do
|
|
225
|
-
expect_offense(<<~RUBY)
|
|
226
|
-
class MyService
|
|
227
|
-
include Service::Base
|
|
228
|
-
|
|
229
|
-
transaction do
|
|
230
|
-
step :first_step
|
|
231
|
-
try do
|
|
232
|
-
^^^^^^ Discourse/Services/EmptyLinesAroundBlocks: Add empty lines around a step block.
|
|
233
|
-
step :second_step
|
|
234
|
-
step :third_step
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
end
|
|
238
|
-
RUBY
|
|
239
|
-
|
|
240
|
-
expect_correction(<<~RUBY)
|
|
241
|
-
class MyService
|
|
242
|
-
include Service::Base
|
|
243
|
-
|
|
244
|
-
transaction do
|
|
245
|
-
step :first_step
|
|
246
|
-
|
|
247
|
-
try do
|
|
248
|
-
step :second_step
|
|
249
|
-
step :third_step
|
|
250
|
-
end
|
|
251
|
-
end
|
|
252
|
-
end
|
|
253
|
-
RUBY
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
end
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
context "when blocks are used in methods" do
|
|
260
|
-
it "does not register an offense" do
|
|
261
|
-
expect_no_offenses(<<~RUBY)
|
|
262
|
-
class MyService
|
|
263
|
-
include Service::Base
|
|
264
|
-
|
|
265
|
-
step :first_step
|
|
266
|
-
|
|
267
|
-
def first_step(model:)
|
|
268
|
-
model.transaction do
|
|
269
|
-
do_something
|
|
270
|
-
end
|
|
271
|
-
end
|
|
272
|
-
end
|
|
273
|
-
RUBY
|
|
274
|
-
end
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
context "with a full valid example" do
|
|
278
|
-
it "does not register an offense" do
|
|
279
|
-
expect_no_offenses(<<~RUBY)
|
|
280
|
-
class MyService
|
|
281
|
-
include Service::Base
|
|
282
|
-
|
|
283
|
-
step :first_step
|
|
284
|
-
|
|
285
|
-
params do
|
|
286
|
-
attribute :my_attribute
|
|
287
|
-
|
|
288
|
-
validates :my_attributes, presence: true
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
policy :allowed?
|
|
292
|
-
model :user
|
|
293
|
-
|
|
294
|
-
transaction do
|
|
295
|
-
try do
|
|
296
|
-
step :save_user
|
|
297
|
-
step :log
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
step :other_step
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
step :last_step
|
|
304
|
-
end
|
|
305
|
-
RUBY
|
|
306
|
-
end
|
|
307
|
-
end
|
|
308
|
-
end
|
|
309
|
-
end
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe RuboCop::Cop::Discourse::Services::GroupKeywords, :config do
|
|
4
|
-
subject(:cop) { described_class.new(config) }
|
|
5
|
-
|
|
6
|
-
let(:config) { RuboCop::Config.new }
|
|
7
|
-
|
|
8
|
-
context "when not in a service class" do
|
|
9
|
-
it "does nothing" do
|
|
10
|
-
expect_no_offenses(<<~RUBY)
|
|
11
|
-
class NotAService
|
|
12
|
-
step :first_step
|
|
13
|
-
|
|
14
|
-
step :another_step
|
|
15
|
-
end
|
|
16
|
-
RUBY
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
context "when in a service class" do
|
|
21
|
-
context "when keywords are not grouped together" do
|
|
22
|
-
it "reports an offense" do
|
|
23
|
-
expect_offense(<<~RUBY)
|
|
24
|
-
class MyService
|
|
25
|
-
include Service::Base
|
|
26
|
-
|
|
27
|
-
model :user
|
|
28
|
-
^^^^^^^^^^^ Discourse/Services/GroupKeywords: Group one-liner steps together by removing extra empty lines.
|
|
29
|
-
|
|
30
|
-
policy :allowed?
|
|
31
|
-
step :save
|
|
32
|
-
end
|
|
33
|
-
RUBY
|
|
34
|
-
|
|
35
|
-
expect_correction(<<~RUBY)
|
|
36
|
-
class MyService
|
|
37
|
-
include Service::Base
|
|
38
|
-
|
|
39
|
-
model :user
|
|
40
|
-
policy :allowed?
|
|
41
|
-
step :save
|
|
42
|
-
end
|
|
43
|
-
RUBY
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
context "when a one-liner block has an empty line before a keyword" do
|
|
48
|
-
it "reports an offense" do
|
|
49
|
-
expect_offense(<<~RUBY)
|
|
50
|
-
class MyService
|
|
51
|
-
include Service::Base
|
|
52
|
-
|
|
53
|
-
model :user
|
|
54
|
-
policy :allowed?
|
|
55
|
-
^^^^^^^^^^^^^^^^ Discourse/Services/GroupKeywords: Group one-liner steps together by removing extra empty lines.
|
|
56
|
-
|
|
57
|
-
try { step :save }
|
|
58
|
-
end
|
|
59
|
-
RUBY
|
|
60
|
-
|
|
61
|
-
expect_correction(<<~RUBY)
|
|
62
|
-
class MyService
|
|
63
|
-
include Service::Base
|
|
64
|
-
|
|
65
|
-
model :user
|
|
66
|
-
policy :allowed?
|
|
67
|
-
try { step :save }
|
|
68
|
-
end
|
|
69
|
-
RUBY
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
context "when keywords with empty lines appear in a nested block" do
|
|
74
|
-
it "reports an offense" do
|
|
75
|
-
expect_offense(<<~RUBY)
|
|
76
|
-
class MyService
|
|
77
|
-
include Service::Base
|
|
78
|
-
|
|
79
|
-
transaction do
|
|
80
|
-
step :save
|
|
81
|
-
^^^^^^^^^^ Discourse/Services/GroupKeywords: Group one-liner steps together by removing extra empty lines.
|
|
82
|
-
|
|
83
|
-
step :log
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
RUBY
|
|
87
|
-
|
|
88
|
-
expect_correction(<<~RUBY)
|
|
89
|
-
class MyService
|
|
90
|
-
include Service::Base
|
|
91
|
-
|
|
92
|
-
transaction do
|
|
93
|
-
step :save
|
|
94
|
-
step :log
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
RUBY
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
context "when keywords are grouped together" do
|
|
102
|
-
it "does not report an offense" do
|
|
103
|
-
expect_no_offenses(<<~RUBY)
|
|
104
|
-
class MyService
|
|
105
|
-
include Service::Base
|
|
106
|
-
|
|
107
|
-
model :user
|
|
108
|
-
policy :allowed?
|
|
109
|
-
|
|
110
|
-
transaction do
|
|
111
|
-
step :save
|
|
112
|
-
step :log
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
RUBY
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
context "when keywords are not at the top level" do
|
|
120
|
-
it "does not report an offense" do
|
|
121
|
-
expect_no_offenses(<<~RUBY)
|
|
122
|
-
class MyService
|
|
123
|
-
include Service::Base
|
|
124
|
-
|
|
125
|
-
private
|
|
126
|
-
|
|
127
|
-
def my_method
|
|
128
|
-
step(:save)
|
|
129
|
-
|
|
130
|
-
step(:log)
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
RUBY
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
end
|