rubocop-discourse 2.4.2 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a72b547f01dafa6cb189e9bfa4478817b6235ae725707b36e4b7f692351c3707
4
- data.tar.gz: 2bfc96ac97e72886e781ddf5bc94f38c04a6f7ce45946dea2823f35d8db8e798
3
+ metadata.gz: d323501481e0e731a79b93e81cb53e5a2b67d0761aebf7ac6ed8088d607bf912
4
+ data.tar.gz: 8ab7c331ea82087f6a2f8a626ac9de4192a231aff5a58ca853938903d16bfc37
5
5
  SHA512:
6
- metadata.gz: cbcd4c1f22751539ee6a1c9550a08170d91f92b26e7098362bcf3039f0d3658b5df789c72b947e857fa38ba7523ca53b5061feff1b9bd6135940db61ce6baef6
7
- data.tar.gz: 1f1d6460703cf74e03ce57ac50deed273f7a1a0f2df3d8a1ab9d6a9d0ec18aa53be63ad442c79dd08cfbf664811ea79caa02ae65127b23ae78a14c1c8721d71f
6
+ metadata.gz: 567ae9f6c1175704e4146fdb1d24ec8220560edc5f438fb4ac8cb4be655f90f92cc5fbc0b2b9a1a2992bd8861725681d0e860be73d16288e34298e61e41d85b1
7
+ data.tar.gz: 38f89b89b1d18efd564afd9c2dc5de3830ace80aa8908e0430697f32436d6a3c91ffd87ec4f467da43f87df5132f1adb34d9161a93da8bc5882c5292fba71337
@@ -5,9 +5,7 @@ on:
5
5
  push:
6
6
  branches:
7
7
  - master
8
- tags:
9
- - v*
10
-
8
+ - main
11
9
  jobs:
12
10
  build:
13
11
  runs-on: ubuntu-latest
@@ -33,7 +31,7 @@ jobs:
33
31
  run: bundle exec rspec spec
34
32
 
35
33
  publish:
36
- if: contains(github.ref, 'refs/tags/v')
34
+ if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
37
35
  needs: build
38
36
  runs-on: ubuntu-latest
39
37
 
@@ -41,6 +39,8 @@ jobs:
41
39
  - uses: actions/checkout@v2
42
40
 
43
41
  - name: Release Gem
44
- uses: discourse/publish-rubygems-action@main
42
+ uses: discourse/publish-rubygems-action@v2
45
43
  env:
46
- RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
44
+ RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
45
+ GIT_EMAIL: team@discourse.org
46
+ GIT_NAME: discoursebot
data/config/default.yml CHANGED
@@ -50,3 +50,15 @@ Discourse/NoMockingJobs:
50
50
  Patterns:
51
51
  - _spec.rb
52
52
  - "(?:^|/)spec/"
