rubocop-openproject 0.7.0 → 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: b6399b37d75f31159de26fc061439ab6107f3621da14770ab2e3f4a263e4748e
4
- data.tar.gz: c0bc045863a214c19a10fe29e4b23edd6d60f3598158f665fdfb4fefba851946
3
+ metadata.gz: 773446caa5319de0f293fec551495d72a218b7613cf7ec376eb1c24197bd7fa9
4
+ data.tar.gz: e9e120a7042a5ea1030132e5cf1061b49d5e63d90745bd6bf7ba45eab3ceef12
5
5
  SHA512:
6
- metadata.gz: 5089a09294d79954f16b4fe511fd6b3aabe57b9272ebf41fa4a376feb7a6fcf8c2872b072fd6e3c7eb8493484e0e5b3eb2dc88f2bbfb964fa5fb67f0cdd8e5d8
7
- data.tar.gz: 46759bc28c398aeefb4fb18305dd9494056a5296a859bb7789d4c37548b785a935a254f0cfcc98442cccceeb70fc5a788113316b3c58707dc0172506ab6462e0
6
+ metadata.gz: a953526a473bf41eb3bc64dea310dee30a82afadc8a161a682b5fefe220586d7ebc95c824298ba04394fed90602b0c02f2348b7a82655c0f27c6fed5222a24b8
7
+ data.tar.gz: 3a7d2453f0b72a95dbbd67d5da315774fc4fd877b091ddb3e28d407f66ef413f5c16467d91b8b6c96440e51f14fb6eec4992ad61ac96f5176a68ade1161a59e3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
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
+
14
+ ## 0.7.1
15
+
16
+ ### Patch Changes
17
+
18
+ - 2e41102: Widen `OpenProject/UseEffectiveTypeForConfiguration` to catch safe navigation and the derived
19
+ pattern readers. The cop only defined `on_send`, so `represented.type&.attribute_groups` parsed
20
+ as a `csend` and slipped through entirely — which is how the whole work package schema
21
+ representer read its form configuration off the root while the cop was enabled. Both sides of
22
+ the call are now matched as `send` or `csend`. `enabled_patterns` and
23
+ `replacement_pattern_defined_for?` join `CONFIGURATION_METHODS`: both resolve through
24
+ `patterns`, which a variant can own independently, so they are as variant-specific as the
25
+ aspect readers already listed.
26
+
27
+ Expect new offenses in consumers wherever a configuration aspect was read off `type` with `&.`.
28
+
3
29
  ## 0.7.0
4
30
 
5
31
  ### Minor 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
@@ -34,6 +34,10 @@ module RuboCop
34
34
  # # bad — inside WorkPackage itself
35
35
  # type.statuses(include_default: true)
36
36
  #
37
+ # # bad — safe navigation on either side reads the root just the same
38
+ # represented.type&.attribute_groups
39
+ # model&.type.enabled_patterns
40
+ #
37
41
  # # good
38
42
  # work_package.effective_type.attribute_groups
39
43
  #
@@ -51,7 +55,9 @@ module RuboCop
51
55
  "the family's root, so this ignores the variant the project resolves to."
52
56
 
53
57
  # Configuration aspects, per Type::ConfigurationLink::ASPECTS and the readers
54
- # Type::ConfigurationLinkable resolves through the link chain.
58
+ # Type::ConfigurationLinkable resolves through the link chain, plus the derived readers
59
+ # that sit on top of one — `enabled_patterns` and `replacement_pattern_defined_for?`
60
+ # both resolve through `patterns` and are just as variant-specific.
55
61
  CONFIGURATION_METHODS = %i[
56
62
  artefact_export_enabled?
57
63
  artefact_export_mode
@@ -59,18 +65,22 @@ module RuboCop
59
65
  custom_field_ids
60
66
  custom_fields
61
67
  description
68
+ enabled_patterns
62
69
  export_templates_disabled
63
70
  export_templates_order
64
71
  patterns
65
72
  project_custom_field_type_mappings
73
+ replacement_pattern_defined_for?
66
74
  statuses
67
75
  workflows
68
76
  ].freeze
69
77
 
70
78
  RESTRICT_ON_SEND = CONFIGURATION_METHODS
71
79
 
80
+ # Both node types on both sides: `type&.attribute_groups` reads the root exactly like
81
+ # `type.attribute_groups` does, and the mistake is written with `&.` at least as often.
72
82
  def_node_matcher :type_call?, <<~PATTERN
73
- (send _ :type)
83
+ ({send csend} _ :type)
74
84
  PATTERN
75
85
 
76
86
  def on_send(node)
@@ -78,6 +88,7 @@ module RuboCop
78
88
 
79
89
  add_offense(node)
80
90
  end
91
+ alias on_csend on_send
81
92
  end
82
93
  end
83
94
  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.0"
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.0
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