rubocop-discourse 3.16.0 → 3.18.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: f4d1f21065c28440ac92a435fe615ba1aa71be866decb87a34569b5035b6ab28
4
- data.tar.gz: 40738677dd38eb78850b649f223c5e70f86a487821d28ba66ab8e25fb7fe155c
3
+ metadata.gz: 537fcf2646cf9fec96730f2ad390cbeaded946953aa3bcf1a629528815ddfc4e
4
+ data.tar.gz: ce0b6d8651f55a1e9f42aa6df409fe2a65ce1dbeba9477f76688615f6607304f
5
5
  SHA512:
6
- metadata.gz: 161fab4a916b845fe201a36a7b5cdc6d329a25f4069bdaab7a62a9c0dcd9ed36e0ef3984698de67edf1aac6043351b2201a43550470fff3c86b3e531e132ab0e
7
- data.tar.gz: 4a474ac36e50368a4a62fc6e1dba557f2294c9f498a53b28b589eed150a7abc2917a60ba71943d5821c32148876a309f3e4b3ca6eeee1dab9b40fa44d18c45f8
6
+ metadata.gz: 8bbc6c84d341cf7d1809bbcdbe6c8ee6ca095912e46031a159453695a828486d6339059e59558bf4978a9ce8762bcba3a422ce71508b4c6ca1f68c778fad2fdb
7
+ data.tar.gz: ca67fb3089276d717be47d2f6dbfa6092192dc68165764822d3f8e8a6598144dfeaab653fdf4cb923b3a96111e88be56bfba3cbb73d2596207dc1e1eddbf331c
data/config/default.yml CHANGED
@@ -94,3 +94,6 @@ Discourse/Services/GroupKeywords:
94
94
 
95
95
  Discourse/Services/EmptyLinesAroundBlocks:
96
96
  Enabled: true
97
+
98
+ Discourse/Services/MutableAttributeDefault:
99
+ Enabled: true
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Discourse
6
+ module Services
7
+ # Wrap mutable `attribute` defaults in a proc — `ActiveModel::Attributes`
8
+ # shares the literal across instances, so mutations leak between calls.
9
+ # `:array`-typed attributes are exempt; the type dups on read.
10
+ #
11
+ # @example
12
+ # # bad
13
+ # options do
14
+ # attribute :overrides, default: {}
15
+ # attribute :ids, default: [1, 2]
16
+ # end
17
+ #
18
+ # # good
19
+ # options do
20
+ # attribute :overrides, default: -> { {} }
21
+ # attribute :ids, default: -> { [1, 2] }
22
+ # attribute :tags, :array, default: [] # :array dups per read
23
+ # end
24
+ #
25
+ class MutableAttributeDefault < Base
26
+ extend AutoCorrector
27
+
28
+ MSG =
29
+ "Mutable `default: %<source>s` is shared across all instances; wrap it in a proc: `-> { %<source>s }`."
30
+ RESTRICT_ON_SEND = %i[attribute].freeze
31
+
32
+ def_node_matcher :service_include?, <<~MATCHER
33
+ (class _ _
34
+ {
35
+ (begin <(send nil? :include (const (const nil? :Service) :Base)) ...>)
36
+ <(send nil? :include (const (const nil? :Service) :Base)) ...>
37
+ }
38
+ )
39
+ MATCHER
40
+
41
+ def_node_matcher :mutable_default, <<~PATTERN
42
+ (send nil? :attribute _ ... (hash <(pair (sym :default) ${hash array}) ...>))
43
+ PATTERN
44
+
45
+ def_node_matcher :array_typed?, <<~PATTERN
46
+ (send nil? :attribute _ (sym :array) ...)
47
+ PATTERN
48
+
49
+ def on_class(node)
50
+ @service = true if service_include?(node)
51
+ end
52
+
53
+ def on_send(node)
54
+ return unless @service
55
+ return if array_typed?(node)
56
+ default = mutable_default(node)
57
+ return unless default
58
+
59
+ source = default.source
60
+ add_offense(default, message: format(MSG, source: source)) do |corrector|
61
+ corrector.replace(default, "-> { #{source} }")
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Discourse
5
- VERSION = "3.16.0"
5
+ VERSION = "3.18.0"
6
6
  end
7
7
  end
data/rubocop-capybara.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  plugins:
2
2
  - rubocop-capybara
3
3
 
4
- Capybara/CurrentPathExpectation:
4
+ Capybara/RSpec/CurrentPathExpectation:
5
5
  Enabled: true
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
33
33
  s.add_runtime_dependency "rubocop-discourse-base", ">= 1.0.0"
34
34
  s.add_runtime_dependency "rubocop-rspec", ">= 3.0.1"
35
35
  s.add_runtime_dependency "rubocop-factory_bot", ">= 2.27.0"
36
- s.add_runtime_dependency "rubocop-capybara", ">= 2.22.0"
36
+ s.add_runtime_dependency "rubocop-capybara", ">= 2.23.0"
37
37
  s.add_runtime_dependency "rubocop-rails", ">= 2.30.3"
38
38
  s.add_runtime_dependency "rubocop-rspec_rails", ">= 2.31.0"
39
39
  s.add_runtime_dependency "lint_roller", ">= 1.1.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-discourse
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.16.0
4
+ version: 3.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Discourse Team
@@ -71,14 +71,14 @@ dependencies:
71
71
  requirements:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: 2.22.0
74
+ version: 2.23.0
75
75
  type: :runtime
76
76
  prerelease: false
77
77
  version_requirements: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: 2.22.0
81
+ version: 2.23.0
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: rubocop-rails
84
84
  requirement: !ruby/object:Gem::Requirement
@@ -179,6 +179,7 @@ files:
179
179
  - lib/rubocop/cop/discourse/plugins/use_require_relative.rb
180
180
  - lib/rubocop/cop/discourse/services/empty_lines_around_blocks.rb
181
181
  - lib/rubocop/cop/discourse/services/group_keywords.rb
182
+ - lib/rubocop/cop/discourse/services/mutable_attribute_default.rb
182
183
  - lib/rubocop/cop/discourse/time_eq_matcher.rb
183
184
  - lib/rubocop/cop/discourse_cops.rb
184
185
  - lib/rubocop/discourse/plugin.rb