53
+
54
+ Discourse/OnlyTopLevelMultisiteSpecs:
55
+ Enabled: true
56
+ Patterns:
57
+ - _spec.rb
58
+ - "(?:^|/)spec/"
59
+
60
+ Discourse/NoMixingMultisiteAndStandardSpecs:
61
+ Enabled: true
62
+ Patterns:
63
+ - _spec.rb
64
+ - "(?:^|/)spec/"
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Discourse
6
+ # Use `type: :multisite` only on a top-level `describe`.
7
+ # Mixing multisite and standard specs can lead to errors,
8
+ # e.g. when using `fab!` helper.
9
+ #
10
+ # @example
11
+ # # bad
12
+ # describe "x" do
13
+ # end
14
+ #
15
+ # describe "x", type: :multisite do
16
+ # end
17
+ #
18
+ # # good
19
+ # # x_spec.rb
20
+ # describe "x" do
21
+ # end
22
+ #
23
+ # # x_multisite_spec.rb
24
+ # describe "x", type: :multisite do
25
+ # end
26
+ class NoMixingMultisiteAndStandardSpecs < Cop
27
+ MSG = "Do not mix multisite and standard specs. Consider moving multisite describes to a separate file."
28
+
29
+ def initialize(config = nil, options = nil)
30
+ super
31
+ @describes = nil
32
+ end
33
+
34
+ def on_block(node)
35
+ return if !top_level?(node)
36
+ return if !describe?(node.children.first)
37
+
38
+ type = !!multisite_describe?(node.children.first)
39
+
40
+ if !@describes.nil? && @describes != type
41
+ add_offense(node, message: MSG)
42
+ else
43
+ @describes = type
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def_node_matcher :describe?, <<~MATCHER
50
+ (send
51
+ {nil? (const nil? :RSpec)}
52
+ {:describe :context :it}
53
+ ...
54
+ )
55
+ MATCHER
56
+
57
+ def_node_matcher :multisite_describe?, <<~MATCHER
58
+ (send
59
+ {nil? (const nil? :RSpec)}
60
+ {:describe :context :it}
61
+ _
62
+ (hash (pair (sym :type) (sym :multisite)) ...)
63
+ )
64
+ MATCHER
65
+
66
+ def top_level?(node)
67
+ if node.parent&.begin_type?
68
+ node.parent.root?
69
+ else
70
+ node.root?
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Discourse
6
+ # Use `type: :multisite` only on a top-level `describe`.
7
+ # Mixing multisite and standard specs can lead to errors,
8
+ # e.g. when using `fab!` helper.
9
+ #
10
+ # @example
11
+ # # bad
12
+ # describe "something" do
13
+ # describe "x", type: :multisite do
14
+ # end
15
+ #
16
+ # it "does X", type: :multisite do
17
+ # end
18
+ # end
19
+ #
20
+ # # good
21
+ # describe "something", type: :multisite do
22
+ # describe "x" do
23
+ # end
24
+ #
25
+ # it "does X" do
26
+ # end
27
+ # end
28
+ class OnlyTopLevelMultisiteSpecs < Cop
29
+ MSG = "Use `type: :multisite` only on a top-level `describe`"
30
+
31
+ def on_block(node)
32
+ return if top_level?(node)
33
+ return if !multisite_describe?(node.children.first)
34
+
35
+ add_offense(node, message: MSG)
36
+ end
37
+
38
+ private
39
+
40
+ def_node_matcher :multisite_describe?, <<~MATCHER
41
+ (send
42
+ {nil? (const nil? :RSpec)}
43
+ {:describe :context :it}
44
+ _
45
+ (hash (pair (sym :type) (sym :multisite)) ...)
46
+ )
47
+ MATCHER
48
+
49
+ def top_level?(node)
50
+ if node.parent&.begin_type?
51
+ node.parent.root?
52
+ else
53
+ node.root?
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
data/rubocop-core.yml CHANGED
@@ -1,3 +1,9 @@
1
+ Security:
2
+ Enabled: true
3
+
4
+ Security/IoMethods:
5
+ Enabled: true
6
+
1
7
  # Prefer &&/|| over and/or.
2
8
  Style/AndOr:
3
9
  Enabled: true
@@ -2,9 +2,9 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "rubocop-discourse"
5
- s.version = "2.4.2"
5
+ s.version = "2.6.0"
6
6
  s.summary = "Custom rubocop cops used by Discourse"
7
- s.authors = ["David Taylor"]
7
+ s.authors = ["Discourse Team"]
8
8
  s.license = "MIT"
9
9
  s.homepage = "https://github.com/discourse/rubocop-discourse"
10
10
 
data/rubocop-rspec.yml CHANGED
@@ -8,16 +8,40 @@ RSpec/AroundBlock:
8
8
  Enabled: true
9
9
 
10
10
  RSpec/BeforeAfterAll:
11
- Enabled: false # To be decided
11
+ Enabled: true
12
+
13
+ RSpec/ChangeByZero:
14
+ Enabled: true
12
15
 
13
16
  RSpec/ContextMethod:
14
- Enabled: false # TODO
17
+ Enabled: true
15
18
 
