sevencop 0.26.2 → 0.27.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: b77d2e545ac1a1e5b85a636130c793c0268ff8740636b7a8a99e419d1991477d
4
- data.tar.gz: df0ee08ada7246f370bb32da744ea1d2482fb196eb103de0ea2546ad433517aa
3
+ metadata.gz: 9a2d0d56a1f5cbd0bc259bf81abbd5f2120f0a79e535ff9fafe6793de262dfb0
4
+ data.tar.gz: a43deda18fed1e061b3442a4bfb6ed27f7af6b71522adde160fe530326462722
5
5
  SHA512:
6
- metadata.gz: b1eaf0aea17f94ec3cdada0afc664724104d3da9abf190ea11ada7db715f39175bbc3471046af08dfc71fa5fe6841a8678becd8d9b4b85d9f2f3a071af491ed0
7
- data.tar.gz: 5c2419f1ea701a95478a872c57f40e0a8af77cdf85f2ae154f4e75ae7a0e1981d7da7fe0d57152a20ee96937f4cdb7f2aff2c431a94ea1fb222203891d74ce69
6
+ metadata.gz: f4888e9cd333099c4ec83c9d0b71349572ad471f4788efe1d8eee377f10286eb6d5c8534e6bb427ad52303f5fcf24e77fc7f3df9aab9ebc35ac726e0098b940f
7
+ data.tar.gz: 1cc3e089fa3e922131dd91e4e2c1c7fa6f835a1619bc8c9234f7f86af4e677a0d033583ea8f4eb1cfc3f1da5abc93222eb8506749c616c434350275a18859af0
data/.rubocop.yml CHANGED
@@ -32,7 +32,9 @@ RSpec/ExampleLength:
32
32
  RSpec/FilePath:
33
33
  CustomTransform:
34
34
  RSpecDescribeHttpEndpoint: rspec_describe_http_endpoint
35
+ RSpecEmptyLineAfterLet: rspec_empty_line_after_let
35
36
  RSpecExamplesInSameGroup: rspec_examples_in_same_group
37
+ RSpecMemoizedHelperBlockDelimiter: rspec_memoized_helper_block_delimiter
36
38
 
37
39
  RSpec/MultipleExpectations:
38
40
  Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sevencop (0.26.2)
4
+ sevencop (0.27.0)
5
5
  activesupport
6
6
  rubocop
7
7
 
data/README.md CHANGED
@@ -45,7 +45,9 @@ Note that all cops are `Enabled: false` by default.
45
45
  - [Sevencop/RailsWhereNot](lib/rubocop/cop/sevencop/rails_where_not.rb)
46
46
  - [Sevencop/RequireOrdered](lib/rubocop/cop/sevencop/require_ordered.rb)
47
47
  - [Sevencop/RSpecDescribeHttpEndpoint](lib/rubocop/cop/sevencop/rspec_describe_http_endpoint.rb)
48
+ - [Sevencop/RSpecEmptyLineAfterLet](lib/rubocop/cop/sevencop/rspec_empty_line_after_let.rb)
48
49
  - [Sevencop/RSpecExamplesInSameGroup](lib/rubocop/cop/sevencop/rspec_examples_in_same_group.rb)
50
+ - [Sevencop/RSpecMemoizedHelperBlockDelimiter](lib/rubocop/cop/sevencop/rspec_memoized_helper_block_delimiter.rb)
49
51
 
50
52
  ## Notes
51
53
 
data/config/default.yml CHANGED
@@ -141,6 +141,14 @@ Sevencop/RSpecDescribeHttpEndpoint:
141
141
  Include:
142
142
  - spec/requests/**/*.rb
143
143
 
144
+ Sevencop/RSpecEmptyLineAfterLet:
145
+ Description: |
146
+ Insert empty line after `let`.
147
+ Enabled: false
148
+ VersionAdded: '0.27'
149
+ Include:
150
+ - spec/**/*
151
+
144
152
  Sevencop/RSpecExamplesInSameGroup:
145
153
  Description: |
146
154
  Combine examples in the same groups in the time-consuming kinds of specs.
