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 +4 -4
- data/.rubocop.yml +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/config/default.yml +8 -0
- data/lib/rubocop/cop/sevencop/method_definition_ordered.rb +1 -3
- data/lib/rubocop/cop/sevencop/require_ordered.rb +1 -1
- data/lib/rubocop/cop/sevencop/rspec_describe_http_endpoint.rb +64 -0
- data/lib/sevencop/cop_concerns/ordered.rb +21 -14
- data/lib/sevencop/version.rb +1 -1
- data/lib/sevencop.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a5c6bd0519b94116517f840ad8b192901dc75c15ebe65abc448f5eb5bb35a5b
|
4
|
+
data.tar.gz: db75fc90b34060eb00308bb14182e3513465243ab9f24739f7baa7f90f374abe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c1fa9ec76954f0f2fb8a7db9fb3ed328ef6dfbd9a7e98997abfbc2fe277af1771453ea954df373e42600e629eda7561b74ec21a73fc7e783742e32aff3f2be8
|
7
|
+
data.tar.gz: bf3f45bf67ccdd187355c81c586eb46903696c89d3234eabb1009938cbc62a7866a4158aec3ff91f1cdf7d4c4fcc59171c8f9e5f7c316ffdf8fe76a8d93dc7f9
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
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),
|
@@ -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
|
-
|
12
|
-
|
13
|
-
node
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
|
data/lib/sevencop/version.rb
CHANGED
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.
|
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-
|
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
|