momocop 0.1.8 → 0.1.9

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: 5441b62d81c8c1015b71ffb8f1457afe3be66007280372c5d239102ab08e9382
4
- data.tar.gz: 3e030584e817127a5d77d83c7ff25d87438ce11d494556d19c196067503db69a
3
+ metadata.gz: dd1936728acc124e621799990c68af8e6aa54c7cd984ce038efcbe8929c2416c
4
+ data.tar.gz: 0b6b2242cb847844e0279ff35193c391922facae5c32dc2ca86cf7778e97aebc
5
5
  SHA512:
6
- metadata.gz: 62c93ee8fc1733bf0a7e27e3e1a4636f6e8d70016d97646bf32e7a158ceb2950657993b15a6be622e7a579f9a7341b3ca6ff8f391ef0db53cef43bccb4e24a13
7
- data.tar.gz: 4f0cde02768b237df824f17e231ac8444a7d18603644873f45974f3dcdb931e6e4e7e946780e4f6eda3ebb88e9cda278b27665e6586da7043377fafa7bbd765b
6
+ metadata.gz: 34e3af0e7bcb5a2b3091fa79e713ceb4fd50acc2bec9c7c815680fb93cb37e0052ba08d70e2adc35a5ba4718c4b622e738acfc0a0e6f33113021978eedb3b1f7
7
+ data.tar.gz: fa078fbc91b3bfe61ac9da25463b59eaab3871e882c16f9e59e8d40d04bb12d82e948d6c08d933a6534b7600661fb6ce13db3009fbfcf850d5ca4cdf2708ce85
data/.rubocop.yml CHANGED
@@ -56,6 +56,9 @@ Style/FrozenStringLiteralComment:
56
56
  Style/IfUnlessModifier:
57
57
  Enabled: false
58
58
 
59
+ Style/MultilineBlockChain:
60
+ Enabled: false
61
+
59
62
  Style/ParallelAssignment:
60
63
  Enabled: false
61
64
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Momocop
4
- VERSION = '0.1.8'
4
+ VERSION = '0.1.9'
5
5
  end
@@ -47,7 +47,7 @@ module RuboCop
47
47
  unless block_node
48
48
  add_offense(node, message: MSG) do |corrector|
49
49
  indentation = ' ' * node.loc.column
50
- corrector.insert_after(node.source_range.end, " do\n#{indentation}end")
50
+ corrector.replace(node.source_range, "#{node.source} do\n#{indentation}end")
51
51
  end
52
52
  end
53
53
 
@@ -54,7 +54,7 @@ module RuboCop
54
54
  unless block_node
55
55
  add_offense(node, message: MSG) do |corrector|
56
56
  indentation = ' ' * node.loc.column
57
- corrector.insert_after(node.source_range.end, " do\n#{indentation}end")
57
+ corrector.replace(node.source_range, "#{node.source} do\n#{indentation}end")
58
58
  end
59
59
  end
60
60
 
@@ -55,7 +55,9 @@ module RuboCop
55
55
 
56
56
  sections =
57
57
  entire_definitions
58
- .slice_when { |a, b| b.loc.last_line - a.loc.last_line > 1 }
58
+ .slice_when { |a, b|
59
+ (range_with_comments(b).first_line - range_with_comments(a).last_line) > 1
60
+ }
59
61
  .select { |definitions| definitions.size >= 2 }
60
62
 
61
63
  sections.each do |definitions|
@@ -85,14 +87,28 @@ module RuboCop
85
87
 
86
88
  private def defined_properties(block_node)
87
89
  body_node = block_node&.children&.last
88
- body_node&.children&.select { |node| definition_node?(node) } || []
90
+
91
+ # empty block
92
+ return [] unless body_node
93
+
94
+ # begin
95
+ if body_node.begin_type?
96
+ body_node&.children&.select { |node| definition_node?(node) } || []
97
+ # block
98
+ elsif body_node.send_type? && definition_node?(body_node)
99
+ [body_node]
100
+ else
101
+ []
102
+ end
89
103
  end
90
104
 
105
+ RUBOCOP_HELPER_METHODS = %i[trait transient before after].freeze
106
+
91
107
  private def definition_node?(node)
92
108
  if node.send_type?
93
- return node.method_name != :trait
109
+ return !RUBOCOP_HELPER_METHODS.include?(node.method_name)
94
110
  elsif node.block_type? && node.children.first.send_type?
95
- return node.children.first.method_name != :trait
111
+ return !RUBOCOP_HELPER_METHODS.include?(node.children.first.method_name)
96
112
  end
97
113
 
98
114
  return false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: momocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - supermomonga
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 1.49.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 1.49.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rubocop-rails
43
43
  requirement: !ruby/object:Gem::Requirement