16
19
  RSpec/ContextWording:
17
- Enabled: false # To be decided
20
+ Enabled: true
21
+ Prefixes:
22
+ - when
23
+ - with
24
+ - without
25
+ - for
26
+ - while
27
+ - if
28
+ - as
29
+ - after
18
30
 
19
31
  RSpec/DescribeClass:
20
- Enabled: false # To be decided
32
+ Enabled: true
33
+ Exclude:
34
+ - "**/spec/features/**/*"
35
+ - "**/spec/requests/**/*"
36
+ - "**/spec/routing/**/*"
37
+ - "**/spec/system/**/*"
38
+ - "**/spec/views/**/*"
39
+ - "**/spec/initializers/**/*"
40
+ - "**/spec/integration/**/*"
41
+ - "**/spec/integrity/**/*"
42
+ - "**/spec/tasks/**/*"
43
+ - "**/spec/lib/freedom_patches/**/*"
44
+ - "**/spec/multisite/**/*"
21
45
 
22
46
  RSpec/DescribeMethod:
23
47
  Enabled: true
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe RuboCop::Cop::Discourse::NoMixingMultisiteAndStandardSpecs, :config do
6
+ subject(:cop) { described_class.new(config) }
7
+
8
+ let(:config) do
9
+ RuboCop::Config.new
10
+ end
11
+
12
+ it "raises an offense if there are multisite and standard top-level describes" do
13
+ inspect_source(<<~RUBY)
14
+ RSpec.describe "test" do
15
+ end
16
+
17
+ describe "test2", type: :multisite do
18
+ end
19
+ RUBY
20
+
21
+ expect(cop.offenses.first.message).to eq(described_class::MSG)
22
+ end
23
+
24
+ it "raises an offense if there are multiple multisite and standard top-level describes" do
25
+ inspect_source(<<~RUBY)
26
+ describe "test", type: :multisite do
27
+ end
28
+
29
+ describe "test2", type: :multisite do
30
+ end
31
+
32
+ describe "test2" do
33
+ end
34
+ RUBY
35
+
36
+ expect(cop.offenses.first.message).to eq(described_class::MSG)
37
+ end
38
+
39
+ it "does not raise an offense if there are only multisite describes" do
40
+ inspect_source(<<~RUBY)
41
+ require "foo"
42
+
43
+ describe "test", type: :multisite do
44
+ describe "inner-test" do
45
+ it "test" do
46
+ end
47
+ end
48
+ end
49
+
50
+ RSpec.describe "test2", type: :multisite do
51
+ end
52
+ RUBY
53
+
54
+ expect(cop.offenses).to eq([])
55
+ end
56
+
57
+ it "does not raise an offense if there are only standard describes" do
58
+ inspect_source(<<~RUBY)
59
+ require "rails_helper"
60
+
61
+ describe "test" do
62
+ end
63
+
64
+ describe "test2" do
65
+ RSpec.describe "inner-test" do
66
+ end
67
+ end
68
+ RUBY
69
+
70
+ expect(cop.offenses).to eq([])
71
+ end
72
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe RuboCop::Cop::Discourse::OnlyTopLevelMultisiteSpecs, :config do
6
+ subject(:cop) { described_class.new(config) }
7
+
8
+ let(:config) do
9
+ RuboCop::Config.new
10
+ end
11
+
12
+ it "raises an offense if multisite config option is used in a sub-describe" do
13
+ inspect_source(<<~RUBY)
14
+ describe "test" do
15
+ describe "sub-test", type: :multisite do
16
+ end
17
+ end
18
+ RUBY
19
+
20
+ expect(cop.offenses.first.message).to eq(described_class::MSG)
21
+ end
22
+
23
+ it "raises an offense if multisite config option is used in a sub-describe (RSpec const version)" do
24
+ inspect_source(<<~RUBY)
25
+ RSpec.describe "test" do
26
+ RSpec.describe "sub-test", type: :multisite do
27
+ end
28
+ end
29
+ RUBY
30
+
31
+ expect(cop.offenses.first.message).to eq(described_class::MSG)
32
+ end
33
+
34
+ it "raises an offense if multisite config option is used in an example" do
35
+ inspect_source(<<~RUBY)
36
+ describe "test" do
37
+ it "acts as an example" do
38
+ end
39
+
40
+ it "does a thing", type: :multisite do
41
+ end
42
+ end
43
+ RUBY
44
+
45
+ expect(cop.offenses.first.message).to eq(described_class::MSG)
46
+ end
47
+
48
+ it "raises an offense if multisite config option is used in a context" do
49
+ inspect_source(<<~RUBY)
50
+ describe "test" do
51
+ context "special circumstances", type: :multisite do
52
+ end
53
+ end
54
+ RUBY
55
+
56
+ expect(cop.offenses.first.message).to eq(described_class::MSG)
57
+ end
58
+
59
+ it "does not raise an offense if multisite config option is used on top-level describe" do
60
+ inspect_source(<<~RUBY)
61
+ describe "test", type: :multisite do
62
+ describe "sub-test" do
63
+ end
64
+ end
65
+ RUBY
66
+
67
+ expect(cop.offenses).to eq([])
68
+ end
69
+
70
+ it "does not raise an offense if multisite config option is used on top-level describe (RSpec const version)" do
71
+ inspect_source(<<~RUBY)
72
+ require "rails_helper"
73
+
74
+ RSpec.describe "test", type: :multisite do
75
+ describe "sub-test" do
76
+ end
77
+ end
78
+ RUBY
79
+
80
+ expect(cop.offenses).to eq([])
81
+ end
82
+ 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: 2.4.2
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
- - David Taylor
7
+ - Discourse Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-07 00:00:00.000000000 Z
11
+ date: 2022-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -86,11 +86,13 @@ files:
86
86
  - lib/rubocop/cop/discourse/no_chdir.rb
