Skip to content

Commit ab6f19b

Browse files
dblockCopilot
andcommitted
Enforce exception message conventions with a separate lint bundle
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2a697df commit ab6f19b

17 files changed

Lines changed: 211 additions & 18 deletions

File tree

‎.github/workflows/lint.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ jobs:
44
rubocop:
55
name: RuboCop
66
runs-on: ubuntu-latest
7+
env:
8+
BUNDLE_GEMFILE: gemfiles/lint.gemfile
79
steps:
810
- name: Checkout
911
uses: actions/checkout@v7
1012
- name: Set up Ruby
1113
uses: ruby/setup-ruby@v1
1214
with:
15+
ruby-version: '3.3'
16+
bundler: latest
1317
bundler-cache: true
1418
- run: bundle exec rubocop

‎.rubocop.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ require:
55
- rubocop-rake
66
- rubocop-rspec
77

8+
plugins:
9+
- rubocop-exception_messages
10+
811
AllCops:
912
TargetRubyVersion: 2.7
1013
NewCops: enable

‎.rubocop_todo.yml‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,40 @@
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9+
# Existing offenses introduced by the separate modern lint bundle.
10+
Layout/EmptyLinesAfterModuleInclusion:
11+
Exclude:
12+
- 'lib/slack/web/api/mixins/conversations.id.rb'
13+
- 'lib/slack/web/api/mixins/users.id.rb'
14+
15+
Naming/PredicateMethod:
16+
Exclude:
17+
- 'lib/slack/events/request.rb'
18+
- 'lib/slack/utils/security.rb'
19+
20+
Style/DirectiveScope:
21+
Exclude:
22+
- 'lib/slack/utils/security.rb'
23+
24+
Style/FetchEnvVar:
25+
Exclude:
26+
- 'examples/files_upload_v2/files_upload_v2.rb'
27+
- 'examples/hi_web/hi.rb'
28+
- 'examples/new_ticket/new_ticket.rb'
29+
- 'examples/oauth_v2/oauth_v2.rb'
30+
- 'lib/slack/events/config.rb'
31+
32+
Style/RedundantConstantBase:
33+
Exclude:
34+
- 'spec/slack/web/client_spec.rb'
35+
- 'spec/slack/web/faraday/response/raise_error_spec.rb'
36+
37+
Style/SuperWithArgsParentheses:
38+
Exclude:
39+
- 'lib/slack/web/api/errors/server_error.rb'
40+
- 'lib/slack/web/api/errors/slack_error.rb'
41+
- 'lib/slack/web/api/errors/too_many_requests_error.rb'
42+
943
# Offense count: 1
1044
# This cop supports unsafe auto-correction (--auto-correct-all).
1145
Lint/NonDeterministicRequireOrder:

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### 3.3.0 (Next)
22

