Skip to content

Commit f042f6b

Browse files
committed
COMPATIBILITY: update linting
1 parent a163ba5 commit f042f6b

File tree

103 files changed

+2752
-3226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+2752
-3226
lines changed

.rubocop.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
inherit_gem:
2-
rubocop-discourse: default.yml
2+
rubocop-discourse: stree-compat.yml
3+
4+
AllCops:
5+
Exclude:
6+
- 'gems/**/*'
7+
- 'vendor/**/*'
38

49
RSpec/ContextWording:
510
Enabled: false

.streerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--print-width=100
2+
--plugins=plugin/trailing_comma,plugin/disable_auto_ternary

Gemfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# frozen_string_literal: true
22

3-
source 'https://rubygems.org'
3+
source "https://rubygems.org"
44

55
group :development do
6-
gem 'rubocop-discourse'
7-
gem 'racc'
6+
gem "rubocop-discourse"
7+
gem "syntax_tree"
8+
gem "racc"
89
end

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ GEM
2828
parser (3.3.5.0)
2929
ast (~> 2.4.1)
3030
racc
31+
prettier_print (1.2.1)
3132
racc (1.8.1)
3233
rack (3.1.7)
3334
rainbow (3.1.1)
@@ -68,6 +69,8 @@ GEM
6869
rubocop-rspec (~> 3, >= 3.0.1)
6970
ruby-progressbar (1.13.0)
7071
securerandom (0.3.1)
72+
syntax_tree (6.2.0)
73+
prettier_print (>= 1.2.0)
7174
tzinfo (2.0.6)
7275
concurrent-ruby (~> 1.0)
7376
unicode-display_width (2.6.0)
@@ -79,6 +82,7 @@ PLATFORMS
7982
DEPENDENCIES
8083
racc
8184
rubocop-discourse
85+
syntax_tree
8286

8387
BUNDLED WITH
8488
2.5.18

app/controllers/custom_wizard/admin/api.rb

Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,28 @@ class CustomWizard::AdminApiController < CustomWizard::AdminController
33
skip_before_action :check_xhr, only: [:redirect]
44

55
def list
6-
serializer = ActiveModel::ArraySerializer.new(CustomWizard::Api.list,
7-
each_serializer: CustomWizard::BasicApiSerializer
8-
)
6+
serializer =
7+
ActiveModel::ArraySerializer.new(
8+
CustomWizard::Api.list,
9+
each_serializer: CustomWizard::BasicApiSerializer,
10+
)
911
render json: MultiJson.dump(serializer)
1012
end
1113

1214
def find
13-
render_serialized(CustomWizard::Api.get(api_params[:name]), CustomWizard::ApiSerializer, root: false)
15+
render_serialized(
16+
CustomWizard::Api.get(api_params[:name]),
17+
CustomWizard::ApiSerializer,
18+
root: false,
19+
)
1420
end
1521

1622
def save
1723
current = CustomWizard::Api.get(api_params[:name])
1824

1925
if api_params[:new] && current
20-
raise Discourse::InvalidParameters, "An API with that name already exists: '#{current.title || current.name}'"
26+
raise Discourse::InvalidParameters,
27+
"An API with that name already exists: '#{current.title || current.name}'"
2128
end
2229

2330
unless subscription.includes?(:api, :all)
@@ -28,28 +35,28 @@ def save
2835
CustomWizard::Api.set(api_params[:name], title: api_params[:title])
2936

3037
if auth_data.present?
31-
auth_data['auth_params'] = auth_data['auth_params'] || []
38+
auth_data["auth_params"] = auth_data["auth_params"] || []
3239
CustomWizard::Api::Authorization.set(api_params[:name], auth_data)
3340
end
3441

3542
if api_params[:endpoints].is_a? String
3643
begin
3744
endpoints = JSON.parse(api_params[:endpoints])
38-
endpoints.each do |endpoint|
39-
CustomWizard::Api::Endpoint.set(api_params[:name], endpoint)
40-
end
45+
endpoints.each { |endpoint| CustomWizard::Api::Endpoint.set(api_params[:name], endpoint) }
4146
rescue => e
4247
puts e
4348
end
4449
end
4550
end
4651

