rubocop-discourse 3.0.3 → 3.2.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 +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/config/default.yml +16 -16
- data/lib/rubocop/cop/discourse/no_add_reference_active_record_migrations.rb +8 -6
- data/lib/rubocop/cop/discourse/no_direct_multisite_manipulation.rb +2 -1
- data/lib/rubocop/cop/discourse/no_json_parse_response.rb +2 -1
- data/lib/rubocop/cop/discourse/no_mixing_multisite_and_standard_specs.rb +3 -6
- data/lib/rubocop/cop/discourse/no_mocking_jobs.rb +2 -1
- data/lib/rubocop/cop/discourse/no_reset_column_information_in_migrations.rb +5 -4
- data/lib/rubocop/cop/discourse/no_uri_escape_encode.rb +10 -7
- data/lib/rubocop/cop/discourse/only_top_level_multisite_specs.rb +1 -5
- data/lib/rubocop/discourse.rb +3 -3
- data/rubocop-core.yml +16 -0
- data/rubocop-discourse.gemspec +6 -6
- data/rubocop-rspec.yml +12 -12
- data/spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb +4 -5
- data/spec/lib/rubocop/cop/no_mixing_multisite_and_standard_specs_spec.rb +2 -4
- data/spec/lib/rubocop/cop/no_mocking_jobs_enqueue_spec.rb +2 -4
- data/spec/lib/rubocop/cop/no_reset_column_information_migrations_spec.rb +4 -5
- data/spec/lib/rubocop/cop/only_top_level_multisite_specs_spec.rb +2 -4
- data/spec/lib/rubocop/cop/time_eq_matcher_spec.rb +2 -4
- data/spec/spec_helper.rb +4 -4
- data/stree-compat.yml +8 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 829d3722889a6cda57c4d83a8531fb72d041c868b958f0ce95eac9c66f9fcf3d
|
4
|
+
data.tar.gz: 9d51dd30c4e5a03ade1e948fd720f5804f3a787e6fa3f21ef0949e07e7e61e6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 323f7c0b2994ccccfa9e5d75cc431caefa7de8cf7f6738c2e87030d8b4ee0454349faa7102bc8c9e2a0eafb76ad0597f1ef58d3afb8b7aff223216b20a2ab774
|
7
|
+
data.tar.gz: 8c262ddadf1dd0d78340093a01a181962c1123f49305bd2c20a34ce1669948d7bd1de9f2c9f950f0f5739234fb308b6c86ff368d18b915b9a6220c7dba95af83
|
data/.github/workflows/ci.yml
CHANGED
data/config/default.yml
CHANGED
@@ -13,8 +13,8 @@ Discourse/NoURIEscapeEncode:
|
|
13
13
|
Discourse/NoAddReferenceOrAliasesActiveRecordMigration:
|
14
14
|
Enabled: true
|
15
15
|
Include:
|
16
|
-
|
17
|
-
|
16
|
+
- '**/db/migrate/*'
|
17
|
+
- '**/db/post_migrate/*'
|
18
18
|
|
19
19
|
Discourse/NoNokogiriHtmlFragment:
|
20
20
|
Enabled: true
|
@@ -22,43 +22,43 @@ Discourse/NoNokogiriHtmlFragment:
|
|
22
22
|
Discourse/NoResetColumnInformationInMigrations:
|
23
23
|
Enabled: false
|
24
24
|
Include:
|
25
|
-
|
26
|
-
|
25
|
+
- '**/db/migrate/*'
|
26
|
+
- '**/db/post_migrate/*'
|
27
27
|
|
28
28
|
# Specs
|
29
29
|
|
30
30
|
Discourse/NoDirectMultisiteManipulation:
|
31
31
|
Enabled: true
|
32
32
|
Patterns:
|
33
|
-
|
34
|
-
|
33
|
+
- _spec.rb
|
34
|
+
- '(?:^|/)spec/'
|
35
35
|
|
36
36
|
Discourse/TimeEqMatcher:
|
37
37
|
Enabled: true
|
38
38
|
Patterns:
|
39
|
-
|
40
|
-
|
39
|
+
- _spec.rb
|
40
|
+
- '(?:^|/)spec/'
|
41
41
|
|
42
42
|
Discourse/NoJsonParseResponse:
|
43
43
|
Enabled: false
|
44
44
|
Patterns:
|
45
|
-
|
46
|
-
|
45
|
+
- _spec.rb
|
46
|
+
- '(?:^|/)spec/'
|
47
47
|
|
48
48
|
Discourse/NoMockingJobs:
|
49
49
|
Enabled: true
|
50
50
|
Patterns:
|
51
|
-
|
52
|
-
|
51
|
+
- _spec.rb
|
52
|
+
- '(?:^|/)spec/'
|
53
53
|
|
54
54
|
Discourse/OnlyTopLevelMultisiteSpecs:
|
55
55
|
Enabled: true
|
56
56
|
Patterns:
|
57
|
-
|
58
|
-
|
57
|
+
- _spec.rb
|
58
|
+
- '(?:^|/)spec/'
|
59
59
|
|
60
60
|
Discourse/NoMixingMultisiteAndStandardSpecs:
|
61
61
|
Enabled: true
|
62
62
|
Patterns:
|
63
|
-
|
64
|
-
|
63
|
+
- _spec.rb
|
64
|
+
- '(?:^|/)spec/'
|
@@ -70,12 +70,14 @@ module RuboCop
|
|
70
70
|
MATCHER
|
71
71
|
|
72
72
|
def on_send(node)
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
73
|
+
if [
|
74
|
+
using_add_reference?(node),
|
75
|
+
using_add_belongs_to?(node),
|
76
|
+
using_t_references?(node),
|
77
|
+
using_t_belongs_to?(node)
|
78
|
+
].none?
|
79
|
+
return
|
80
|
+
end
|
79
81
|
add_offense(node, message: MSG)
|
80
82
|
end
|
81
83
|
end
|
@@ -17,7 +17,8 @@ module RuboCop
|
|
17
17
|
# do_something
|
18
18
|
# end
|
19
19
|
class NoDirectMultisiteManipulation < Cop
|
20
|
-
MSG =
|
20
|
+
MSG =
|
21
|
+
"Use `type: :multisite` example setting instead of modifying `Rails.configuration.multisite`."
|
21
22
|
|
22
23
|
def_node_matcher :multisite_setter?, <<-MATCHER
|
23
24
|
(send
|
@@ -12,7 +12,8 @@ module RuboCop
|
|
12
12
|
# # good
|
13
13
|
# expect(response.parsed_body).to eq({})
|
14
14
|
class NoJsonParseResponse < Cop
|
15
|
-
MSG =
|
15
|
+
MSG =
|
16
|
+
"Use `response.parsed_body` instead of `JSON.parse(response.body)` in specs."
|
16
17
|
|
17
18
|
def_node_matcher :json_parse_body?, <<-MATCHER
|
18
19
|
(send
|
@@ -24,7 +24,8 @@ module RuboCop
|
|
24
24
|
# describe "x", type: :multisite do
|
25
25
|
# end
|
26
26
|
class NoMixingMultisiteAndStandardSpecs < Cop
|
27
|
-
MSG =
|
27
|
+
MSG =
|
28
|
+
"Do not mix multisite and standard specs. Consider moving multisite describes to a separate file."
|
28
29
|
|
29
30
|
def initialize(config = nil, options = nil)
|
30
31
|
super
|
@@ -64,11 +65,7 @@ module RuboCop
|
|
64
65
|
MATCHER
|
65
66
|
|
66
67
|
def top_level?(node)
|
67
|
-
|
68
|
-
node.parent.root?
|
69
|
-
else
|
70
|
-
node.root?
|
71
|
-
end
|
68
|
+
node.parent&.begin_type? ? node.parent.root? : node.root?
|
72
69
|
end
|
73
70
|
end
|
74
71
|
end
|
@@ -4,7 +4,8 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Discourse
|
6
6
|
class NoMockingJobs < Cop
|
7
|
-
MSG =
|
7
|
+
MSG =
|
8
|
+
"Use the test helpers provided by Sidekiq instead of mocking `Jobs.expects(:enqueue)`."
|
8
9
|
|
9
10
|
def_node_matcher :mocking_jobs_enqueue?, <<~MATCHER
|
10
11
|
(send (const nil? :Jobs) :expects (:sym :enqueue))
|
@@ -8,10 +8,11 @@ module RuboCop
|
|
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
10
|
class NoResetColumnInformationInMigrations < Cop
|
11
|
-
MSG =
|
12
|
-
"
|
13
|
-
|
14
|
-
|
11
|
+
MSG =
|
12
|
+
"ActiveRecord::ModelSchema.reset_column_information is not thread-safe " \
|
13
|
+
"and we run migrations concurrently on multisite clusters. Using this " \
|
14
|
+
"method also means ActiveRecord methods are being used in migration " \
|
15
|
+
"which is discouraged at Discourse. Instead, you should write SQL in your migrations instead."
|
15
16
|
|
16
17
|
def on_send(node)
|
17
18
|
return if node.method_name != :reset_column_information
|
@@ -16,7 +16,8 @@ module RuboCop
|
|
16
16
|
# UrlHelper.encode("https://a%20a.com?a='a%22")
|
17
17
|
# Addressable::URI.encode("https://a%20a.com?a='a%22")
|
18
18
|
class NoURIEscapeEncode < Cop
|
19
|
-
MSG =
|
19
|
+
MSG =
|
20
|
+
"URI.escape, URI.encode, URI.unescape, URI.decode are deprecated and should not be used."
|
20
21
|
|
21
22
|
def_node_matcher :using_uri_escape?, <<-MATCHER
|
22
23
|
(send (const nil? :URI) :escape ...)
|
@@ -35,12 +36,14 @@ module RuboCop
|
|
35
36
|
MATCHER
|
36
37
|
|
37
38
|
def on_send(node)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
if [
|
40
|
+
using_uri_escape?(node),
|
41
|
+
using_uri_encode?(node),
|
42
|
+
using_uri_unescape?(node),
|
43
|
+
using_uri_decode?(node)
|
44
|
+
].none?
|
45
|
+
return
|
46
|
+
end
|
44
47
|
add_offense(node, message: MSG)
|
45
48
|
end
|
46
49
|
end
|
data/lib/rubocop/discourse.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
module RuboCop
|
4
4
|
# RuboCop Discourse project namespace
|
5
5
|
module Discourse
|
6
|
-
PROJECT_ROOT
|
7
|
-
CONFIG_DEFAULT = PROJECT_ROOT.join(
|
8
|
-
CONFIG
|
6
|
+
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
|
7
|
+
CONFIG_DEFAULT = PROJECT_ROOT.join("config", "default.yml").freeze
|
8
|
+
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
9
9
|
|
10
10
|
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
11
11
|
end
|
data/rubocop-core.yml
CHANGED
@@ -4,6 +4,9 @@ Security:
|
|
4
4
|
Security/IoMethods:
|
5
5
|
Enabled: true
|
6
6
|
|
7
|
+
Security/CompoundHash:
|
8
|
+
Enabled: true
|
9
|
+
|
7
10
|
# Prefer &&/|| over and/or.
|
8
11
|
Style/AndOr:
|
9
12
|
Enabled: true
|
@@ -14,6 +17,7 @@ Style/FrozenStringLiteralComment:
|
|
14
17
|
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
|
15
18
|
Style/HashSyntax:
|
16
19
|
Enabled: true
|
20
|
+
EnforcedShorthandSyntax: either
|
17
21
|
|
18
22
|
# Defining a method with parameters needs parentheses.
|
19
23
|
Style/MethodDefParentheses:
|
@@ -38,6 +42,18 @@ Style/GlobalVars:
|
|
38
42
|
- 'spec/**/*.rb'
|
39
43
|
- 'plugins/*/spec/**/*'
|
40
44
|
|
45
|
+
Style/InvertibleUnlessCondition:
|
46
|
+
Enabled: true
|
47
|
+
|
48
|
+
Style/NegatedUnless:
|
49
|
+
Enabled: true
|
50
|
+
|
51
|
+
Style/UnlessElse:
|
52
|
+
Enabled: true
|
53
|
+
|
54
|
+
Style/UnlessLogicalOperators:
|
55
|
+
Enabled: true
|
56
|
+
|
41
57
|
Lint/Debugger:
|
42
58
|
Enabled: true
|
43
59
|
|
data/rubocop-discourse.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name
|
5
|
-
s.version
|
6
|
-
s.summary
|
7
|
-
s.authors
|
8
|
-
s.license
|
9
|
-
s.homepage
|
4
|
+
s.name = "rubocop-discourse"
|
5
|
+
s.version = "3.2.0"
|
6
|
+
s.summary = "Custom rubocop cops used by Discourse"
|
7
|
+
s.authors = ["Discourse Team"]
|
8
|
+
s.license = "MIT"
|
9
|
+
s.homepage = "https://github.com/discourse/rubocop-discourse"
|
10
10
|
|
11
11
|
s.files = `git ls-files`.split($/)
|
12
12
|
s.require_paths = ["lib"]
|
data/rubocop-rspec.yml
CHANGED
@@ -31,17 +31,17 @@ RSpec/ContextWording:
|
|
31
31
|
RSpec/DescribeClass:
|
32
32
|
Enabled: true
|
33
33
|
Exclude:
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
-
|
38
|
-
-
|
39
|
-
-
|
40
|
-
-
|
41
|
-
-
|
42
|
-
-
|
43
|
-
-
|
44
|
-
-
|
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/**/*'
|
45
45
|
|
46
46
|
RSpec/DescribeMethod:
|
47
47
|
Enabled: true
|
@@ -213,7 +213,7 @@ RSpec/VoidExpect:
|
|
213
213
|
RSpec/Yield:
|
214
214
|
Enabled: true
|
215
215
|
|
216
|
-
|
216
|
+
Capybara/CurrentPathExpectation:
|
217
217
|
Enabled: true
|
218
218
|
|
219
219
|
RSpec/Capybara/FeatureMethods:
|
@@ -1,12 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
|
-
describe RuboCop::Cop::Discourse::NoAddReferenceOrAliasesActiveRecordMigration,
|
5
|
+
describe RuboCop::Cop::Discourse::NoAddReferenceOrAliasesActiveRecordMigration,
|
6
|
+
:config do
|
6
7
|
subject(:cop) { described_class.new(config) }
|
7
|
-
let(:config)
|
8
|
-
RuboCop::Config.new
|
9
|
-
end
|
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
11
|
inspect_source(<<~RUBY)
|
@@ -1,13 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe RuboCop::Cop::Discourse::NoMixingMultisiteAndStandardSpecs, :config do
|
6
6
|
subject(:cop) { described_class.new(config) }
|
7
7
|
|
8
|
-
let(:config)
|
9
|
-
RuboCop::Config.new
|
10
|
-
end
|
8
|
+
let(:config) { RuboCop::Config.new }
|
11
9
|
|
12
10
|
it "raises an offense if there are multisite and standard top-level describes" do
|
13
11
|
inspect_source(<<~RUBY)
|
@@ -1,13 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe RuboCop::Cop::Discourse::NoMockingJobs, :config do
|
6
6
|
subject(:cop) { described_class.new(config) }
|
7
7
|
|
8
|
-
let(:config)
|
9
|
-
RuboCop::Config.new
|
10
|
-
end
|
8
|
+
let(:config) { RuboCop::Config.new }
|
11
9
|
|
12
10
|
it "raises an offense if Jobs is mocked with :enqueue" do
|
13
11
|
inspect_source(<<~RUBY)
|
@@ -1,13 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
|
-
describe RuboCop::Cop::Discourse::NoResetColumnInformationInMigrations,
|
5
|
+
describe RuboCop::Cop::Discourse::NoResetColumnInformationInMigrations,
|
6
|
+
:config do
|
6
7
|
subject(:cop) { described_class.new(config) }
|
7
8
|
|
8
|
-
let(:config)
|
9
|
-
RuboCop::Config.new
|
10
|
-
end
|
9
|
+
let(:config) { RuboCop::Config.new }
|
11
10
|
|
12
11
|
it "raises an offense if reset_column_information is used" do
|
13
12
|
inspect_source(<<~RUBY)
|
@@ -1,13 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe RuboCop::Cop::Discourse::OnlyTopLevelMultisiteSpecs, :config do
|
6
6
|
subject(:cop) { described_class.new(config) }
|
7
7
|
|
8
|
-
let(:config)
|
9
|
-
RuboCop::Config.new
|
10
|
-
end
|
8
|
+
let(:config) { RuboCop::Config.new }
|
11
9
|
|
12
10
|
it "raises an offense if multisite config option is used in a sub-describe" do
|
13
11
|
inspect_source(<<~RUBY)
|
@@ -1,13 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe RuboCop::Cop::Discourse::TimeEqMatcher, :config do
|
6
6
|
subject(:cop) { described_class.new(config) }
|
7
7
|
|
8
|
-
let(:config)
|
9
|
-
RuboCop::Config.new
|
10
|
-
end
|
8
|
+
let(:config) { RuboCop::Config.new }
|
11
9
|
|
12
10
|
it "raises an offense if a timestamp is compared using `eq`" do
|
13
11
|
inspect_source(<<~RUBY)
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "bundler/setup"
|
4
4
|
Bundler.setup
|
5
5
|
|
6
6
|
# Require supporting files exposed for testing.
|
7
|
-
require
|
8
|
-
require
|
7
|
+
require "rubocop"
|
8
|
+
require "rubocop/rspec/support"
|
9
9
|
|
10
|
-
require
|
10
|
+
require "rubocop-discourse" # and any other gems you need
|
11
11
|
|
12
12
|
RSpec.configure do |config|
|
13
13
|
config.include RuboCop::RSpec::ExpectOffense
|
data/stree-compat.yml
CHANGED
@@ -6,16 +6,16 @@ inherit_from:
|
|
6
6
|
- ./rubocop-rspec.yml
|
7
7
|
|
8
8
|
AllCops:
|
9
|
-
TargetRubyVersion: 2
|
9
|
+
TargetRubyVersion: 3.2
|
10
10
|
DisabledByDefault: true
|
11
11
|
Exclude:
|
12
|
-
-
|
13
|
-
-
|
14
|
-
-
|
15
|
-
-
|
16
|
-
-
|
17
|
-
-
|
18
|
-
-
|
12
|
+
- 'db/schema.rb'
|
13
|
+
- 'bundle/**/*'
|
14
|
+
- 'vendor/**/*'
|
15
|
+
- '**/node_modules/**/*'
|
16
|
+
- 'public/**/*'
|
17
|
+
- 'plugins/**/gems/**/*'
|
18
|
+
- 'plugins/**/vendor/**/*'
|
19
19
|
|
20
20
|
Discourse:
|
21
21
|
Enabled: true
|
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.0
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Discourse Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|