sevencop 0.17.2 → 0.18.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: bb03ae9347c8419a82327535021c4567f50ee667fa6b49d01de0766c9db17b19
4
- data.tar.gz: 219b887de52c24ffd4c6baf30b6443311e297b4ef1e3b03895d60f874b145b1f
3
+ metadata.gz: 4a5c6bd0519b94116517f840ad8b192901dc75c15ebe65abc448f5eb5bb35a5b
4
+ data.tar.gz: db75fc90b34060eb00308bb14182e3513465243ab9f24739f7baa7f90f374abe
5
5
  SHA512:
6
- metadata.gz: 4a8c1fba03d1a7e5bacae6aa878f9d6284c8b1c5becd745285b5e5f3910784ecc5b815191d0a1f4c7f0e6ee06e70109a58af8bd5dd78797bacaf053a7857e42b
7
- data.tar.gz: b0d4562158515e27a4bbc8c3e90a633bcaeb548267ab208b92e55931416b843340c5b2a528f3bcfbd72f430701513aeda02fcbfb2dc8602945456a94eb1ece4d
6
+ metadata.gz: 4c1fa9ec76954f0f2fb8a7db9fb3ed328ef6dfbd9a7e98997abfbc2fe277af1771453ea954df373e42600e629eda7561b74ec21a73fc7e783742e32aff3f2be8
7
+ data.tar.gz: bf3f45bf67ccdd187355c81c586eb46903696c89d3234eabb1009938cbc62a7866a4158aec3ff91f1cdf7d4c4fcc59171c8f9e5f7c316ffdf8fe76a8d93dc7f9
data/.rubocop.yml CHANGED
@@ -28,6 +28,7 @@ RSpec/ExampleLength:
28
28
 
29
29
  RSpec/FilePath:
30
30
  CustomTransform:
31
+ RSpecDescribeHttpEndpoint: rspec_describe_http_endpoint
31
32
  RSpecExamplesInSameGroup: rspec_examples_in_same_group
32
33
 
33
34
  RSpec/MultipleExpectations:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sevencop (0.17.2)
4
+ sevencop (0.18.0)
5
5
  rubocop
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -39,6 +39,7 @@ Choose the cops you want to use and enable them on your .rubocop.yml.
39
39
  - [Sevencop/RailsUniquenessValidatorExplicitCaseSensitivity](lib/rubocop/cop/sevencop/rails_uniqueness_validator_explicit_case_sensitivity.rb)
40
40
  - [Sevencop/RailsWhereNot](lib/rubocop/cop/sevencop/rails_where_not.rb)
41
41
  - [Sevencop/RequireOrdered](lib/rubocop/cop/sevencop/require_ordered.rb)
42
+ - [Sevencop/RSpecDescribeHttpEndpoint](lib/rubocop/cop/sevencop/rspec_describe_http_endpoint.rb)
42
43
  - [Sevencop/RSpecExamplesInSameGroup](lib/rubocop/cop/sevencop/rspec_examples_in_same_group.rb)
43
44
 
44
45
  Note that all cops are `Enabled: false` by default.
data/config/default.yml CHANGED
@@ -68,6 +68,14 @@ Sevencop/RequireOrdered:
68
68
  Enabled: false
69
69
  VersionAdded: '0.16'
70
70
 
71
+ Sevencop/RSpecDescribeHttpEndpoint:
72
+ Description: |
73
+ Pass HTTP endpoint identifier to top-level `describe` on request-specs.
74
+ Enabled: false
75
+ VersionAdded: '0.18'
76
+ Include:
77
+ - spec/requests/**/*.rb
78
+
71
79
  Sevencop/RSpecExamplesInSameGroup:
72
80
  Description: |
73
81
  Combine examples in the same groups in the time-consuming kinds of specs.
@@ -40,9 +40,7 @@ module RuboCop
40
40
  previous_older_sibling = find_previous_older_sibling(node)
41
41
  return unless previous_older_sibling
42
42
 
