empty_example_cop 0.1.0 → 0.1.1

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: e0be7d5ab101cb6b152cab80a9507240fbf5b59dea8434269c96d4046c9c1161
4
- data.tar.gz: 0bde0aed2a517db144d47d6d234c5600d3d44d5c9a703771d69238675b54cef1
3
+ metadata.gz: '096f55917d0f21e125d90a8126c533fbff48df8d7695bcff14879ae6d894dbc4'
4
+ data.tar.gz: bf13a1aa5321e5565451c00d90948da370661834b3ec75a1b4f2a1578e9163e0
5
5
  SHA512:
6
- metadata.gz: 07e31362cadd4a8deb31cbb3fa731c21aeeb47e62d48c91c25943c3ec257d65603de5f033d32df4da8d9c03019dc2bb6fabba0b8cb8cc4ed9e81cd3ebeb89ea5
7
- data.tar.gz: c361a76eb0fefaa8c0dad94d2a78d07c88e034c84181320b226b0d8308c4d70be4c52b677d626a541cc34af3e0f923b564511e13986c9c61bab52f5c7320e960
6
+ metadata.gz: 4ee09ad3a6d184e23bd4dfeb3c1743170f9907bd9afd7b2345fc73cec11f15b136ad52ebea2debfee307f9e4ba6ad39d3509d4e2ee3dbaf5e456f2512cad74a3
7
+ data.tar.gz: d73461f323bf058bfeedf0c295d5ae0fe11953ee9fb58b4e972169cc479407e45a6a4439a264cc5034ec885d3699226c88d8ac1ec35ff344db4dc5ebc6084205
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.1.1] - 2022-07-12
2
+
3
+ - Add autocorrect
4
+
1
5
  ## [0.1.0] - 2021-12-06
2
6
 
3
7
  - Initial release
data/config/default.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  RSpec/EmptyExample:
2
2
  Description: Detect empty examples which don't include any expectations.
3
3
  Enabled: true
4
+ SafeAutoCorrect: false
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EmptyExampleCop
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -4,6 +4,10 @@ module RuboCop
4
4
  module Cop
5
5
  module RSpec
6
6
  class EmptyExample < Base
7
+ extend AutoCorrector
8
+
9
+ include RangeHelp
10
+
7
11
  # Checks if an example does not include any expectations.
8
12
  #
9
13
  # @example usage
@@ -29,9 +33,9 @@ module RuboCop
29
33
  # end
30
34
  MSG = 'Empty example detected.'
31
35
 
32
- def_node_matcher :it_description?, <<-PATTERN
36
+ def_node_matcher :it_description, <<-PATTERN
33
37
  (block
34
- (send nil? :it ...) ...)
38
+ (send nil? :it $...) ...)
35
39
  PATTERN
36
40
 
37
41
  def_node_matcher :expect?, <<-PATTERN
@@ -47,10 +51,16 @@ module RuboCop
47
51
  PATTERN
48
52
 
49
53
  def on_block(node)
50
- return unless it_description?(node)
54
+ description = it_description(node)
55
+ return if description.nil?
51
56
 
52
57
  unless example_present?(node)
53
- add_offense(node, message: MSG)
58
+ add_offense(node, message: MSG) do |corrector|
59
+ corrector.replace(
60
+ range_by_whole_lines(node.location.expression),
61
+ "it #{description.last&.source}"
62
+ )
63
+ end
54
64
  end
55
65
  end
56
66
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: empty_example_cop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - makicamel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-06 00:00:00.000000000 Z
11
+ date: 2022-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop