rubocop-discourse 3.8.1 → 3.8.2

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: a6b21abdd18093c8fdfbcf7811f0bb520da340cbd12b70a4f47bb996d960e9c8
4
- data.tar.gz: dd1e656a4ce9b42ae87ea61717db604d102c693e5bed2b9d56b9ac1b75e9b32f
3
+ metadata.gz: d99caa8cf2d3885ef79b260a4b7747d7060a4fc57bf4b72d10627b7c076f1460
4
+ data.tar.gz: 92bb54e600d4875a6ba0f21a003438292e2f6c15874f8e170677e9721d1cb3ba
5
5
  SHA512:
6
- metadata.gz: 455fa288eb139814eb3deb1ad92495ff3822ab055b4584f44da708be10958049f10e7023d3a2df0080861979aa1302d84e00688bb116edff957c6bdc56de930c
7
- data.tar.gz: 90ada24a89b5649487653c5a9c40b0ad7199b839c92a3388ecf8b5b2e71bb4e73381a1d6ca511b2cf78b0a5257b31d49ac2f700041a91710a70253d4e9f83c38
6
+ metadata.gz: 2a589b65b0f8ef2948e9efbf061e9a022d5434f98f25644ff19c6c7ef6c37581c569f988af30894a80a16f0e4bf7c8611156ed6e1b480ad8a78f7ede2a160a4f
7
+ data.tar.gz: bd12917c2c595b37fda32e695ecdc3f513072b9d55c018b6e31c07b62654c9dca299f8eadd2019ea8df43674c9a29643137f477dd633002649aee31aa3a80474
@@ -16,7 +16,7 @@ jobs:
16
16
  - name: Setup ruby
17
17
  uses: ruby/setup-ruby@v1
18
18
  with:
19
- ruby-version: '3.2'
19
+ ruby-version: "3.3"
20
20
  bundler-cache: true
21
21
 
22
22
  - name: Rubocop
@@ -44,7 +44,7 @@ module RuboCop
44
44
  # index_posts_on_image_upload_id ON posts USING btree (image_upload_id)
45
45
  # SQL
46
46
  # end
47
- class NoAddReferenceOrAliasesActiveRecordMigration < Cop
47
+ class NoAddReferenceOrAliasesActiveRecordMigration < Base
48
48
  MSG = <<~MSG
49
49
  AR methods add_reference, add_belongs_to, t.references, and t.belongs_to are
50
50
  high-risk for large tables and have too many background magic operations.
@@ -74,7 +74,7 @@ module RuboCop
74
74
  using_add_reference?(node),
75
75
  using_add_belongs_to?(node),
76
76
  using_t_references?(node),
77
- using_t_belongs_to?(node)
77
+ using_t_belongs_to?(node),
78
78
  ].none?
79
79
  return
80
80
  end
@@ -13,7 +13,7 @@ module RuboCop
13
13
  # @example
14
14
  # # bad
15
15
  # Dir.chdir("test")
16
- class NoChdir < Cop
16
+ class NoChdir < Base
17
17
  MSG = "Chdir is not thread safe."
18
18
 
19
19
  def_node_matcher :using_dir_chdir?, <<-MATCHER
@@ -16,7 +16,7 @@ module RuboCop
16
16
  # it "works", type: :multisite do
17
17
  # do_something
18
18
  # end
19
- class NoDirectMultisiteManipulation < Cop
19
+ class NoDirectMultisiteManipulation < Base
20
20
  MSG =
21
21
  "Use `type: :multisite` example setting instead of modifying `Rails.configuration.multisite`."
22
22
 
@@ -11,9 +11,8 @@ module RuboCop
11
11
  #
12
12
  # # good
13
13
  # expect(response.parsed_body).to eq({})