3+
* Enforce consistent exception messages with rubocop-exception_messages in a separate Ruby 3.2+ lint bundle - [@dblock](https://github.com/dblock).
34
* [#602](https://github.com/slack-ruby/slack-ruby-client/pull/602): Make gli an optional dependency; only the `slack` command-line client needs it - [@corsonknowles](https://github.com/corsonknowles).
45
* [#591](https://github.com/slack-ruby/slack-ruby-client/pull/591): Generate AI CHANGELOG entries and PR summaries for automated API update PRs, lock simplecov below 1.1.0 to avoid breaking Coveralls - [@dblock](https://github.com/dblock).
56
* [#590](https://github.com/slack-ruby/slack-ruby-client/pull/590): Add entity.acknowledgeCommentAction and entity.presentComments methods - [@slack-ruby-ci-bot](https://github.com/apps/slack-ruby-ci-bot).

‎CONTRIBUTING.md‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,16 @@ We definitely appreciate pull requests that highlight or reproduce a problem, ev
5959

6060
Implement your feature or bug fix.
6161

62-
Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop). Run `bundle exec rubocop` and fix any style issues highlighted, auto-correct issues when possible with `bundle exec rubocop -a`. To silence generally ignored issues, including line lengths or code complexity metrics, run `bundle exec rubocop --auto-gen-config`.
62+
Ruby style is enforced with [RuboCop](https://github.com/rubocop/rubocop), including [exception message conventions](https://github.com/dblock/rubocop-exception_messages). Lint dependencies use a separate bundle requiring Ruby 3.2+ so tests can continue running on older supported Ruby versions.
63+
64+
```bash
65+
BUNDLE_GEMFILE=gemfiles/lint.gemfile bundle install
66+
BUNDLE_GEMFILE=gemfiles/lint.gemfile bundle exec rubocop
67+
```
68+
69+
Fix any style issues highlighted, auto-correcting safe issues with `BUNDLE_GEMFILE=gemfiles/lint.gemfile bundle exec rubocop -a`. Exception message corrections require `-A`; review them and update message expectations in tests. To regenerate the baseline for generally ignored issues, including line lengths or code complexity metrics, run `BUNDLE_GEMFILE=gemfiles/lint.gemfile bundle exec rubocop --auto-gen-config`.
70+
71+
On Ruby 3.2+, `bundle exec rake rubocop` also runs the separate lint bundle. The default `bundle exec rake` runs tests only; CI runs lint separately.
6372

6473
Make sure that `bundle exec rake` completes without errors.
6574

‎Gemfile‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ group :test do
1818
gem 'racc'
1919
gem 'rake', '~> 13'
2020
gem 'rspec'
21-
gem 'rubocop', '1.26.1' # Lock to specific version to avoid breaking cops/changes
22-
gem 'rubocop-performance'
23-
gem 'rubocop-rake'
24-
gem 'rubocop-rspec'
2521
# Lock below 1.1.0, which started writing float timestamps to
2622
# coverage/.resultset.json, breaking coverallsapp/github-action's parser
2723
# (coverallsapp/github-action#269, coverallsapp/coverage-reporter#191).

‎Rakefile‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
1212
spec.pattern = FileList['spec/**/*_spec.rb']
1313
end
1414

15-
require 'rubocop/rake_task'
16-
RuboCop::RakeTask.new
15+
desc 'Run RuboCop using the separate lint bundle (Ruby 3.2+).'
16+
task :rubocop do
17+
Bundler.with_unbundled_env do
18+
sh({ 'BUNDLE_GEMFILE' => File.expand_path('gemfiles/lint.gemfile', __dir__) }, 'bundle', 'exec', 'rubocop')
19+
end
20+
end
1721

18-
task default: %i[spec rubocop]
22+
task default: :spec
1923

2024
load 'tasks/git.rake'
2125
load 'tasks/web.rake'

‎gemfiles/lint.gemfile‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
5+
ruby '>= 3.2'
6+
7+
gem 'rubocop', '~> 1.72'
8+
gem 'rubocop-exception_messages', '~> 0.2.0', require: false
9+
gem 'rubocop-performance', '1.19.1'
10+
gem 'rubocop-rake', '0.6.0'
11+
gem 'rubocop-rspec', '2.11.1'

‎gemfiles/lint.gemfile.lock‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
ast (2.4.3)
5+
json (3.0.2)
6+
language_server-protocol (3.17.0.6)
7+
lint_roller (1.1.0)
8+
parallel (2.3.0)
9+
parser (3.3.12.0)
10+
ast (~> 2.4.1)
11+
racc
12+
prism (1.9.0)
13+
racc (1.8.1)
14+
rainbow (3.1.1)
15+
regexp_parser (2.13.1)
16+
rubocop (1.91.0)
17+
json (>= 2.3)
18+
language_server-protocol (~> 3.17.0.2)
19+
lint_roller (~> 1.1.0)
20+
parallel (>= 1.10)
21+
parser (>= 3.3.0.2)
22+
rainbow (>= 2.2.2, < 4.0)
23+
regexp_parser (>= 2.9.3, < 3.0)
24+
rubocop-ast (>= 1.49.0, < 2.0)
25+
ruby-progressbar (~> 1.7)
26+
unicode-display_width (>= 2.4.0, < 4.0)
27+
rubocop-ast (1.50.0)
28+
parser (>= 3.3.7.2)
29+
prism (~> 1.7)
30+
rubocop-exception_messages (0.2.0)
31+
lint_roller (~> 1.1)
32+
rubocop (~> 1.72)
33+
rubocop-performance (1.19.1)
34+
rubocop (>= 1.7.0, < 2.0)
35+
rubocop-ast (>= 0.4.0)
36+
rubocop-rake (0.6.0)
37+
rubocop (~> 1.0)
38+
rubocop-rspec (2.11.1)
39+
rubocop (~> 1.19)
40+
ruby-progressbar (1.13.0)
41+
unicode-display_width (3.3.0)
42+
unicode-emoji (~> 4.3)
43+
unicode-emoji (4.3.0)
44+
45+
PLATFORMS
46+
arm64-darwin-23
47+
ruby
48+
x86_64-linux
49+
50+
DEPENDENCIES
51+
rubocop (~> 1.72)
52+
rubocop-exception_messages (~> 0.2.0)
53+
rubocop-performance (= 1.19.1)
54+
rubocop-rake (= 0.6.0)
55+
rubocop-rspec (= 2.11.1)
56+
57+
CHECKSUMS
58+
ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
59+
bundler (4.0.21) sha256=7cbf5499b426076aa16c8d28a59e4c2c3aad5a438402abcd961f0119f29f1dd0
60+
json (3.0.2) sha256=8e6d7e7b11384c21230430cef90b71f14849a34a1f4452796670f7c981bd19df
61+
language_server-protocol (3.17.0.6) sha256=5ef2c0c138f8267e1bc631d3328347d354f96724b0af22f2c79516120443b7f0
62+
lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
63+
parallel (2.3.0) sha256=f75a3e904101ce6a1ccb6b8dc800cbafd42166d83330192438dcf29395167a6f
64+
parser (3.3.12.0) sha256=21a6d7f755d5a24dfbdc6e6b772e4e879a52e7631a88bc5a3a134606052c9828
65+
prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85
66+
racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f
67+
rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a
68+
regexp_parser (2.13.1) sha256=5aedb6b7c35688f51e86eef17a15374dfd287c83f4ca644b2c5f3ec50a33b44b
69+
rubocop (1.91.0) sha256=9c82b7bf391c5d7e3798c5b9996e22a1fe3bd7468e351dfdeb96140c058296d0
70+
rubocop-ast (1.50.0) sha256=b9ca88300da0803ee222ad20cdb30494c0a784eed06fdc35d254b06d662788db
71+
rubocop-exception_messages (0.2.0) sha256=67bf465f442ccea99839875f9d43e40303c8751dcd8e42be199b0ccc1cb605dc
72+
rubocop-performance (1.19.1) sha256=52664172d944eb45d478ed6d04c8b02c36cf0ee15726fabb6c90a95ca5cdfadf
73+
rubocop-rake (0.6.0) sha256=56b6f22189af4b33d4f4e490a555c09f1281b02f4d48c3a61f6e8fe5f401d8db
74+
rubocop-rspec (2.11.1) sha256=0398cf77ef892e3aeda104f1d67855d00f90a42a9ba788a31896a1f0df4c6c47
75+
ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
76+
unicode-display_width (3.3.0) sha256=4b7aa66a4b11db50f6f7e98411215cd0dd10eaecb665d36eec5bcacb3fa0b613
77+
unicode-emoji (4.3.0) sha256=11c02fa73290378c066bb0562cd4c87d8e1b706fbbe0059ca12746a4244de8ce
78+
79+
RUBY VERSION
80+
ruby 3.3.5
81+
82+
BUNDLED WITH
83+
4.0.21

‎lib/slack/web/api/helpers/files.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ def files_upload_v2(params = {})
4545

4646
files_to_upload.each_with_index do |file, index|
4747
%i[filename content].each do |param|
48-
raise ArgumentError, "Required argument :#{param} missing in file (#{index})" if file[param].nil?
48+
raise ArgumentError, "required argument :`#{param}` missing in file (`#{index}`)" if file[param].nil?
4949
end
5050
end
5151

5252
channel_params = %i[channel channels channel_id].map { |param| params[param] }.compact
53-
raise ArgumentError, 'Only one of :channel, :channels, or :channel_id is required' if channel_params.size > 1
53+
raise ArgumentError, 'only one of :channel, :channels, or :channel_id is required' if channel_params.size > 1
5454

5555
complete_upload_request_params = params.slice(:initial_comment, :blocks, :thread_ts)
5656

0 commit comments

Comments
 (0)