43
- add_offense(
44
- range_with_comments(node)
45
- ) do |corrector|
43
+ add_offense(node) do |corrector|
46
44
  swap(
47
45
  range_with_comments_and_lines(previous_older_sibling),
48
46
  range_with_comments_and_lines(node),
@@ -52,7 +52,7 @@ module RuboCop
52
52
  return unless previous_older_sibling
53
53
 
54
54
  add_offense(
55
- range_with_comments(node),
55
+ node,
56
56
  message: "Sort `#{node.method_name}` in alphabetical order."
57
57
  ) do |corrector|
58
58
  swap(
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Sevencop
6
+ # Pass HTTP endpoint identifier to top-level `describe` on request-specs.
7
+ #
8
+ # @see https://github.com/r7kamura/rspec-request_describer
9
+ #
10
+ # @example
11
+ # # bad
12
+ # RSpec.describe 'Users'
13
+ #
14
+ # # good
15
+ # RSpec.describe 'GET /users'
16
+ class RSpecDescribeHttpEndpoint < Base
17
+ MSG = 'Pass HTTP endpoint identifier to top-level `describe` on request-specs.'
18
+
19
+ RESTRICT_ON_SEND = %i[
20
+ describe
21
+ ].freeze
22
+
23
+ SUPPORTED_HTTP_METHODS = %w[
24
+ DELETE
25
+ GET
26
+ PATCH
27
+ POST
28
+ PUT
29
+ ].freeze
30
+
31
+ DESCRIPTION_PATTERN = %r{\A#{::Regexp.union(SUPPORTED_HTTP_METHODS)} /}.freeze
32
+
33
+ # @param node [RuboCop::AST::SendNode]
34
+ # @return [void]
35
+ def on_send(node)
36
+ return unless top_level_describe?(node)
37
+ return unless node.first_argument
38
+ return if http_endpoint_identifier?(node.first_argument)
39
+
40
+ add_offense(node.first_argument)
41
+ end
42
+
43
+ private
44
+
45
+ # @!method top_level_describe?(node)
46
+ # @param node [RuboCop::AST::SendNode]
47
+ # @return [Boolean]
48
+ def_node_matcher :top_level_describe?, <<~PATTERN
49
+ (send
50
+ (const nil? :RSpec)
51
+ :describe
52
+ _
53
+ )
54
+ PATTERN
55
+
56
+ # @param node [RuboCop::AST::Node]
57
+ # @return [Boolean]
58
+ def http_endpoint_identifier?(node)
59
+ node.is_a?(::RuboCop::AST::StrNode) && node.value.match?(DESCRIPTION_PATTERN)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -5,23 +5,30 @@ module Sevencop
5
5
  module Ordered
6
6
  private
7
7
 
8
+ # @param range1 [Paresr::Source::Range]
9
+ # @param range2 [Paresr::Source::Range]
10
+ # @return [Paresr::Source::Range]
11
+ def add_range(
12
+ range1,
13
+ range2
14
+ )
15
+ range1.with(
16
+ begin_pos: [range1.begin_pos, range2.begin_pos].min,
17
+ end_pos: [range1.end_pos, range2.end_pos].max
18
+ )
19
+ end
20
+
8
21
  # @param node [RuboCop::AST::Node]
9
22
  # @return [Paresr::Source::Range]
10
23
  def range_with_comments(node)
11
- comment = processed_source.ast_with_comments[node].first
12
- if comment
13
- node.location.expression.with(
14
- begin_pos: [
15
- comment.location.expression.begin_pos,
16
- node.location.expression.begin_pos
17
- ].min,
18
- end_pos: [
19
- comment.location.expression.end_pos,
20
- node.location.expression.end_pos
21
- ].max
22
- )
23
- else
24
- node.location.expression
24
+ ranges = [
25
+ node,
26
+ *processed_source.ast_with_comments[node]
27
+ ].map do |element|
28
+ element.location.expression
29
+ end
30
+ ranges.reduce do |result, range|
31
+ add_range(result, range)
25
32
  end
26
33
  end
27
34
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sevencop
4
- VERSION = '0.17.2'
4
+ VERSION = '0.18.0'
5
5
  end
data/lib/sevencop.rb CHANGED
@@ -15,4 +15,5 @@ require_relative 'rubocop/cop/sevencop/rails_order_field'
15
15
  require_relative 'rubocop/cop/sevencop/rails_uniqueness_validator_explicit_case_sensitivity'
16
16
  require_relative 'rubocop/cop/sevencop/rails_where_not'
17
17
  require_relative 'rubocop/cop/sevencop/require_ordered'
18
+ require_relative 'rubocop/cop/sevencop/rspec_describe_http_endpoint'
18
19
  require_relative 'rubocop/cop/sevencop/rspec_examples_in_same_group'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sevencop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.2
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-07 00:00:00.000000000 Z
11
+ date: 2022-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -52,6 +52,7 @@ files:
52
52
  - lib/rubocop/cop/sevencop/rails_uniqueness_validator_explicit_case_sensitivity.rb
53
53
  - lib/rubocop/cop/sevencop/rails_where_not.rb
54
54
  - lib/rubocop/cop/sevencop/require_ordered.rb
55
+ - lib/rubocop/cop/sevencop/rspec_describe_http_endpoint.rb
55
56
  - lib/rubocop/cop/sevencop/rspec_examples_in_same_group.rb
56
57
  - lib/sevencop.rb
57
58
  - lib/sevencop/config_loader.rb