14
- class NoJsonParseResponse < Cop
15
- MSG =
16
- "Use `response.parsed_body` instead of `JSON.parse(response.body)` in specs."
14
+ class NoJsonParseResponse < Base
15
+ MSG = "Use `response.parsed_body` instead of `JSON.parse(response.body)` in specs."
17
16
 
18
17
  def_node_matcher :json_parse_body?, <<-MATCHER
19
18
  (send
@@ -29,9 +28,7 @@ module RuboCop
29
28
  end
30
29
 
31
30
  def autocorrect(node)
32
- lambda do |corrector|
33
- corrector.replace(node.loc.expression, "response.parsed_body")
34
- end
31
+ lambda { |corrector| corrector.replace(node.loc.expression, "response.parsed_body") }
35
32
  end
36
33
  end
37
34
  end
@@ -23,7 +23,7 @@ module RuboCop
23
23
  # # x_multisite_spec.rb
24
24
  # describe "x", type: :multisite do
25
25
  # end
26
- class NoMixingMultisiteAndStandardSpecs < Cop
26
+ class NoMixingMultisiteAndStandardSpecs < Base
27
27
  MSG =
28
28
  "Do not mix multisite and standard specs. Consider moving multisite describes to a separate file."
29
29
 
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Discourse
6
- class NoMockingJobs < Cop
6
+ class NoMockingJobs < Base
7
7
  MSG =
8
8
  "Use the test helpers provided by Sidekiq instead of mocking `Jobs.expects(:enqueue)`."
9
9
 
@@ -12,7 +12,7 @@ module RuboCop
12
12
  #
13
13
  # # good
14
14
  # Nokogiri::HTML5.fragment("<p>test</p>")
15
- class NoNokogiriHtmlFragment < Cop
15
+ class NoNokogiriHtmlFragment < Base
16
16
  MSG = "Nokogiri::HTML.fragment is deprecated and should not be used."
17
17
 
18
18
  def_node_matcher :using_nokogiri_html_fragment?, <<-MATCHER
@@ -7,7 +7,7 @@ module RuboCop
7
7
  # migrations. The method is not thread safe and we run migrations
8
8
  # concurrently for multisites. Also, we don't encourage the use of
9
9
  # ActiveRecord methods in migrations and prefer to write SQL directly.
10
- class NoResetColumnInformationInMigrations < Cop
10
+ class NoResetColumnInformationInMigrations < Base
11
11
  MSG =
12
12
  "ActiveRecord::ModelSchema.reset_column_information is not thread-safe " \
13
13
  "and we run migrations concurrently on multisite clusters. Using this " \
@@ -11,7 +11,7 @@ module RuboCop
11
11
  #
12
12
  # # good
13
13
  # now = Time.zone.now
14
- class NoTimeNewWithoutArgs < Cop
14
+ class NoTimeNewWithoutArgs < Base
15
15
  MSG = "Use `Time.zone.now` instead of `Time.new` without arguments."
16
16
 
17
17
  def_node_matcher :time_new_without_args?, <<-MATCHER
@@ -25,9 +25,7 @@ module RuboCop
25
25
  end
26
26
 
27
27
  def autocorrect(node)
28
- lambda do |corrector|
29
- corrector.replace(node.loc.expression, "Time.zone.now")
30
- end
28
+ lambda { |corrector| corrector.replace(node.loc.expression, "Time.zone.now") }
31
29
  end
32
30
  end
33
31
  end
@@ -15,7 +15,7 @@ module RuboCop
15
15
  # # good
16
16
  # UrlHelper.encode("https://a%20a.com?a='a%22")
17
17
  # Addressable::URI.encode("https://a%20a.com?a='a%22")
18
- class NoURIEscapeEncode < Cop
18
+ class NoURIEscapeEncode < Base
19
19
  MSG =
20
20
  "URI.escape, URI.encode, URI.unescape, URI.decode are deprecated and should not be used."
21
21
 
@@ -40,7 +40,7 @@ module RuboCop
40
40
  using_uri_escape?(node),
41
41
  using_uri_encode?(node),
42
42
  using_uri_unescape?(node),
43
- using_uri_decode?(node)
43
+ using_uri_decode?(node),
44
44
  ].none?
