rubocop-discourse 3.1.0 → 3.2.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: 41746c69c5012edbafa4e2f85d902a55a72235316897c0a5afdff69a7b7abbda
4
- data.tar.gz: b0128a77bf8387b94c7797c6e3df26a0eb1b0ffb68a87122b005e34aab13a448
3
+ metadata.gz: 829d3722889a6cda57c4d83a8531fb72d041c868b958f0ce95eac9c66f9fcf3d
4
+ data.tar.gz: 9d51dd30c4e5a03ade1e948fd720f5804f3a787e6fa3f21ef0949e07e7e61e6a
5
5
  SHA512:
6
- metadata.gz: abf20aff53a75d624eeb703a3bb86036486ebb6b5dd67b5255312eb8eb7e2ffb04cd57f3cf6ae173bff02a8bee6042fe93acaf038851c2a06011a082e91fd382
7
- data.tar.gz: 53b2e0e2bed1e95f94531819aa4f0c5595e1627231f53f626e6f557c59ab42d854f58362211ae8ff23fa60b5ebea4454185de2d9c4ce0322c71f2ed4e89c91e9
6
+ metadata.gz: 323f7c0b2994ccccfa9e5d75cc431caefa7de8cf7f6738c2e87030d8b4ee0454349faa7102bc8c9e2a0eafb76ad0597f1ef58d3afb8b7aff223216b20a2ab774
7
+ data.tar.gz: 8c262ddadf1dd0d78340093a01a181962c1123f49305bd2c20a34ce1669948d7bd1de9f2c9f950f0f5739234fb308b6c86ff368d18b915b9a6220c7dba95af83
@@ -16,7 +16,7 @@ jobs:
16
16
  - name: Setup ruby
17
17
  uses: ruby/setup-ruby@v1
18
18
  with:
19
- ruby-version: '2.6'
19
+ ruby-version: '3.2'
20
20
  bundler-cache: true
21
21
 
22
22
  - name: Rubocop
data/config/default.yml CHANGED
@@ -13,8 +13,8 @@ Discourse/NoURIEscapeEncode:
13
13
  Discourse/NoAddReferenceOrAliasesActiveRecordMigration:
14
14
  Enabled: true
15
15
  Include:
16
- - "**/db/migrate/*"
17
- - "**/db/post_migrate/*"
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
- - "**/db/migrate/*"
26
- - "**/db/post_migrate/*"
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
- - _spec.rb
34
- - "(?:^|/)spec/"
33
+ - _spec.rb
34
+ - '(?:^|/)spec/'
35
35
 
36
36
  Discourse/TimeEqMatcher:
37
37
  Enabled: true
38
38
  Patterns:
39
- - _spec.rb
40
- - "(?:^|/)spec/"
39
+ - _spec.rb
40
+ - '(?:^|/)spec/'
41
41
 
42
42
  Discourse/NoJsonParseResponse:
43
43
  Enabled: false
44
44
  Patterns:
45
- - _spec.rb
46
- - "(?:^|/)spec/"
45
+ - _spec.rb
46
+ - '(?:^|/)spec/'
47
47
 
48
48
  Discourse/NoMockingJobs:
49
49
  Enabled: true
50
50
  Patterns:
51
- - _spec.rb
52
- - "(?:^|/)spec/"
51
+ - _spec.rb
52
+ - '(?:^|/)spec/'
53
53
 
54
54
  Discourse/OnlyTopLevelMultisiteSpecs:
55
55
  Enabled: true
56
56
  Patterns:
57
- - _spec.rb
58
- - "(?:^|/)spec/"
57
+ - _spec.rb
58
+ - '(?:^|/)spec/'
59
59
 
60
60
  Discourse/NoMixingMultisiteAndStandardSpecs:
61
61
  Enabled: true
62
62
  Patterns:
63
- - _spec.rb
64
- - "(?:^|/)spec/"
63
+ - _spec.rb
64
+ - '(?:^|/)spec/'
@@ -70,12 +70,14 @@ module RuboCop
70
70
  MATCHER
71
71
 
72
72
  def on_send(node)
73
- return 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?
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 = "Use `type: :multisite` example setting instead of modifying `Rails.configuration.multisite`."
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 = "Use `response.parsed_body` instead of `JSON.parse(response.body)` in specs."
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 = "Do not mix multisite and standard specs. Consider moving multisite describes to a separate file."
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
- if node.parent&.begin_type?
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 = "Use the test helpers provided by Sidekiq instead of mocking `Jobs.expects(:enqueue)`."
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 = "ActiveRecord::ModelSchema.reset_column_information is not thread-safe " \
12
- "and we run migrations concurrently on multisite clusters. Using this " \
13
- "method also means ActiveRecord methods are being used in migration "\
14
- "which is discouraged at Discourse. Instead, you should write SQL in your migrations instead."
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 = "URI.escape, URI.encode, URI.unescape, URI.decode are deprecated and should not be used."
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
- return if [
39
- using_uri_escape?(node),
40
- using_uri_encode?(node),
41
- using_uri_unescape?(node),
42
- using_uri_decode?(node)
43
- ].none?
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
@@ -47,11 +47,7 @@ module RuboCop
47
47
  MATCHER
48
48
 
49
49
  def top_level?(node)
50
- if node.parent&.begin_type?
51
- node.parent.root?
52
- else
53
- node.root?
54
- end
50
+ node.parent&.begin_type? ? node.parent.root? : node.root?
55
51
  end
56
52
  end
57
53
  end
@@ -3,9 +3,9 @@
3
3
  module RuboCop
4
4
  # RuboCop Discourse project namespace
5
5
  module Discourse
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
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:
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = "rubocop-discourse"
5
- s.version = "3.1.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"
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
- - "**/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/**/*"
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
- RSpec/Capybara/CurrentPathExpectation:
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 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
- describe RuboCop::Cop::Discourse::NoAddReferenceOrAliasesActiveRecordMigration, :config do
5
+ describe RuboCop::Cop::Discourse::NoAddReferenceOrAliasesActiveRecordMigration,
6
+ :config do
6
7
  subject(:cop) { described_class.new(config) }
7
- let(:config) do
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 'spec_helper'
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) do
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 'spec_helper'
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) do
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 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
- describe RuboCop::Cop::Discourse::NoResetColumnInformationInMigrations, :config do
5
+ describe RuboCop::Cop::Discourse::NoResetColumnInformationInMigrations,
6
+ :config do
6
7
  subject(:cop) { described_class.new(config) }
7
8
 
8
- let(:config) do
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 'spec_helper'
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) do
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 'spec_helper'
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) do
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 'bundler/setup'
3
+ require "bundler/setup"
4
4
  Bundler.setup
5
5
 
6
6
  # Require supporting files exposed for testing.
7
- require 'rubocop'
8
- require 'rubocop/rspec/support'
7
+ require "rubocop"
8
+ require "rubocop/rspec/support"
9
9
 
10
- require 'rubocop-discourse' # and any other gems you need
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.6
9
+ TargetRubyVersion: 3.2
10
10
  DisabledByDefault: true
11
11
  Exclude:
12
- - "db/schema.rb"
13
- - "bundle/**/*"
14
- - "vendor/**/*"
15
- - "**/node_modules/**/*"
16
- - "public/**/*"
17
- - "plugins/**/gems/**/*"
18
- - "plugins/**/vendor/**/*"
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.1.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-02-16 00:00:00.000000000 Z
11
+ date: 2023-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop