workitcop 0.4.2 → 0.5.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: 79371e45e2687e40b8c948ff054876d913874e37afec5976a0a87321b8d366fd
4
- data.tar.gz: 1b7d4eb18afc0e5aacb18858b5fde8528afd27e37c06d12153ce44da043772f5
3
+ metadata.gz: 80347b4fb04c9aa32c22b82b23dbbd0e5a2fd03ef88b315f1f1c01dfc8c93e26
4
+ data.tar.gz: 1dd7d9093b765e52c835df19e0bd433cf88a67cad7d54750d52df70347bbb919
5
5
  SHA512:
6
- metadata.gz: abf0954f07328af9294526a90d474ece1b2a385e43424daabc6e975c2c3ff9199a3d86666cdbc71224ed9da878d71958cf1123e053b469c19f8f3b9b04c8609d
7
- data.tar.gz: fc02dae95dda1045deaa1fe766a43249435a8f3afe4234714aa80622cacfc28f6eb4e288b80a55f0d55fad9451d0ec5858619f26b6cb3ede6f147265585663e7
6
+ metadata.gz: 5b3e06a38ae5d726881aaa11c9913f3dad29b53c28b8b8faf99be48f56fa8bdf53c270a081310a8bee6c8aadd8f09b7c57a247abe20ef6aea673bb23a9d7f4f9
7
+ data.tar.gz: e2e06375856be038f064a4e4c26f61b12190c4ff4a3a3e5abada637fa74535572f4a1463e1e634012c2f22e6d86474f8c03dfd486593759571fc26fb9c7c1895
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.5.0 - 2022-12-27
6
+
7
+ - Deprecate `Workit/ComitteeAssertSchemaConfirm`. ([@ydah])
8
+ - Add new `Workit/CommitteeExpectedResponseStatusCode` and `Workit/RSpecRedundantHttpStatus`. ([@ydah])
9
+
5
10
  ## 0.4.2 - 2022-12-12
6
11
 
7
12
  - Fix a false negative for `Workit/ComitteeAssertSchemaConfirm`. ([@ydah])
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # Workitcop [![Gem Version](https://badge.fury.io/rb/workitcop.svg)](https://badge.fury.io/rb/workitcop) [![CI](https://github.com/ydah/workitcop/actions/workflows/ci.yml/badge.svg)](https://github.com/ydah/workitcop/actions/workflows/ci.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/77fd345a1f0e8ab706ed/maintainability)](https://codeclimate.com/github/ydah/workitcop/maintainability)
1
+ # Workitcop
2
+
3
+ ![GitHub top language](https://img.shields.io/github/languages/top/ydah/workitcop?color=39ff14) [![Gem Version](https://badge.fury.io/rb/workitcop.svg)](https://badge.fury.io/rb/workitcop) [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop) [![CI](https://github.com/ydah/workitcop/actions/workflows/ci.yml/badge.svg)](https://github.com/ydah/workitcop/actions/workflows/ci.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/77fd345a1f0e8ab706ed/maintainability)](https://codeclimate.com/github/ydah/workitcop/maintainability)
2
4
 
3
5
  Custom cops for [RuboCop](https://github.com/rubocop/rubocop).
4
6
 
@@ -16,28 +18,13 @@ If bundler is not being used to manage dependencies, install the gem by executin
16
18
  gem install workitcop
17
19
  ```
18
20
 
19
- ## Usage
20
-
21
- You need to tell RuboCop to load the Workitcop extension.
21
+ ## Documentation
22
22
 
23
- ### RuboCop configuration file
23
+ You can read a lot more about Workitcop in its [official docs](https://ydah.github.io/docs.wkt).
24
24
 
25
- Put this into your `.rubocop.yml`.
26
-
27
- ```yaml
28
- require: workitcop
29
- ```
30
-
31
- Alternatively, use the following array notation when specifying multiple extensions.
32
-
33
- ```yaml
34
- require:
35
- - rubocop-other-extension
36
- - workitcop
37
- ```
25
+ ## Changelog
38
26
 
39
- Now you can run `rubocop` and it will automatically load the Workitcop
40
- cops together with the standard cops.
27
+ Workitcop's changelog is available [here](https://github.com/ydah/workitcop/blob/main/CHANGELOG.md).
41
28
 
42
29
  ## License
43
30
 
data/config/default.yml CHANGED
@@ -8,7 +8,7 @@ Workit/ActionArgs:
8
8
  Check for controller action must be using `action_args`.
9
9
  Enabled: false
10
10
  Include:
11
- - 'controllers/**/*'
11
+ - "controllers/**/*"
12
12
  ControllerMethods:
13
13
  - index
14
14
  - show
@@ -22,8 +22,14 @@ Workit/ComitteeAssertSchemaConfirm:
22
22
  Check for not pass expected response status code to check it against the corresponding schema explicitly.
23
23
  Enabled: false
24
24
 
25
+ Workit/CommitteeExpectedResponseStatusCode:
26
+ Description: |
27
+ Check if the status code is specified as an argument to the method of the Committee
28
+ where the expected response status code is required.
29
+ Enabled: false
30
+
25
31
  Workit/NoopRescue:
26
- Description: 'Check for suppress or ignore checked exception.'
32
+ Description: "Check for suppress or ignore checked exception."
27
33
  Enabled: false
28
34
 
29
35
  Workit/RestrictOnSend:
@@ -48,3 +54,7 @@ Workit/RSpecCapybaraPredicateMatcher:
48
54
  Workit/RSpecMinitestAssertions:
49
55
  Description: Check if using Minitest matchers.
50
56
  Enabled: false
57
+
58
+ Workit/RSpecRedundantHttpStatus:
59
+ Description: Check for validation of redundant response HTTP status codes.
60
+ Enabled: false
@@ -5,52 +5,11 @@ module RuboCop
5
5
  module Workit
6
6
  # Check for not pass expected response status code to check it against the corresponding schema explicitly.
7
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
8
+ # This cop is deprecated.
16
9
  #
17
- # # good
18
- # it 'something' do
19
- # subject
20
- # do_something
21
- # assert_schema_conform(400)
22
- # end
10
+ # @see https://www.rubydoc.info/gems/workitcop/RuboCop/Cop/Workit/CommitteeExpectedResponseStatusCode
23
11
  #
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
- return autocorrect(node, child_node, value)
41
- end
42
-
43
- add_offense(node)
44
- end
45
-
46
- private
47
-
48
- def autocorrect(node, child_node, value)
49
- add_offense(node) do |corrector|
50
- corrector.remove(range_by_whole_lines(child_node.parent.loc.expression, include_final_newline: true))
51
- corrector.insert_after(node, "(#{value})")
52
- end
53
- end
12
+ class ComitteeAssertSchemaConfirm < CommitteeExpectedResponseStatusCode
54
13
  end
55
14
  end
56
15
  end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Workit
6
+ # Check if the status code is specified as an argument to the method of the Committee
7
+ # where the expected response status code is required.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # it 'something' do
12
+ # subject
13
+ # expect(response).to have_http_status 400
14
+ # assert_schema_conform
15
+ # end
16
+ #
17
+ # # good
18
+ # it 'something' do
19
+ # subject
20
+ # assert_schema_conform(400)
21
+ # end
22
+ #
23
+ class CommitteeExpectedResponseStatusCode < Base
24
+ include RangeHelp
25
+ extend AutoCorrector
26
+
27
+ MSG = "Specify the HTTP status code of the expected response as an argument."
28
+ RESTRICT_ON_SEND = %i[assert_schema_conform assert_response_schema_confirm].freeze
29
+
30
+ # @!method have_http_status(node)
31
+ def_node_search :have_http_status, <<~PATTERN
32
+ (send nil? :have_http_status (:int $_))
33
+ PATTERN
34
+
35
+ def on_send(node)
36
+ return if node.arguments?
37
+
38
+ have_http_status(node.parent) do |status|
39
+ return autocorrect(node, status)
40
+ end
41
+
42
+ add_offense(node)
43
+ end
44
+
45
+ private
46
+
47
+ def autocorrect(node, status)
48
+ add_offense(node) do |corrector|
49
+ corrector.insert_after(node, "(#{status})")
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Workit
6
+ # Check for validation of redundant response HTTP status codes.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # it 'something' do
11
+ # subject
12
+ # expect(response).to have_http_status 400
13
+ # assert_schema_conform(400)
14
+ # end
15
+ #
16
+ # # good
17
+ # it 'something' do
18
+ # subject
19
+ # assert_schema_conform(400)
20
+ # end
21
+ #
22
+ class RSpecRedundantHttpStatus < Base
23
+ include RangeHelp
24
+ extend AutoCorrector
25
+
26
+ MSG = "Remove redundant HTTP response status code validation."
27
+ RESTRICT_ON_SEND = %i[assert_schema_conform assert_response_schema_confirm].freeze
28
+
29
+ # @!method have_http_status(node)
30
+ def_node_search :have_http_status, <<~PATTERN
31
+ $(send nil? :have_http_status (:int _))
32
+ PATTERN
33
+
34
+ def on_send(node)
35
+ return if node.first_argument.nil?
36
+
37
+ have_http_status(node.parent) do |http_node|
38
+ return autocorrect(node, http_node.parent.loc.expression)
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def autocorrect(_node, bad_range)
45
+ add_offense(bad_range) do |corrector|
46
+ corrector.remove(range_by_whole_lines(bad_range, include_final_newline: true))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Workitcop
4
- VERSION = "0.4.2"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/workitcop.rb CHANGED
@@ -8,12 +8,16 @@ require_relative "rubocop/cop/workit/mixin/rspec_inflected_help"
8
8
  require_relative "rubocop/cop/workit/mixin/rspec_predicate_matcher_base"
9
9
 
10
10
  require_relative "rubocop/cop/workit/action_args"
11
- require_relative "rubocop/cop/workit/comittee_assert_schema_confirm"
11
+ require_relative "rubocop/cop/workit/committee_expected_response_status_code"
12
12
  require_relative "rubocop/cop/workit/noop_rescue"
13
13
  require_relative "rubocop/cop/workit/restrict_on_send"
14
14
  require_relative "rubocop/cop/workit/rspec_capybara_match_style"
15
15
  require_relative "rubocop/cop/workit/rspec_capybara_predicate_matcher"
16
16
  require_relative "rubocop/cop/workit/rspec_minitest_assertions"
17
+ require_relative "rubocop/cop/workit/rspec_redundant_http_status"
18
+
19
+ # deprecated
20
+ require_relative "rubocop/cop/workit/comittee_assert_schema_confirm"
17
21
 
18
22
  module Workitcop
19
23
  PROJECT_ROOT = ::Pathname.new(__dir__).parent.expand_path.freeze
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.4.2
4
+ version: 0.5.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-12-12 00:00:00.000000000 Z
11
+ date: 2022-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -40,6 +40,7 @@ files:
40
40
  - config/default.yml
41
41
  - lib/rubocop/cop/workit/action_args.rb
42
42
  - lib/rubocop/cop/workit/comittee_assert_schema_confirm.rb
43
+ - lib/rubocop/cop/workit/committee_expected_response_status_code.rb
43
44
  - lib/rubocop/cop/workit/mixin/rspec_explicit_help.rb
44
45
  - lib/rubocop/cop/workit/mixin/rspec_inflected_help.rb
45
46
  - lib/rubocop/cop/workit/mixin/rspec_predicate_matcher_base.rb
@@ -48,6 +49,7 @@ files:
48
49
  - lib/rubocop/cop/workit/rspec_capybara_match_style.rb
49
50
  - lib/rubocop/cop/workit/rspec_capybara_predicate_matcher.rb
50
51
  - lib/rubocop/cop/workit/rspec_minitest_assertions.rb
52
+ - lib/rubocop/cop/workit/rspec_redundant_http_status.rb
51
53
  - lib/workitcop.rb
52
54
  - lib/workitcop/inject.rb
53
55
  - lib/workitcop/version.rb