45
45
  return
46
46
  end
@@ -25,7 +25,7 @@ module RuboCop
25
25
  # it "does X" do
26
26
  # end
27
27
  # end
28
- class OnlyTopLevelMultisiteSpecs < Cop
28
+ class OnlyTopLevelMultisiteSpecs < Base
29
29
  MSG = "Use `type: :multisite` only on a top-level `describe`"
30
30
 
31
31
  def on_block(node)
@@ -11,7 +11,7 @@ module RuboCop
11
11
  #
12
12
  # # good
13
13
  # expect(user.created_at).to eq_time(Time.zone.now)
14
- class TimeEqMatcher < Cop
14
+ class TimeEqMatcher < Base
15
15
  MSG = "Use eq_time when testing timestamps"
16
16
 
17
17
  def_node_matcher :using_eq_matcher_with_timestamp?, <<-MATCHER
@@ -29,9 +29,7 @@ module RuboCop
29
29
  end
30
30
 
31
31
  def autocorrect(node)
32
- lambda do |corrector|
33
- corrector.replace(node.children.last.loc.selector, "eq_time")
34
- end
32
+ lambda { |corrector| corrector.replace(node.children.last.loc.selector, "eq_time") }
35
33
  end
36
34
 
37
35
  private
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "rubocop-discourse"
5
- s.version = "3.8.1"
5
+ s.version = "3.8.2"
6
6
  s.summary = "Custom rubocop cops used by Discourse"
7
7
  s.authors = ["Discourse Team"]
8
8
  s.license = "MIT"
@@ -2,28 +2,27 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe RuboCop::Cop::Discourse::NoAddReferenceOrAliasesActiveRecordMigration,
6
- :config do
5
+ describe RuboCop::Cop::Discourse::NoAddReferenceOrAliasesActiveRecordMigration, :config do
7
6
  subject(:cop) { described_class.new(config) }
8
7
 
9
8
  let(:config) { RuboCop::Config.new }
10
9
 
11
10
  it "raises an offense if add_reference is used, with or without arguments" do
12
- inspect_source(<<~RUBY)
11
+ offenses = inspect_source(<<~RUBY)
13
12
  add_reference :posts, :users, foreign_key: true, null: false
14
13
  RUBY
15
- expect(cop.offenses.first.message).to match(described_class::MSG)
14
+ expect(offenses.first.message).to match(described_class::MSG)
16
15
  end
17
16
 
18
17
  it "raises an offense if add_belongs_to is used, with or without arguments" do
19
- inspect_source(<<~RUBY)
18
+ offenses = inspect_source(<<~RUBY)
20
19
  add_belongs_to :posts, :users, foreign_key: true, null: false
21
20
  RUBY
22
- expect(cop.offenses.first.message).to match(described_class::MSG)
21
+ expect(offenses.first.message).to match(described_class::MSG)
23
22
  end
24
23
 
25
24
  it "raises an offense if t.references, or any variable.references is used, with or without arguments" do
26
- inspect_source(<<~RUBY)
25
+ offenses = inspect_source(<<~RUBY)
27
26
  create_table do |t|
28
27
  t.references :topic, null: false
29
28
  end
@@ -31,12 +30,12 @@ describe RuboCop::Cop::Discourse::NoAddReferenceOrAliasesActiveRecordMigration,
31
30
  mytable.references :topic, null: false
32
31
  end
33
32
  RUBY
34
- expect(cop.offenses.count).to eq(2)
35
- expect(cop.offenses.first.message).to match(described_class::MSG)
33
+ expect(offenses.count).to eq(2)
34
+ expect(offenses.first.message).to match(described_class::MSG)
36
35
  end
37
36
 
