rubocop-openproject 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddc09cf55b857f7ce9d1f944be04ad89fca8733ed2ee571e7a21e61ee0b93531
4
- data.tar.gz: 597940571a0def133a1e4c22ba02fc5f277b4e69b43e72be0ae8e63ad2b3959b
3
+ metadata.gz: 773446caa5319de0f293fec551495d72a218b7613cf7ec376eb1c24197bd7fa9
4
+ data.tar.gz: e9e120a7042a5ea1030132e5cf1061b49d5e63d90745bd6bf7ba45eab3ceef12
5
5
  SHA512:
6
- metadata.gz: 7b4b3c182974ae3030781217c2a1c37abdff29b21398a1b9644806c36d55b81ec6ec1d22af6d7e44dead45a5ce3950d394a73ab361d15c15834562a67a443296
7
- data.tar.gz: cefcaa216a26645a8ca75e6caedae544462cd411bd5b298d0d80b24e0502680075c5bf3ad4bf4b8e3e8d3054ab416c14408b87af9a841eb3950656e488ef3aef
6
+ metadata.gz: a953526a473bf41eb3bc64dea310dee30a82afadc8a161a682b5fefe220586d7ebc95c824298ba04394fed90602b0c02f2348b7a82655c0f27c6fed5222a24b8
7
+ data.tar.gz: 3a7d2453f0b72a95dbbd67d5da315774fc4fd877b091ddb3e28d407f66ef413f5c16467d91b8b6c96440e51f14fb6eec4992ad61ac96f5176a68ade1161a59e3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # rubocop-openproject
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - cb825c6: Add `OpenProject/NoConditionalPatchGemVersion` cop to catch `patch_gem_version` calls wrapped in a
8
+ condition. The version check inside `patch_gem_version` is what makes the application fail to boot
9
+ on CI when a patched gem is upgraded. The OpenTelemetry grape patch was guarded by
10
+ `defined?(OpenTelemetry::Instrumentation::Grape::EventHandler)`, which is only defined when
11
+ OpenTelemetry is enabled, so CI skipped the check and the gem upgrade went unnoticed. Conditions
12
+ belong inside the block, around the patch itself.
13
+
3
14
  ## 0.7.1
4
15
 
5
16
  ### Patch Changes
data/config/default.yml CHANGED
@@ -8,6 +8,11 @@ OpenProject/NoDoEndBlockWithRSpecCapybaraMatcherInExpect:
8
8
  Enabled: true
9
9
  VersionAdded: '0.1.0'
10
10
 
11
+ OpenProject/NoConditionalPatchGemVersion:
12
+ Description: 'Call `patch_gem_version` unconditionally so its version check runs on CI.'
13
+ Enabled: true
14
+ VersionAdded: '0.8.0'
15
+
11
16
  OpenProject/NoNotImplementedError:
12
17
  Description: 'Do not raise `NotImplementedError` to signal an unimplemented abstract method.'
13
18
  Enabled: true
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module OpenProject
6
+ # Checks that `patch_gem_version` is not wrapped in a condition.
7
+ #
8
+ # `patch_gem_version` raises when the patched gem is newer than the version the
9
+ # patch was written for, which makes the application fail to boot on CI after a
10
+ # gem upgrade. A condition around the call (e.g. `defined?` on a constant of a
11
+ # gem that is only required in production) skips that version check as well,
12
+ # so an outdated patch goes unnoticed. Move the condition inside the block.
13
+ #
14
+ # @example
15
+ # # bad
16
+ # if defined?(SomeGem::Thing)
17
+ # OpenProject::Patches.patch_gem_version "some-gem", "1.2.3" do
18
+ # SomeGem::Thing.prepend Patch
19
+ # end
20
+ # end
21
+ #
22
+ # # bad
23
+ # OpenProject::Patches.patch_gem_version("some-gem", "1.2.3") { apply } if Rails.env.local?
24
+ #
25
+ # # good
26
+ # OpenProject::Patches.patch_gem_version "some-gem", "1.2.3" do
27
+ # SomeGem::Thing.prepend Patch if defined?(SomeGem::Thing)
28
+ # end
29
+ #
30
+ class NoConditionalPatchGemVersion < Base
31
+ MSG = "`patch_gem_version` must run unconditionally so CI catches gem upgrades. " \
32
+ "Move the condition inside the block."
33
+
34
+ RESTRICT_ON_SEND = %i[patch_gem_version].freeze
35
+
36
+ def on_send(node)
37
+ return unless node.each_ancestor(:if, :case, :and, :or).any?
38
+
39
+ add_offense(node)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "open_project/add_preview_for_view_component"
4
+ require_relative "open_project/no_conditional_patch_gem_version"
4
5
  require_relative "open_project/no_not_implemented_error"
5
6
  require_relative "open_project/no_params_in_work_package_where_id"
6
7
  require_relative "open_project/use_service_result_factory_methods"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module OpenProject
5
- VERSION = "0.7.1"
5
+ VERSION = "0.8.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-openproject
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenProject GmbH
@@ -40,6 +40,7 @@ files:
40
40
  - config/default.yml
41
41
  - lib/rubocop-openproject.rb
42
42
  - lib/rubocop/cop/open_project/add_preview_for_view_component.rb
43
+ - lib/rubocop/cop/open_project/no_conditional_patch_gem_version.rb
43
44
  - lib/rubocop/cop/open_project/no_not_implemented_error.rb
44
45
  - lib/rubocop/cop/open_project/no_params_in_work_package_where_id.rb
45
46
  - lib/rubocop/cop/open_project/no_sleep_in_feature_specs.rb