@@ -150,3 +158,11 @@ Sevencop/RSpecExamplesInSameGroup:
150
158
  Include:
151
159
  - spec/controllers/**/*
152
160
  - spec/requests/**/*
161
+
162
+ Sevencop/RSpecMemoizedHelperBlockDelimiter:
163
+ Description: |
164
+ Use do-end block delimiter on RSpec memoized helper.
165
+ Enabled: false
166
+ VersionAdded: '0.27'
167
+ Include:
168
+ - spec/**/*
@@ -8,7 +8,7 @@ module RuboCop
8
8
  # Prefer ActiveSupport date and time helper.
9
9
  #
10
10
  # @safety
11
- # This cop is unsafe becuase it considers that `n.days` is a Duration,
11
+ # This cop is unsafe because it considers that `n.days` is a Duration,
12
12
  # and `date` in `date == Date.current` is a Date, but there is no guarantee.
13
13
  #
14
14
  # @example
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'set'
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Sevencop
8
+ # Insert empty line after `let`.
9
+ #
10
+ # Since `let` defines a method, it should be written in the same style as `def`.
11
+ #
12
+ # @example
13
+ # # bad
14
+ # context 'with something' do
15
+ # let(:foo) do
16
+ # 'foo'
17
+ # end
18
+ # let(:bar) do
19
+ # 'bar'
20
+ # end
21
+ # end
22
+ #
23
+ # # good
24
+ # context 'with something' do
25
+ # let(:foo) do
26
+ # 'foo'
27
+ # end
28
+ #
29
+ # let(:bar) do
30
+ # 'bar'
31
+ # end
32
+ # end
33
+ #
34
+ # # good
35
+ # context 'with something' do
36
+ # let(:foo) do
37
+ # 'foo'
38
+ # end
39
+ # end
40
+ class RSpecEmptyLineAfterLet < Base
41
+ extend AutoCorrector
42
+
43
+ MSG = 'Insert empty line after `let`.'
44
+
45
+ # @param node [RuboCop::AST::BlockNode]
46
+ # @return [void]
47
+ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
48
+ return unless bad?(node)
49
+
50
+ add_offense(node) do |corrector|
51
+ corrector.insert_after(node.location.end, "\n")
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ # @!method let?(node)
58
+ # @param node [RuboCop::AST::BlockNode]
59
+ # @return [Boolean]
60
+ def_node_matcher :let?, <<~PATTERN
61
+ (block
62
+ (send
63
+ nil?
64
+ {:let :let!}
65
+ ...
66
+ )
67
+ ...
68
+ )
69
+ PATTERN
70
+
71
+ # @param node [RuboCop::AST::BlockNode]
72
+ # @return [Boolean]
73
+ def bad?(node)
74
+ let?(node) &&
75
+ !empty_line_after?(node) &&
76
+ !last_child?(node)
77
+ end
78
+
79
+ # @param node [RuboCop::AST::BlockNode]
80
+ # @return [Boolean]
81
+ def empty_line_after?(node)
82
+ processed_source[node.location.end.line].strip.empty?
83
+ end
84
+
85
+ # @param node [RuboCop::AST::BlockNode]
86
+ # @return [Boolean]
87
+ def last_child?(node)
88
+ !node.parent&.begin_type? ||
89
+ node.equal?(node.parent.children.last)
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'set'
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Sevencop
8
+ # Use do-end block delimiter on RSpec memoized helper.
9
+ #
10
+ # Since these helpers define methods, they should be written in the same style as `def`.
11
+ #
12
+ # @example
13
+ # # bad
14
+ # let(:foo) { 'bar' }
15
+ #
16
+ # # good
17
+ # let(:foo) do
18
+ # 'bar'
19
+ # end
20
+ #
21
+ # # bad
22
+ # subject(:foo) { 'bar' }
23
+ #
24
+ # # good
25
+ # subject(:foo) do
26
+ # 'bar'
27
+ # end
28
+ class RSpecMemoizedHelperBlockDelimiter < Base
29
+ extend AutoCorrector
30
+
31
+ include ConfigurableEnforcedStyle
32
+ include RangeHelp
33
+
34
+ MSG = 'Use do-end block delimiter on RSpec memoized helper.'
35
+
36
+ # @param node [RuboCop::AST::BlockNode]
37
+ # @return [void]
38
+ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
39
+ return unless bad?(node)
40
+
41
+ add_offense(
42
+ node.location.begin.with(
43
+ end_pos: node.location.end.end_pos
44
+ )
45
+ ) do |corrector|
46
+ autocorrect(corrector, node)
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ # @!method memoized_helper?(node)
53
+ # @param node [RuboCop::AST::Node]
54
+ # @return [Boolean]
55
+ def_node_matcher :memoized_helper?, <<~PATTERN
56
+ (block
57
+ (send
58
+ nil?
59
+ {
60
+ :let
61
+ :let!
62
+ :subject
63
+ }
64
+ ...
65
+ )
66
+ ...
67
+ )
68
+ PATTERN
69
+
70
+ # @param corrector [RuboCop::Cop::Corrector]
71
+ # @param node [RuboCop::AST::BlockNode]
72
+ # @return [void]
73
+ def autocorrect(
74
+ corrector,
75
+ node
76
+ )
77
+ corrector.insert_before(node.location.begin, ' ') unless whitespace_before?(node.location.begin)
78
+ corrector.replace(node.location.begin, 'do')
79
+ corrector.replace(node.location.end, 'end')
80
+ wrap_in_newlines(corrector, node) if node.single_line?
81
+ end
82
+
83
+ # @param node [RuboCop::AST::BlockNode]
84
+ # @return [Boolean]
85
+ def bad?(node)
86
+ memoized_helper?(node) && node.braces?
87
+ end
88
+
89
+ # @param range [Parser::Source::Range]
90
+ # @return [Boolean]
91
+ def whitespace_before?(range)
92
+ range.source_buffer.source[range.begin_pos - 1].match?(/\s/)
93
+ end
94
+
95
+ # @param corrector [RuboCop::Cop::Corrector]
96
+ # @param node [RuboCop::AST::BlockNode]
97
+ # @return [void]
98
+ def wrap_in_newlines(
99
+ corrector,
100
+ node
101
+ )
102
+ corrector.wrap(
103
+ node.location.begin.with(
104
+ begin_pos: node.location.begin.end_pos,
105
+ end_pos: node.location.end.begin_pos
106
+ ),
107
+ "\n",
108
+ "\n"
109
+ )
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sevencop
4
- VERSION = '0.26.2'
4
+ VERSION = '0.27.0'
5
5
  end