38
37
  it "raises an offense if t.belongs_to, or any variable.belongs_to is used, with or without arguments" do
39
- inspect_source(<<~RUBY)
38
+ offenses = inspect_source(<<~RUBY)
40
39
  create_table do |t|
41
40
  t.belongs_to :topic, null: false
42
41
  end
@@ -44,7 +43,7 @@ describe RuboCop::Cop::Discourse::NoAddReferenceOrAliasesActiveRecordMigration,
44
43
  mytable.belongs_to :topic, null: false
45
44
  end
46
45
  RUBY
47
- expect(cop.offenses.count).to eq(2)
48
- expect(cop.offenses.first.message).to match(described_class::MSG)
46
+ expect(offenses.count).to eq(2)
47
+ expect(offenses.first.message).to match(described_class::MSG)
49
48
  end
50
49
  end
@@ -8,7 +8,7 @@ describe RuboCop::Cop::Discourse::NoMixingMultisiteAndStandardSpecs, :config do
8
8
  let(:config) { RuboCop::Config.new }
9
9
 
10
10
  it "raises an offense if there are multisite and standard top-level describes" do
11
- inspect_source(<<~RUBY)
11
+ offenses = inspect_source(<<~RUBY)
12
12
  RSpec.describe "test" do
13
13
  end
14
14
 
@@ -16,11 +16,11 @@ describe RuboCop::Cop::Discourse::NoMixingMultisiteAndStandardSpecs, :config do
16
16
  end
17
17
  RUBY
18
18
 
19
- expect(cop.offenses.first.message).to match(described_class::MSG)
19
+ expect(offenses.first.message).to match(described_class::MSG)
20
20
  end
21
21
 
22
22
  it "raises an offense if there are multiple multisite and standard top-level describes" do
23
- inspect_source(<<~RUBY)
23
+ offenses = inspect_source(<<~RUBY)
24
24
  describe "test", type: :multisite do
25
25
  end
26
26
 
@@ -31,11 +31,11 @@ describe RuboCop::Cop::Discourse::NoMixingMultisiteAndStandardSpecs, :config do
31
31
  end
32
32
  RUBY
33
33
 
34
- expect(cop.offenses.first.message).to match(described_class::MSG)
34
+ expect(offenses.first.message).to match(described_class::MSG)
35
35
  end
36
36
 
37
37
  it "does not raise an offense if there are only multisite describes" do
38
- inspect_source(<<~RUBY)
38
+ offenses = inspect_source(<<~RUBY)
39
39
  require "foo"
40
40
 
41
41
  describe "test", type: :multisite do
@@ -49,11 +49,11 @@ describe RuboCop::Cop::Discourse::NoMixingMultisiteAndStandardSpecs, :config do
49
49
  end
50
50
  RUBY
51
51
 
52
- expect(cop.offenses).to eq([])
52
+ expect(offenses).to eq([])
53
53
  end
54
54
 
55
55
  it "does not raise an offense if there are only standard describes" do
56
- inspect_source(<<~RUBY)
56
+ offenses = inspect_source(<<~RUBY)
57
57
  require "rails_helper"
58
58
 
59
59
  describe "test" do
@@ -65,6 +65,6 @@ describe RuboCop::Cop::Discourse::NoMixingMultisiteAndStandardSpecs, :config do
65
65
  end
66
66
  RUBY
67
67
 
68
- expect(cop.offenses).to eq([])
68
+ expect(offenses).to eq([])
69
69
  end
70
70
  end
@@ -8,26 +8,26 @@ describe RuboCop::Cop::Discourse::NoMockingJobs, :config do
8
8
  let(:config) { RuboCop::Config.new }
9
9
 
10
10
  it "raises an offense if Jobs is mocked with :enqueue" do
11
- inspect_source(<<~RUBY)
11
+ offenses = inspect_source(<<~RUBY)
12
12
  Jobs.expects(:enqueue)
