Skip to content

Commit 5b04d2b

Browse files
authored
DEV: Update linting setup (#250)
Updates rubocop-discourse, adds syntax_tree, fixes linting issues and reformats code, extracts linting into a separate CI job.
1 parent d97fa2b commit 5b04d2b

Some content is hidden

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

73 files changed

+1380
-1003
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ jobs:
1515
- name: Setup ruby
1616
uses: ruby/setup-ruby@v1
1717
with:
18-
ruby-version: '3.1'
18+
ruby-version: '3.2'
1919
bundler-cache: true
2020

2121
- name: Rubocop
2222
run: bundle exec rubocop
2323

24+
- name: syntax_tree
25+
if: ${{ !cancelled() }}
26+
run: |
27+
set -E
28+
bundle exec stree check Gemfile $(git ls-files '*.rb') $(git ls-files '*.rake')
29+
2430
test:
2531
runs-on: ubuntu-latest
2632

.rubocop.yml

Lines changed: 1 addition & 1 deletion
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

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,disable_ternary

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
2-
source 'https://rubygems.org'
2+
source "https://rubygems.org"
33

44
# Specify your gem's dependencies in discourse_api.gemspec
55
gemspec

discourse_api.gemspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ Gem::Specification.new do |spec|
3030
spec.add_development_dependency 'rspec', '~> 3.4'
3131
spec.add_development_dependency 'simplecov', '~> 0.11'
3232
spec.add_development_dependency 'webmock', '~> 3.0'
33-
spec.add_development_dependency 'rubocop-discourse', '~> 2.5.0'
33+
spec.add_development_dependency 'rubocop-discourse', '~> 3.2.0'
34+
spec.add_development_dependency 'syntax_tree', '~> 6.1.1'
35+
spec.add_development_dependency 'syntax_tree-disable_ternary', '~> 1.0.0'
3436

3537
spec.required_ruby_version = '>= 2.7.0'
3638
end

examples/backups.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# frozen_string_literal: true
2-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3-
require File.expand_path('../../lib/discourse_api', __FILE__)
2+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3+
require File.expand_path("../../lib/discourse_api", __FILE__)
44

55
config = DiscourseApi::ExampleHelper.load_yml
66

7-
client = DiscourseApi::Client.new(config['host'] || 'http://localhost:3000')
8-
client.api_key = config['api_key'] || "YOUR_API_KEY"
9-
client.api_username = config['api_username'] || "YOUR_USERNAME"
7+
client = DiscourseApi::Client.new(config["host"] || "http://localhost:3000")
8+
client.api_key = config["api_key"] || "YOUR_API_KEY"
9+
client.api_username = config["api_username"] || "YOUR_USERNAME"
1010

1111
# get list of backup files
1212
puts client.backups()

examples/badges.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# frozen_string_literal: true
2-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3-
require File.expand_path('../../lib/discourse_api', __FILE__)
2+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3+
require File.expand_path("../../lib/discourse_api", __FILE__)
44

55
config = DiscourseApi::ExampleHelper.load_yml
66

7-
client = DiscourseApi::Client.new(config['host'] || 'http://localhost:3000')
8-
client.api_key = config['api_key'] || "YOUR_API_KEY"
9-
client.api_username = config['api_username'] || "YOUR_USERNAME"
7+
client = DiscourseApi::Client.new(config["host"] || "http://localhost:3000")
8+
client.api_key = config["api_key"] || "YOUR_API_KEY"
9+
client.api_username = config["api_username"] || "YOUR_USERNAME"
1010

1111
# get badges
1212
puts client.badges

examples/bookmark_topic.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# frozen_string_literal: true
2-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3-
require File.expand_path('../../lib/discourse_api', __FILE__)
2+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3+
require File.expand_path("../../lib/discourse_api", __FILE__)
44

55
config = DiscourseApi::ExampleHelper.load_yml
66

7-
client = DiscourseApi::Client.new(config['host'] || 'http://localhost:3000')
8-
client.api_key = config['api_key'] || "YOUR_API_KEY"
9-
client.api_username = config['api_username'] || "YOUR_USERNAME"
7+
client = DiscourseApi::Client.new(config["host"] || "http://localhost:3000")
8+
client.api_key = config["api_key"] || "YOUR_API_KEY"
9+
client.api_username = config["api_username"] || "YOUR_USERNAME"
1010

1111
# Bookmark topic
1212
puts client.bookmark_topic(1418)

examples/category.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# frozen_string_literal: true
2-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3-
require File.expand_path('../../lib/discourse_api', __FILE__)
2+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3+
require File.expand_path("../../lib/discourse_api", __FILE__)
44

55
config = DiscourseApi::ExampleHelper.load_yml
66

7-
client = DiscourseApi::Client.new(config['host'] || 'http://localhost:3000')
8-
client.api_key = config['api_key'] || "YOUR_API_KEY"
9-
client.api_username = config['api_username'] || "YOUR_USERNAME"
7+
client = DiscourseApi::Client.new(config["host"] || "http://localhost:3000")
8+
client.api_key = config["api_key"] || "YOUR_API_KEY"
9+
client.api_username = config["api_username"] || "YOUR_USERNAME"
1010

1111
# get categories
1212
puts client.categories()
@@ -26,5 +26,9 @@
2626
puts category_topics_paged
2727

2828
# update category notification_level
29-
update_response = client.category_set_user_notification(id: "test-id", notification_level: "test-notification-level")
29+
update_response =
30+
client.category_set_user_notification(
31+
id: "test-id",
32+
notification_level: "test-notification-level",
33+
)
3034
puts update_response

examples/change_topic_status.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
# frozen_string_literal: true
2-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3-
require File.expand_path('../../lib/discourse_api', __FILE__)
2+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3+
require File.expand_path("../../lib/discourse_api", __FILE__)
44

55
config = DiscourseApi::ExampleHelper.load_yml
66

7-
client = DiscourseApi::Client.new(config['host'] || 'http://localhost:3000')
8-
client.api_key = config['api_key'] || "YOUR_API_KEY"
9-
client.api_username = config['api_username'] || "YOUR_USERNAME"
7+
client = DiscourseApi::Client.new(config["host"] || "http://localhost:3000")
8+
client.api_key = config["api_key"] || "YOUR_API_KEY"
9+
client.api_username = config["api_username"] || "YOUR_USERNAME"
1010

11-
response = client.create_topic(
11+
response =
12+
client.create_topic(
1213
category: 1,
1314
skip_validations: true,
1415
auto_track: false,
1516
title: "Concert Master: A new way to choose",
16-
raw: "This is the raw markdown for my post"
17-
)
17+
raw: "This is the raw markdown for my post",
18+
)
1819

1920
# get topic_id from response
20-
topic_id = response['topic_id']
21+
topic_id = response["topic_id"]
2122

2223
##
2324
# available options (guessing from reading discourse source)
@@ -26,9 +27,9 @@
2627
##
2728

2829
# lock topic (note: api_username determines user that is performing action)
29-
params = { status: 'closed', enabled: true, api_username: "YOUR USERNAME/USERS USERNAME" }
30+
params = { status: "closed", enabled: true, api_username: "YOUR USERNAME/USERS USERNAME" }
3031
client.change_topic_status(topic_id, params)
3132

3233
# unlock topic (note: api_username determines user that is performing action)
33-
params = { status: 'closed', enabled: false, api_username: "YOUR USERNAME/USERS USERNAME" }
34+
params = { status: "closed", enabled: false, api_username: "YOUR USERNAME/USERS USERNAME" }
3435
client.change_topic_status(topic_id, params)

0 commit comments

Comments
 (0)