workitcop 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27336368b30a080fc58a6053182931a6abb0addbf3481fc19266a008ab574c3a
4
- data.tar.gz: 23cbb18bc27d25f68003200c0eb505efec7200f45b4634fe32d9e69a2b72cdf5
3
+ metadata.gz: d9a1c429544b92ec47ac6a467cef8d26a1bea4c43371299d323441636b0ecbfc
4
+ data.tar.gz: 255c41e5e4995120ebea4370b3ef9e3a95773614d580b719c17041eec1883df9
5
5
  SHA512:
6
- metadata.gz: 9ed01c88aeabb5f4759e710555ba6566d248f800e7fc239ea0634f7a2d735acf6e5551c244fa81e810fc617438bb5094f33d344014300917e5c7afb1dec12d39
7
- data.tar.gz: f5ff520cccd27c6d58c687b2a9bf7ab34d38c931c37dd03e6f4037831ecd56309964402301572ddd3faaab6e986fac9f3ec5e2c98488153fb9399a20beeef920
6
+ metadata.gz: 6513c422e88c53f8287f61fbfeedf160232340bebeea000ebfd2389b6d92b6ffa4b4a657d1a6fff5072281b09ebbc413ace375de128eb686605956dd56b4a869
7
+ data.tar.gz: 5ea74291617530ff065df00d6ecbd3c9a5f339feb446417fae198667249e746f137424028158df6fe4ad91d364dcf6af10fc71725df7e33513e82688afdd5e50
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.3.0 - 2022-12-08
6
+
7
+ - Fix an error for `Workit/RestrictOnSend` when not in class. ([@ydah])
8
+ - Add new `Workit/ComitteeAssertSchemaConfirm` cop. ([@ydah])
9
+ - Remove VersionAdded for default.yml. ([@ydah])
10
+ - Change default to `Enabled: false`. ([@ydah])
11
+
5
12
  ## 0.2.0 - 2022-11-07
6
13
 
7
14
  - Add new `Workit/ActionArgs` cop. ([@ydah])
data/config/default.yml CHANGED
@@ -6,8 +6,7 @@ inherit_mode:
6
6
  Workit/ActionArgs:
7
7
  Description: |
8
8
  Check for controller action must be using `action_args`.
9
- Enabled: pending
10
- VersionAdded: '0.2'
9
+ Enabled: false
11
10
  Include:
12
11
  - 'controllers/**/*'
13
12
  ControllerMethods:
@@ -18,13 +17,16 @@ Workit/ActionArgs:
18
17
  - cancel
19
18
  - destroy
20
19
 
20
+ Workit/ComitteeAssertSchemaConfirm:
21
+ Description: |
22
+ Check for not pass expected response status code to check it against the corresponding schema explicitly.
23
+ Enabled: false
24
+
21
25
  Workit/NoopRescue:
22
26
  Description: 'Check for suppress or ignore checked exception.'
23
27
  Enabled: false
24
- VersionAdded: '0.2'
25
28
 
26
29
  Workit/RestrictOnSend:
27
30
  Description: |
28
31
  Check for `RESTRICT_ON_SEND` is defined if `on_send` or `after_send` are defined.
29
- Enabled: pending
30
- VersionAdded: '0.1'
32
+ Enabled: false
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Workit
6
+ # Check for not pass expected response status code to check it against the corresponding schema explicitly.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # it 'something' do
11
+ # subject
12
+ # expect(response).to have_http_status 400
13
+ # do_something
14
+ # assert_schema_conform
15
+ # end
16
+ #
17
+ # # good
18
+ # it 'something' do
19
+ # subject
20
+ # do_something
21
+ # assert_schema_conform(400)
22
+ # end
23
+ #
24
+ class ComitteeAssertSchemaConfirm < Base
25
+ include RangeHelp
26
+ extend AutoCorrector
27
+
28
+ MSG = "Pass expected response status code to check it against the corresponding schema explicitly."
29
+ RESTRICT_ON_SEND = %i[assert_schema_conform assert_response_schema_confirm].freeze
30
+
31
+ # @!method have_http_status(node)
32
+ def_node_search :have_http_status, <<~PATTERN
33
+ $(send nil? :have_http_status (:int $_))
34
+ PATTERN
35
+
36
+ def on_send(node)
37
+ return if node.arguments?
38
+
39
+ have_http_status(node.parent) do |child_node, value|
40
+ add_offense(node) do |corrector|
41
+ corrector.remove(range_by_whole_lines(child_node.parent.loc.expression, include_final_newline: true))
42
+ corrector.insert_after(node, "(#{value})")
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -30,12 +30,14 @@ module RuboCop
30
30
 
31
31
  def on_def(node)
32
32
  return unless NEED_RESTRICT_ON_SEND.include?(node.method_name)
33
+ return unless (class_node = class_node(node))
33
34
 
34
- class_node = class_node(node)
35
35
  add_offense(class_node) unless defined_restrict_on_send?(class_node)
36
36
  end
37
37
 
38
38
  def class_node(node)
39
+ return if node.parent.nil?
40
+
39
41
  if node.parent.class_type?
40
42
  node.parent
41
43
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Workitcop
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/workitcop.rb CHANGED
@@ -4,6 +4,7 @@ require_relative "workitcop/inject"
4
4
  require_relative "workitcop/version"
5
5
 
6
6
  require_relative "rubocop/cop/workit/action_args"
7
+ require_relative "rubocop/cop/workit/comittee_assert_schema_confirm"
7
8
  require_relative "rubocop/cop/workit/noop_rescue"
8
9
  require_relative "rubocop/cop/workit/restrict_on_send"
9
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workitcop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ydah
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-07 00:00:00.000000000 Z
11
+ date: 2022-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -39,6 +39,7 @@ files:
39
39
  - README.md
40
40
  - config/default.yml
41
41
  - lib/rubocop/cop/workit/action_args.rb
42
+ - lib/rubocop/cop/workit/comittee_assert_schema_confirm.rb
42
43
  - lib/rubocop/cop/workit/noop_rescue.rb
43
44
  - lib/rubocop/cop/workit/restrict_on_send.rb
44
45
  - lib/workitcop.rb
@@ -67,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
68
  - !ruby/object:Gem::Version
68
69
  version: '0'
69
70
  requirements: []
70
- rubygems_version: 3.1.4
71
+ rubygems_version: 3.3.3
71
72
  signing_key:
72
73
  specification_version: 4
73
74
  summary: Custom cops for `RuboCop`.