13
13
  RUBY
14
14
 
15
- expect(cop.offenses.first.message).to end_with(described_class::MSG)
15
+ expect(offenses.first.message).to end_with(described_class::MSG)
16
16
  end
17
17
 
18
18
  it "raises an offense if Jobs is mocked with :enqueue_in" do
19
- inspect_source(<<~RUBY)
19
+ offenses = inspect_source(<<~RUBY)
20
20
  Jobs.expects(:enqueue_in)
21
21
  RUBY
22
22
 
23
- expect(cop.offenses.first.message).to end_with(described_class::MSG)
23
+ expect(offenses.first.message).to end_with(described_class::MSG)
24
24
  end
25
25
 
26
26
  it "does not raise an offense if Jobs is not mocked with :enqueue or :enqueue_in" do
27
- inspect_source(<<~RUBY)
27
+ offenses = inspect_source(<<~RUBY)
28
28
  Jobs.enqueue(:some_job)
29
29
  RUBY
30
30
 
31
- expect(cop.offenses).to eq([])
31
+ expect(offenses).to eq([])
32
32
  end
33
33
  end
@@ -2,8 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe RuboCop::Cop::Discourse::NoResetColumnInformationInMigrations,
6
- :config do
5
+ describe RuboCop::Cop::Discourse::NoResetColumnInformationInMigrations, :config do
7
6
  subject(:cop) { described_class.new(config) }
8
7
 
9
8
  let(:config) { RuboCop::Config.new }
@@ -11,7 +10,7 @@ describe RuboCop::Cop::Discourse::NoResetColumnInformationInMigrations,
11
10
  before { config["Discourse/NoResetColumnInformationInMigrations"]["Enabled"] = true }
12
11
 
13
12
  it "raises an offense if reset_column_information is used" do
14
- inspect_source(<<~RUBY)
13
+ offenses = inspect_source(<<~RUBY)
15
14
  class SomeMigration < ActiveRecord::Migration[6.0]
16
15
  def up
17
16
  Post.reset_column_information
@@ -19,11 +18,11 @@ describe RuboCop::Cop::Discourse::NoResetColumnInformationInMigrations,
19
18
  end
20
19
  RUBY
21
20
 
22
- expect(cop.offenses.first.message).to match(described_class::MSG)
21
+ expect(offenses.first.message).to match(described_class::MSG)
23
22
  end
24
23
 
25
24
  it "raise an offense if reset_column_information is used without AR model" do
26
- inspect_source(<<~RUBY)
25
+ offenses = inspect_source(<<~RUBY)
27
26
  class SomeMigration < ActiveRecord::Migration[6.0]
28
27
  def up
29
28
  "post".classify.constantize.reset_column_information
@@ -31,6 +30,6 @@ describe RuboCop::Cop::Discourse::NoResetColumnInformationInMigrations,
31
30
  end
32
31
  RUBY
33
32
 
34
- expect(cop.offenses.first.message).to match(described_class::MSG)
33
+ expect(offenses.first.message).to match(described_class::MSG)
35
34
  end
36
35
  end
@@ -8,29 +8,29 @@ describe RuboCop::Cop::Discourse::OnlyTopLevelMultisiteSpecs, :config do
8
8
  let(:config) { RuboCop::Config.new }
9
9
 
10
10
  it "raises an offense if multisite config option is used in a sub-describe" do
11
- inspect_source(<<~RUBY)
11
+ offenses = inspect_source(<<~RUBY)
12
12
  describe "test" do
13
13
  describe "sub-test", type: :multisite do
14
14
  end
15
15
  end
16
16
  RUBY
17
17
 
18
- expect(cop.offenses.first.message).to match(described_class::MSG)
18
+ expect(offenses.first.message).to match(described_class::MSG)
19
19
  end
20
20
 
21
21
  it "raises an offense if multisite config option is used in a sub-describe (RSpec const version)" do