87
87
  - lib/rubocop/cop/discourse/no_direct_multisite_manipulation.rb
88
88
  - lib/rubocop/cop/discourse/no_json_parse_response.rb
89
+ - lib/rubocop/cop/discourse/no_mixing_multisite_and_standard_specs.rb
89
90
  - lib/rubocop/cop/discourse/no_mocking_jobs.rb
90
91
  - lib/rubocop/cop/discourse/no_nokogiri_html_fragment.rb
91
92
  - lib/rubocop/cop/discourse/no_reset_column_information_in_migrations.rb
92
93
  - lib/rubocop/cop/discourse/no_time_new_without_args.rb
93
94
  - lib/rubocop/cop/discourse/no_uri_escape_encode.rb
95
+ - lib/rubocop/cop/discourse/only_top_level_multisite_specs.rb
94
96
  - lib/rubocop/cop/discourse/time_eq_matcher.rb
95
97
  - lib/rubocop/cop/discourse_cops.rb
96
98
  - lib/rubocop/discourse.rb
@@ -99,8 +101,10 @@ files:
99
101
  - rubocop-discourse.gemspec
100
102
  - rubocop-rspec.yml
101
103
  - spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb
104
+ - spec/lib/rubocop/cop/no_mixing_multisite_and_standard_specs_spec.rb
102
105
  - spec/lib/rubocop/cop/no_mocking_jobs_enqueue_spec.rb
103
106
  - spec/lib/rubocop/cop/no_reset_column_information_migrations_spec.rb
107
+ - spec/lib/rubocop/cop/only_top_level_multisite_specs_spec.rb
104
108
  - spec/spec_helper.rb
105
109
  homepage: https://github.com/discourse/rubocop-discourse
106
110
  licenses:
@@ -121,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
125
  - !ruby/object:Gem::Version
122
126
  version: '0'
123
127
  requirements: []
124
- rubygems_version: 3.0.3
128
+ rubygems_version: 3.1.6
125
129
  signing_key:
126
130
  specification_version: 4
127
131
  summary: Custom rubocop cops used by Discourse