Skip to content

Commit 14e0800

Browse files
DEV: Introduce syntax_tree for ruby formatting (#217)
1 parent d07ffb6 commit 14e0800

20 files changed

+406
-338
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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
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'
6+
gem "rubocop-discourse"
7+
gem "syntax_tree"
78
end

Gemfile.lock

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ GEM
66
parallel (1.22.1)
77
parser (3.1.2.1)
88
ast (~> 2.4.1)
9+
prettier_print (1.1.0)
910
rainbow (3.1.1)
1011
regexp_parser (2.6.0)
1112
rexml (3.2.5)
@@ -27,13 +28,16 @@ GEM
2728
rubocop-rspec (2.13.2)
2829
rubocop (~> 1.33)
2930
ruby-progressbar (1.11.0)
31+
syntax_tree (5.0.1)
32+
prettier_print (>= 1.1.0)
3033
unicode-display_width (2.3.0)
3134

3235
PLATFORMS
3336
ruby
3437

3538
DEPENDENCIES
3639
rubocop-discourse
40+
syntax_tree
3741

3842
BUNDLED WITH
3943
2.1.4

app/lib/first_accepted_post_solution_validator.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ class FirstAcceptedPostSolutionValidator
44
def self.check(post, trust_level:)
55
return false if post.archetype != Archetype.default
66
return false if !post&.user&.human?
7-
return true if trust_level == 'any'
7+
return true if trust_level == "any"
88

9-
if TrustLevel.compare(post&.user&.trust_level, trust_level.to_i)
10-
return false
11-
end
9+
return false if TrustLevel.compare(post&.user&.trust_level, trust_level.to_i)
1210

1311
if !UserAction.where(user_id: post&.user_id, action_type: UserAction::SOLVED).exists?
1412
return true

db/migrate/20191209095548_ensures_unique_accepted_answer_post_id.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def change
1212
SQL
1313

1414
add_index :topic_custom_fields,
15-
:topic_id,
16-
name: :idx_topic_custom_fields_accepted_answer,
17-
unique: true,
18-
where: "name = 'accepted_answer_post_id'"
15+
:topic_id,
16+
name: :idx_topic_custom_fields_accepted_answer,
17+
unique: true,
18+
where: "name = 'accepted_answer_post_id'"
1919
end
2020
end

db/migrate/20221121223417_rename_badges.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class RenameBadges < ActiveRecord::Migration[6.1]
1818
"sv" => "Kundtjänst",
1919
"tr_TR" => "Yardım masası",
2020
"zh_CN" => "帮助台",
21-
"zh_TW" => "服務台"
21+
"zh_TW" => "服務台",
2222
}
2323

2424
TECH_SUPPORT_TRANSLATIONS = {
@@ -43,11 +43,12 @@ class RenameBadges < ActiveRecord::Migration[6.1]
4343
"sv" => "Teknisk support",
4444
"tr_TR" => "Teknik Destek",
4545
"zh_CN" => "技术支持",
46-
"zh_TW" => "技術支援"
46+
"zh_TW" => "技術支援",
4747
}
4848

4949
def up
50-
default_locale = DB.query_single("SELECT value FROM site_settings WHERE name = 'default_locale'").first || "en"
50+
default_locale =
51+
DB.query_single("SELECT value FROM site_settings WHERE name = 'default_locale'").first || "en"
5152

5253
sql = <<~SQL
5354
UPDATE badges

0 commit comments

Comments
 (0)