22
- inspect_source(<<~RUBY)
22
+ offenses = inspect_source(<<~RUBY)
23
23
  RSpec.describe "test" do
24
24
  RSpec.describe "sub-test", type: :multisite do
25
25
  end
26
26
  end
27
27
  RUBY
28
28
 
29
- expect(cop.offenses.first.message).to match(described_class::MSG)
29
+ expect(offenses.first.message).to match(described_class::MSG)
30
30
  end
31
31
 
32
32
  it "raises an offense if multisite config option is used in an example" do
33
- inspect_source(<<~RUBY)
33
+ offenses = inspect_source(<<~RUBY)
34
34
  describe "test" do
35
35
  it "acts as an example" do
36
36
  end
@@ -40,33 +40,33 @@ describe RuboCop::Cop::Discourse::OnlyTopLevelMultisiteSpecs, :config do
40
40
  end
41
41
  RUBY
42
42
 
43
- expect(cop.offenses.first.message).to match(described_class::MSG)
43
+ expect(offenses.first.message).to match(described_class::MSG)
44
44
  end
45
45
 
46
46
  it "raises an offense if multisite config option is used in a context" do
47
- inspect_source(<<~RUBY)
47
+ offenses = inspect_source(<<~RUBY)
48
48
  describe "test" do
49
49
  context "special circumstances", type: :multisite do
50
50
  end
51
51
  end
52
52
  RUBY
53
53
 
54
- expect(cop.offenses.first.message).to match(described_class::MSG)
54
+ expect(offenses.first.message).to match(described_class::MSG)
55
55
  end
56
56
 
57
57
  it "does not raise an offense if multisite config option is used on top-level describe" do
58
- inspect_source(<<~RUBY)
58
+ offenses = inspect_source(<<~RUBY)
59
59
  describe "test", type: :multisite do
60
60
  describe "sub-test" do
61
61
  end
62
62
  end
63
63
  RUBY
64
64
 
65
- expect(cop.offenses).to eq([])
65
+ expect(offenses).to eq([])
66
66
  end
67
67
 
68
68
  it "does not raise an offense if multisite config option is used on top-level describe (RSpec const version)" do
69
- inspect_source(<<~RUBY)
69
+ offenses = inspect_source(<<~RUBY)
70
70
  require "rails_helper"
71
71
 
72
72
  RSpec.describe "test", type: :multisite do
@@ -75,6 +75,6 @@ describe RuboCop::Cop::Discourse::OnlyTopLevelMultisiteSpecs, :config do
75
75
  end
76
76
  RUBY
77
77
 
78
- expect(cop.offenses).to eq([])
78
+ expect(offenses).to eq([])
79
79
  end
80
80
  end
@@ -8,18 +8,18 @@ describe RuboCop::Cop::Discourse::TimeEqMatcher, :config do
8
8
  let(:config) { RuboCop::Config.new }
9
9
 
10
10
  it "raises an offense if a timestamp is compared using `eq`" do
11
- inspect_source(<<~RUBY)
11
+ offenses = inspect_source(<<~RUBY)
12
12
  expect(user.created_at).to eq(Time.zone.now)
13
13
  RUBY
14
14
 
15
- expect(cop.offenses.first.message).to match(described_class::MSG)
15
+ expect(offenses.first.message).to match(described_class::MSG)
16
16
  end
17
17
 
18
18
  it "passes if a timestamp is compared using `eq_time`" do
19
- inspect_source(<<~RUBY)
19
+ offenses = inspect_source(<<~RUBY)
20
20
  expect(user.created_at).to eq_time(Time.zone.now)
21
21
  RUBY
22
22
 
23
- expect(cop.offenses).to be_empty
23
+ expect(offenses).to be_empty
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-discourse
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.1
4
+ version: 3.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Discourse Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-13 00:00:00.000000000 Z
11
+ date: 2024-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport