Skip to content

Commit 65958a6

Browse files
committed
Fix rubocop offenses in Dangerfile
Apply Style/IfUnlessModifier and Performance/RegexpMatch fixes. Disable Style/SignalException for Danger's `fail` DSL method.
1 parent f7113a2 commit 65958a6

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

Dangerfile

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,25 @@
55
has_app_changes = !git.modified_files.grep(/lib/).empty?
66
has_spec_changes = !git.modified_files.grep(/spec/).empty?
77

8-
if has_app_changes && !has_spec_changes
9-
warn("There're library changes, but not tests. That's OK as long as you're refactoring existing code.", sticky: false)
10-
end
8+
warn("There're library changes, but not tests. That's OK as long as you're refactoring existing code.", sticky: false) if has_app_changes && !has_spec_changes
119

12-
if !has_app_changes && has_spec_changes
13-
message('We really appreciate pull requests that demonstrate issues, even without a fix. That said, the next step is to try and fix the failing tests!', sticky: false)
14-
end
10+
message('We really appreciate pull requests that demonstrate issues, even without a fix. That said, the next step is to try and fix the failing tests!', sticky: false) if !has_app_changes && has_spec_changes
1511

1612
# Simplified changelog check (replaces danger-changelog plugin which requires github.* methods)
1713
# Note: toc.check! from danger-toc plugin removed (not essential for CI)
1814
has_changelog_changes = git.modified_files.include?('CHANGELOG.md') || git.added_files.include?('CHANGELOG.md')
19-
if has_app_changes && !has_changelog_changes
20-
warn('Please update CHANGELOG.md with a description of your changes.', sticky: false)
21-
end
15+
warn('Please update CHANGELOG.md with a description of your changes.', sticky: false) if has_app_changes && !has_changelog_changes
2216

2317
(git.modified_files + git.added_files - %w[Dangerfile]).each do |file|
2418
next unless File.file?(file)
2519

2620
contents = File.read(file)
21+
# rubocop:disable Style/SignalException -- `fail` is Danger's DSL method, not Kernel#fail
2722
if file.start_with?('spec')
28-
fail("`xit` or `fit` left in tests (#{file})") if contents =~ /^\w*[xf]it/
29-
fail("`fdescribe` left in tests (#{file})") if contents =~ /^\w*fdescribe/
23+
fail("`xit` or `fit` left in tests (#{file})") if /^\w*[xf]it/.match?(contents)
24+
fail("`fdescribe` left in tests (#{file})") if /^\w*fdescribe/.match?(contents)
3025
end
26+
# rubocop:enable Style/SignalException
3127
end
3228

3329
# Output JSON report for GitHub Actions workflow_run to post as PR comment

0 commit comments

Comments
 (0)