Skip to content

Commit bc56eea

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 bc56eea

26 files changed

Lines changed: 145 additions & 53 deletions

File tree

‎.github/workflows/lint.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ jobs:
1010
- name: Set up Ruby
1111
uses: ruby/setup-ruby@v1
1212
with:
13+
ruby-version: '3.3'
14+
bundler: latest
1315
bundler-cache: true
1416
- 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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
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+
# Remaining offenses after safe autocorrection with modern RuboCop.
10+
Naming/PredicateMethod:
11+
Exclude:
12+
- 'lib/slack/events/request.rb'
13+
- 'lib/slack/utils/security.rb'
14+
15+
Style/DirectiveScope:
16+
Exclude:
17+
- 'lib/slack/utils/security.rb'
18+
919
# Offense count: 1
1020
# This cop supports unsafe auto-correction (--auto-correct-all).
1121
Lint/NonDeterministicRequireOrder:

‎AGENTS.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Contributor guidance
2+
3+
- Use the main Gemfile; lint dependencies are included only on Ruby 3.2+. Preserve the supported-Ruby test matrix and run RuboCop separately on Ruby 3.3 in CI.
4+
- Run `bundle exec rake` for tests and `bundle exec rubocop` for lint. When upgrading lint tooling, run `bundle exec rubocop -a` once, review corrections, and baseline only remaining unrelated offenses.
5+
- Exception message corrections can change public error strings. Update matching specs, including handwritten specs under `spec/slack/web/api/endpoints/custom/`.
6+
- Add a CHANGELOG entry under the next release with the pull request number and contributor attribution. Keep `Your contribution here`. After opening a PR, update the entry with its assigned number.
7+
- Generated endpoints and specs come from `bundle exec rake slack:api:update`. Persist endpoint changes in `lib/slack/web/api/patches/` and verify regeneration applies the patch. Do not edit the API-reference submodule or include existing submodule changes unless requested.

‎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+
* [#603](https://github.com/slack-ruby/slack-ruby-client/pull/603): Enforce consistent exception messages with rubocop-exception_messages and run lint separately from the test matrix - [@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). The main Gemfile includes lint dependencies only on Ruby 3.2+ so tests can continue running on older supported Ruby versions.
63+
64+
```bash
65+
bundle install
66+
bundle exec rubocop
67+
```
68+
69+
Fix any style issues highlighted, auto-correcting safe issues with `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 exec rubocop --auto-gen-config`.
70+
71+
On Ruby 3.2+, `bundle exec rake rubocop` also runs lint. The default `bundle exec rake` runs tests only; CI runs lint separately on Ruby 3.3.
6372

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

‎Gemfile‎

Lines changed: 10 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).
@@ -31,3 +27,13 @@ group :test do
3127
gem 'vcr'
3228
gem 'webmock'
3329
end
30+
31+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.2')
32+
group :lint do
33+
gem 'rubocop', '~> 1.72'
34+
gem 'rubocop-exception_messages', '~> 0.2.0', require: false
35+
gem 'rubocop-performance', '1.19.1'
36+
gem 'rubocop-rake', '0.6.0'
37+
gem 'rubocop-rspec', '2.11.1'
38+
end
39+
end

‎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 (Ruby 3.2+).'
16+
task :rubocop do
17+
abort 'RuboCop requires Ruby 3.2 or newer' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.2')
1718

18-
task default: %i[spec rubocop]
19+
sh 'bundle exec rubocop'
20+
end
21+
22+
task default: :spec
1923

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

‎examples/files_upload_v2/files_upload_v2.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'securerandom'
44

55
Slack.configure do |config|
6-
config.token = ENV['SLACK_API_TOKEN']
6+
config.token = ENV.fetch('SLACK_API_TOKEN', nil)
77
raise 'Missing ENV[SLACK_API_TOKEN]!' unless config.token
88
end
99

‎examples/hi_web/hi.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'slack-ruby-client'
33

44
Slack.configure do |config|
5-
config.token = ENV['SLACK_API_TOKEN']
5+
config.token = ENV.fetch('SLACK_API_TOKEN', nil)
66
raise 'Missing ENV[SLACK_API_TOKEN]!' unless config.token
77
end
88

0 commit comments

Comments
 (0)