47-
render json: success_json.merge(
48-
api: CustomWizard::ApiSerializer.new(
49-
CustomWizard::Api.get(api_params[:name]),
50-
root: false
51-
)
52-
)
52+
render json:
53+
success_json.merge(
54+
api:
55+
CustomWizard::ApiSerializer.new(
56+
CustomWizard::Api.get(api_params[:name]),
57+
root: false,
58+
),
59+
)
5360
end
5461

5562
def remove
@@ -67,14 +74,16 @@ def authorize
6774
result = CustomWizard::Api::Authorization.get_token(api_params[:name])
6875

6976
if result.instance_variable_defined?(:@error)
70-
render json: failed_json.merge(message: result['error_description'] || result['error'])
77+
render json: failed_json.merge(message: result["error_description"] || result["error"])
7178
else
72-
render json: success_json.merge(
73-
api: CustomWizard::ApiSerializer.new(
74-
CustomWizard::Api.get(api_params[:name]),
75-
root: false
76-
)
77-
)
79+
render json:
80+
success_json.merge(
81+
api:
82+
CustomWizard::ApiSerializer.new(
83+
CustomWizard::Api.get(api_params[:name]),
84+
root: false,
85+
),
86+
)
7887
end
7988
end
8089

@@ -90,47 +99,51 @@ def redirect
9099
CustomWizard::Api::Authorization.set(params[:name], code: params[:code])
91100
CustomWizard::Api::Authorization.get_token(params[:name])
92101

93-
redirect_to path('/admin/wizards/apis/' + params[:name])
102+
redirect_to path("/admin/wizards/apis/" + params[:name])
94103
end
95104

96105
private
97106

98107
def api_params
99108
params.require(:name)
100109

101-
data = params.permit(
102-
:name,
103-
:title,
104-
:auth_type,
105-
:auth_url,
106-
:token_url,
107-
:client_id,
108-
:client_secret,
109-
:username,
110-
:password,
111-
:auth_params,
112-
:endpoints,
113-
:new
114-
).to_h
110+
data =
111+
params.permit(
112+
:name,
113+
:title,
114+
:auth_type,
115+
:auth_url,
116+
:token_url,
117+
:client_id,
118+
:client_secret,
119+
:username,
120+
:password,
121+
:auth_params,
122+
:endpoints,
123+
:new,
124+
).to_h
115125

116126
data[:name] = data[:name].underscore
117127

118128
@api_params ||= data
119129
end
120130

121131
def auth_data
122-
auth_data = api_params.slice(
123-
:auth_type,
124-
:auth_url,
125-
:token_url,
126-
:client_id,
127-
:client_secret,
128-
:username,
129-
:password,
130-
:auth_params
131-
)
132+
auth_data =
133+
api_params.slice(
134+
:auth_type,
135+
:auth_url,
136+
:token_url,
137+
:client_id,
138+
:client_secret,
139+
:username,
140+
:password,
141+
:auth_params,
142+
)
132143

133-
auth_data[:auth_params] = JSON.parse(auth_data[:auth_params]) if auth_data[:auth_params].present?
144+
auth_data[:auth_params] = JSON.parse(auth_data[:auth_params]) if auth_data[
145+
:auth_params
146+
].present?
134147

135148
@auth_data ||= auth_data
136149
end
Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# frozen_string_literal: true
22
class CustomWizard::AdminCustomFieldsController < CustomWizard::AdminController
33
def index
4-
render_json_dump(
5-
custom_fields: custom_field_list
6-
)
4+
render_json_dump(custom_fields: custom_field_list)
75
end
86

97
def update
@@ -12,23 +10,24 @@ def update
1210
field_data = {}
1311

1412
if saved_field = CustomWizard::CustomField.find(field_params[:id].to_i)
15-
CustomWizard::CustomField::ATTRS.each do |attr|
16-
field_data[attr] = saved_field.send(attr)
17-
end
13+
CustomWizard::CustomField::ATTRS.each { |attr| field_data[attr] = saved_field.send(attr) }
1814
field_id = saved_field.id
1915
end
2016

21-
CustomWizard::CustomField::ATTRS.each do |attr|
22-
field_data[attr] = field_params[attr]
23-
end
17+
CustomWizard::CustomField::ATTRS.each { |attr| field_data[attr] = field_params[attr] }
2418

2519
field = CustomWizard::CustomField.new(field_id, field_data)
2620

2721
PluginStoreRow.transaction do
2822
unless field.save
29-
field_errors = field.errors.any? ?
30-
field.errors.full_messages.join("\n\n") :
31-
I18n.t("wizard.custom_field.error.save_default", name: field.name)
23+
field_errors =
24+
(
25+
if field.errors.any?
26+
field.errors.full_messages.join("\n\n")
27+
else
28+
I18n.t("wizard.custom_field.error.save_default", name: field.name)
29+
end
30+
)
3231
errors << field_errors
3332
raise ActiveRecord::Rollback.new
3433
end
@@ -54,13 +53,6 @@ def destroy
5453
private
5554

5655
def field_params
57-
params.required(:custom_field)
58-
.permit(
59-
:id,
60-
:name,
61-
:klass,
62-
:type,
63-
serializers: []
64-
)
56+
params.required(:custom_field).permit(:id, :name, :klass, :type, serializers: [])
6557
end
6658
end

app/controllers/custom_wizard/admin/logs.rb

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,45 @@ class CustomWizard::AdminLogsController < CustomWizard::AdminController
33
before_action :find_wizard, except: [:index]
44

55
def index
6-
render json: ActiveModel::ArraySerializer.new(
7-
CustomWizard::Wizard.list(current_user),
8-
each_serializer: CustomWizard::BasicWizardSerializer
9-
)
6+
render json:
7+
ActiveModel::ArraySerializer.new(
8+
CustomWizard::Wizard.list(current_user),
9+
each_serializer: CustomWizard::BasicWizardSerializer,
10+
)
1011
end
1112

1213
def show
1314
render_json_dump(
1415
wizard: CustomWizard::BasicWizardSerializer.new(@wizard, root: false),
15-
logs: ActiveModel::ArraySerializer.new(
16-
log_list.logs,
17-
each_serializer: CustomWizard::LogSerializer
18-
),
19-
total: log_list.total
16+
logs:
17+
ActiveModel::ArraySerializer.new(
18+
log_list.logs,
19+
each_serializer: CustomWizard::LogSerializer,
20+
),
21+
total: log_list.total,
2022
)
2123
end
2224

2325
protected
2426

2527
def log_list
26-
@log_list ||= begin
27-
list = CustomWizard::Log.list(params[:page].to_i, params[:limit].to_i, params[:wizard_id])
28+
@log_list ||=
29+
begin
30+
list = CustomWizard::Log.list(params[:page].to_i, params[:limit].to_i, params[:wizard_id])
2831

29-
if list.logs.any? && (usernames = list.logs.map(&:username)).present?
30-
user_map = User.where(username: usernames)
31-
.reduce({}) do |result, user|
32-
result[user.username] = user
33-
result
34-
end
32+
if list.logs.any? && (usernames = list.logs.map(&:username)).present?
33+
user_map =
34+
User
35+
.where(username: usernames)
36+
.reduce({}) do |result, user|
37+
result[user.username] = user
38+
result
39+
end
3540

36-
list.logs.each do |log_item|
37-
log_item.user = user_map[log_item.username]
41+
list.logs.each { |log_item| log_item.user = user_map[log_item.username] }
3842
end
39-
end
4043

41-
list
42-
end
44+
list
45+
end
4346
end
4447
end

0 commit comments

Comments
 (0)