rubocop-discourse 2.1.0 → 2.1.1

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: 6655fa53ae9c2bd93548aae8db88b78294303626031e03896131ca120c083021
4
- data.tar.gz: f21f3ab9e4b3b184f7e26ab16e917ad77598c076fa3a4e0bc9a4280517b9bbcf
3
+ metadata.gz: d87c5bc1d76fa5c4d785017af0f514bfd836d0a35a5b3ecb35d34c3c08f311b1
4
+ data.tar.gz: 9469659b2155d8acb12d82ce1a7bca26771862cd16975c520f8e86028f96918d
5
5
  SHA512:
6
- metadata.gz: df675e48cb73e337f4256161d8e16da66ca0c2b00c7402b983f221cc979b1594d0b8636d71672b8d16b7ea74b8be0d4d2ca94accb4dd49c2a3f7810ea13bde11
7
- data.tar.gz: a2a12b9f318aa4fcb2f18adac55efc2bc8c05ffbb151085d9d1f607b0abaf623c13960fcbd18074efc92540b7feff7f1285efc3215dc8cf50615a437192b5a03
6
+ metadata.gz: cf4d58947738c5c37cc396579058bab0241cbd5dc7d3c654be92c74fca0b4fe51fcb892f8f590738aaa4f93a76fc431632fefa50bd1994eb82b5cab989decd83
7
+ data.tar.gz: 291d805bc86a3bca91c6e32d547c8ae27bcce4335a00922ed9da22bd3d0c4cbaa2df991b8ff7c2f17a222c9fea41452c5cc9ba9f736f7d910b1c677d44978b92
@@ -1,20 +1,2 @@
1
- require:
2
- - rubocop-discourse
3
-
4
1
  inherit_from:
5
- - ./rubocop-core.yml
6
- - ./rubocop-rspec.yml
7
-
8
- AllCops:
9
- TargetRubyVersion: 2.6
10
- DisabledByDefault: true
11
- Exclude:
12
- - "db/schema.rb"
13
- - "bundle/**/*"
14
- - "vendor/**/*"
15
- - "node_modules/**/*"
16
- - "public/**/*"
17
- - "plugins/**/gems/**/*"
18
-
19
- Discourse:
20
- Enabled: true
2
+ - default.yml
data/README.md CHANGED
@@ -7,5 +7,5 @@ Then add the following to `.rubocop.yml`:
7
7
 
8
8
  ```yml
9
9
  inherit_gem:
10
- rubocop-discourse: .rubocop.yml
10
+ rubocop-discourse: default.yml
11
11
  ```
@@ -4,14 +4,28 @@ Discourse/NoChdir:
4
4
  - 'spec/**/*' # Specs are run sequentially, so chdir can be used
5
5
  - 'plugins/*/spec/**/*'
6
6
 
7
- Discourse/NoDirectMultisiteManipulation:
8
- Enabled: true
9
-
10
7
  Discourse/NoTimeNewWithoutArgs:
11
8
  Enabled: true
12
9
 
13
10
  Discourse/NoUriEscapeEncode:
14
11
  Enabled: true
15
12
 
13
+ # Specs
14
+
15
+ Discourse/NoDirectMultisiteManipulation:
16
+ Enabled: true
17
+ Patterns:
18
+ - _spec.rb
19
+ - "(?:^|/)spec/"
20
+
16
21
  Discourse/TimeEqMatcher:
17
22
  Enabled: true
23
+ Patterns:
24
+ - _spec.rb
25
+ - "(?:^|/)spec/"
26
+
27
+ Discourse/NoJsonParseResponse:
28
+ Enabled: true
29
+ Patterns:
30
+ - _spec.rb
31
+ - "(?:^|/)spec/"
@@ -0,0 +1,20 @@
1
+ require:
2
+ - rubocop-discourse
3
+
4
+ inherit_from:
5
+ - ./rubocop-core.yml
6
+ - ./rubocop-rspec.yml
7
+
8
+ AllCops:
9
+ TargetRubyVersion: 2.6
10
+ DisabledByDefault: true
11
+ Exclude:
12
+ - "db/schema.rb"
13
+ - "bundle/**/*"
14
+ - "vendor/**/*"
15
+ - "node_modules/**/*"
16
+ - "public/**/*"
17
+ - "plugins/**/gems/**/*"
18
+
19
+ Discourse:
20
+ Enabled: true
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Discourse
6
+ # Use `response.parsed_body` instead of `JSON.parse(response.body)` in specs.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # expect(::JSON.parse(response.body)).to eq({})
11
+ #
12
+ # # good
13
+ # expect(response.parsed_body).to eq({})
14
+ class NoJsonParseResponse < Cop
15
+ MSG = "Use `response.parsed_body` instead of `JSON.parse(response.body)` in specs."
16
+
17
+ def_node_matcher :json_parse_body?, <<-MATCHER
18
+ (send
19
+ (const {cbase nil?} :JSON) :parse
20
+ (send
21
+ (send nil? :response) :body))
22
+ MATCHER
23
+
24
+ def on_send(node)
25
+ return unless json_parse_body?(node)
26
+
27
+ add_offense(node, message: MSG)
28
+ end
29
+
30
+ def autocorrect(node)
31
+ lambda do |corrector|
32
+ corrector.replace(node.loc.expression, "response.parsed_body")
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "rubocop-discourse"
5
- s.version = "2.1.0"
5
+ s.version = "2.1.1"
6
6
  s.summary = "Custom rubocop cops used by Discourse"
7
7
  s.authors = ["David Taylor"]
8
8
  s.files = `git ls-files`.split($/)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-discourse
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Taylor
@@ -66,9 +66,11 @@ files:
66
66
  - README.md
67
67
  - Rakefile
68
68
  - config/default.yml
69
+ - default.yml
69
70
  - lib/rubocop-discourse.rb
70
71
  - lib/rubocop/cop/discourse/no_chdir.rb
71
72
  - lib/rubocop/cop/discourse/no_direct_multisite_manipulation.rb
73
+ - lib/rubocop/cop/discourse/no_json_parse_response.rb
72
74
  - lib/rubocop/cop/discourse/no_time_new_without_args.rb
73
75
  - lib/rubocop/cop/discourse/no_uri_escape_encode.rb
74
76
  - lib/rubocop/cop/discourse/time_eq_matcher.rb