Skip to content

Commit 46dd269

Browse files
DEV: Introduce syntax_tree for ruby formatting (#408)
1 parent 4902ba6 commit 46dd269

9 files changed

+39
-24
lines changed

.github/workflows/plugin-linting.yml

+9
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,12 @@ jobs:
5555
- name: Rubocop
5656
if: ${{ !cancelled() }}
5757
run: bundle exec rubocop .
58+
59+
- name: Syntax Tree
60+
if: ${{ !cancelled() }}
61+
run: |
62+
if test -f .streerc; then
63+
bundle exec stree check Gemfile $(git ls-files '*.rb') $(git ls-files '*.rake')
64+
else
65+
echo "Stree config not detected for this repository. Skipping."
66+
fi

.github/workflows/plugin-tests.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080

8181
- name: Get yarn cache directory
8282
id: yarn-cache-dir
83-
run: echo "::set-output name=dir::$(yarn cache dir)"
83+
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
8484

8585
- name: Yarn cache
8686
uses: actions/cache@v3
@@ -130,7 +130,7 @@ jobs:
130130
shell: bash
131131
run: |
132132
if [ 0 -lt $(find plugins/${{ github.event.repository.name }}/spec -type f -name "*.rb" 2> /dev/null | wc -l) ]; then
133-
echo "::set-output name=files_exist::true"
133+
echo "files_exist=true" >> $GITHUB_OUTPUT
134134
fi
135135
136136
- name: Plugin RSpec
@@ -142,7 +142,7 @@ jobs:
142142
shell: bash
143143
run: |
144144
if [ 0 -lt $(find plugins/${{ github.event.repository.name }}/test/javascripts -type f \( -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then
145-
echo "::set-output name=files_exist::true"
145+
echo "files_exist=true" >> $GITHUB_OUTPUT
146146
fi
147147
148148
- name: Plugin QUnit

.rubocop.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
inherit_gem:
2-
rubocop-discourse: default.yml
2+
rubocop-discourse: stree-compat.yml

.streerc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--print-width=100
2+
--plugins=plugin/trailing_comma

Gemfile.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ GEM
66
parallel (1.22.1)
77
parser (3.1.3.0)
88
ast (~> 2.4.1)
9-
prettier_print (0.1.0)
9+
prettier_print (1.1.0)
1010
rainbow (3.1.1)
1111
regexp_parser (2.6.1)
1212
rexml (3.2.5)
@@ -28,8 +28,8 @@ GEM
2828
rubocop-rspec (2.16.0)
2929
rubocop (~> 1.33)
3030
ruby-progressbar (1.11.0)
31-
syntax_tree (3.2.1)
32-
prettier_print
31+
syntax_tree (5.0.1)
32+
prettier_print (>= 1.1.0)
3333
unicode-display_width (2.3.0)
3434

3535
PLATFORMS

lib/discourse_calendar.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module DiscourseAssign
44
module DiscourseCalendar
5-
HOLIDAY_CUSTOM_FIELD ||= 'on_holiday'
5+
HOLIDAY_CUSTOM_FIELD ||= "on_holiday"
66
end
77
end

lib/random_assign_utils.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def self.automation_script!(context, fields, automation)
2323
min_hours = fields.dig("minimum_time_between_assignments", "value").presence
2424
if min_hours &&
2525
TopicCustomField
26-
.where(name: "assigned_to_id", topic_id: topic_id)
27-
.where("created_at < ?", min_hours.to_i.hours.ago)
28-
.exists?
26+
.where(name: "assigned_to_id", topic_id: topic_id)
27+
.where("created_at < ?", min_hours.to_i.hours.ago)
28+
.exists?
2929
log_info(automation, "Topic(#{topic_id}) has already been assigned recently")
3030
return
3131
end

spec/lib/assigner_spec.rb

+7-8
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,13 @@
4646
it "deletes notification for original assignee when reassigning" do
4747
Jobs.run_immediately!
4848

49-
expect {
50-
described_class.new(topic, admin).assign(moderator)
51-
}.to change { moderator.notifications.count }.by(1)
52-
53-
expect {
54-
described_class.new(topic, admin).assign(moderator_2)
55-
}.to change { moderator.notifications.count }.by(-1)
56-
.and change { moderator_2.notifications.count }.by(1)
49+
expect { described_class.new(topic, admin).assign(moderator) }.to change {
50+
moderator.notifications.count
51+
}.by(1)
52+
53+
expect { described_class.new(topic, admin).assign(moderator_2) }.to change {
54+
moderator.notifications.count
55+
}.by(-1).and change { moderator_2.notifications.count }.by(1)
5756
end
5857

5958
it "can assign with note" do

spec/requests/assign_controller_spec.rb

+10-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
let(:user) { Fabricate(:admin, name: "Robin Ward", username: "eviltrout") }
1111
fab!(:post) { Fabricate(:post) }
1212
fab!(:user2) do
13-
Fabricate(:active_user, name: "David Taylor", username: "david", groups: [default_allowed_group])
13+
Fabricate(
14+
:active_user,
15+
name: "David Taylor",
16+
username: "david",
17+
groups: [default_allowed_group],
18+
)
1419
end
1520
let(:non_admin) { Fabricate(:user, groups: [default_allowed_group]) }
1621
fab!(:normal_user) { Fabricate(:user) }
@@ -91,9 +96,7 @@
9196
end
9297

9398
describe "#suggestions" do
94-
before do
95-
sign_in(user)
96-
end
99+
before { sign_in(user) }
97100

98101
it "suggests the current user + the last 6 previously assigned users" do
99102
assignees = 10.times.map { |_| assign_user_to_post.username }
@@ -106,7 +109,9 @@
106109

107110
it "doesn't suggest users on holiday" do
108111
user_on_vacation = assign_user_to_post
109-
user_on_vacation.upsert_custom_fields(DiscourseAssign::DiscourseCalendar::HOLIDAY_CUSTOM_FIELD => "t")
112+
user_on_vacation.upsert_custom_fields(
113+
DiscourseAssign::DiscourseCalendar::HOLIDAY_CUSTOM_FIELD => "t",
114+
)
110115

111116
get "/assign/suggestions.json"
112117

0 commit comments

Comments
 (0)