data/lib/sevencop.rb CHANGED
@@ -21,4 +21,6 @@ require_relative 'rubocop/cop/sevencop/rails_uniqueness_validator_explicit_case_
21
21
  require_relative 'rubocop/cop/sevencop/rails_where_not'
22
22
  require_relative 'rubocop/cop/sevencop/require_ordered'
23
23
  require_relative 'rubocop/cop/sevencop/rspec_describe_http_endpoint'
24
+ require_relative 'rubocop/cop/sevencop/rspec_empty_line_after_let'
24
25
  require_relative 'rubocop/cop/sevencop/rspec_examples_in_same_group'
26
+ require_relative 'rubocop/cop/sevencop/rspec_memoized_helper_block_delimiter'
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.26.2
4
+ version: 0.27.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-11-01 00:00:00.000000000 Z
11
+ date: 2022-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -73,7 +73,9 @@ files:
73
73
  - lib/rubocop/cop/sevencop/rails_where_not.rb
74
74
  - lib/rubocop/cop/sevencop/require_ordered.rb
75
75
  - lib/rubocop/cop/sevencop/rspec_describe_http_endpoint.rb
76
+ - lib/rubocop/cop/sevencop/rspec_empty_line_after_let.rb
76
77
  - lib/rubocop/cop/sevencop/rspec_examples_in_same_group.rb
78
+ - lib/rubocop/cop/sevencop/rspec_memoized_helper_block_delimiter.rb
77
79
  - lib/sevencop.rb
78
80
  - lib/sevencop/config_loader.rb
79
81
  - lib/sevencop/cop_concerns.rb