rubocop-discourse 2.3.2 → 2.5.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: 77712b97cde68ea4417a03ea56b6fccff3678c96ca97d3a6e518534efd65b7ab
4
- data.tar.gz: 284be7e29c7278afac20f0d7edf73a3cfb08cd662c7d4d2f2ae1377d0584be8d
3
+ metadata.gz: 3a1dd5d5b8d79de5bcda354a31c6f993460f11875065c64edd9f7cc3cce71bff
4
+ data.tar.gz: 175c1f83d9300537bac93184d5e8bf5d21cffc8196e996d59cc9298f69d8bdb5
5
5
  SHA512:
6
- metadata.gz: 4d40d329945599d5b41d2f00383a63e75c0e2a57e4860295003bbcb345255bddfe0bf95784ca1e071e83e0fd1cb6f5ea61f7e5b8edcc2f94aa0f37145c77f0d3
7
- data.tar.gz: f83f42a4e2805b15f713eb7b45b7517340bd458e8ae1ad05c046f9677e7b1a8b215e3cc768010e4458fc32698cca3871bfca185d6d97269cc42a522f8f5cebf7
6
+ metadata.gz: ada5c637849f829f0d8d0247b86fbec1a1cc9182d06b6385f6ac13f081f9782a7d9cd38d8a3dd30c2bf121f834171a9f28933deaee4ab8a53a022aa3af5d06fc
7
+ data.tar.gz: ab731fee843a5a8ef9821c613751906457672eb11bed54ec0aae3856588b723a77c03aa26f258a3c1e19c25b1edac4d198ae8ffbfd3e4bbaf397d4e2f1332c8f
@@ -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
@@ -28,12 +26,12 @@ jobs:
28
26
 
29
27
  - name: Rubocop
30
28
  run: bundle exec rubocop
31
-
29
+
32
30
  - name: Rspec
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: CvX/publish-rubygems-action@master
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/.gitignore CHANGED
@@ -1,3 +1 @@
1
- .rubocop-http*
2
1
  Gemfile.lock
3
- .byebug_history
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/"
data/default.yml CHANGED
@@ -15,6 +15,7 @@ AllCops:
15
15
  - "**/node_modules/**/*"
16
16
  - "public/**/*"
17
17
  - "plugins/**/gems/**/*"
18
+ - "plugins/**/vendor/**/*"
18
19
 
19
20
  Discourse:
20
21
  Enabled: true
@@ -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,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "rubocop-discourse"
5
- s.version = "2.3.2"
5
+ s.version = "2.5.0"
6
6
  s.summary = "Custom rubocop cops used by Discourse"
7
7
  s.authors = ["David Taylor"]
8
8
  s.license = "MIT"
@@ -11,8 +11,8 @@ Gem::Specification.new do |s|
11
11
  s.files = `git ls-files`.split($/)
12
12
  s.require_paths = ["lib"]
13
13
 
14
- s.add_runtime_dependency "rubocop", ">= 0.69.0"
15
- s.add_runtime_dependency "rubocop-rspec", ">= 1.39.0"
14
+ s.add_runtime_dependency "rubocop", ">= 1.1.0"
15
+ s.add_runtime_dependency "rubocop-rspec", ">= 2.0.0"
16
16
 
17
17
  s.add_development_dependency "rake", "~> 13.0"
18
18
  s.add_development_dependency "rspec"
data/rubocop-rspec.yml CHANGED
@@ -99,9 +99,6 @@ RSpec/InstanceSpy:
99
99
  RSpec/InstanceVariable:
100
100
  Enabled: false # TODO
101
101
 
102
- RSpec/InvalidPredicateMatcher:
103
- Enabled: true
104
-
105
102
  RSpec/ItBehavesLike:
106
103
  Enabled: true
107
104
 
@@ -192,20 +189,20 @@ RSpec/VoidExpect:
192
189
  RSpec/Yield:
193
190
  Enabled: true
194
191
 
195
- Capybara/CurrentPathExpectation:
192
+ RSpec/Capybara/CurrentPathExpectation:
196
193
  Enabled: true
197
194
 
198
- Capybara/FeatureMethods:
195
+ RSpec/Capybara/FeatureMethods:
199
196
  Enabled: true
200
197
 
201
- FactoryBot/AttributeDefinedStatically:
198
+ RSpec/FactoryBot/AttributeDefinedStatically:
202
199
  Enabled: true
203
200
 
204
- FactoryBot/CreateList:
201
+ RSpec/FactoryBot/CreateList:
205
202
  Enabled: true
206
203
 
207
- FactoryBot/FactoryClassName:
204
+ RSpec/FactoryBot/FactoryClassName:
208
205
  Enabled: true
209
206
 
210
- Rails/HttpStatus:
207
+ RSpec/Rails/HttpStatus:
211
208
  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.3.2
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Taylor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-03 00:00:00.000000000 Z
11
+ date: 2021-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.69.0
19
+ version: 1.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.69.0
26
+ version: 1.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubocop-rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.39.0
33
+ version: 2.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.39.0
40
+ version: 2.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -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