momocop 0.1.8 → 0.1.10

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: 65a6e94746e124b9b4b7faa9f87effebbbe8f75f7a23ac9f80ee71ef0fee674c
4
+ data.tar.gz: e32490d4c0fc3e2f02d96ad154db9ff52ef17f56ba993ac7260bc04169fa0e01
5
5
  SHA512:
6
- metadata.gz: 62c93ee8fc1733bf0a7e27e3e1a4636f6e8d70016d97646bf32e7a158ceb2950657993b15a6be622e7a579f9a7341b3ca6ff8f391ef0db53cef43bccb4e24a13
7
- data.tar.gz: 4f0cde02768b237df824f17e231ac8444a7d18603644873f45974f3dcdb931e6e4e7e946780e4f6eda3ebb88e9cda278b27665e6586da7043377fafa7bbd765b
6
+ metadata.gz: 3aae3b5142feb84c7bc741a0d988e715c9101fc16f362e71325abbe330a7952e7ccaaa1ec99f260227b5e14c967341c57a3855810da3034d12e04dadb0c2dbaa
7
+ data.tar.gz: 31a58eb60a8f1cd43dadd62d0be672620157070f00b441171db634fdd24d65b0b6967c75cf743bff77a1ae5baa4776a2d84147f7b8b99ca86f5e5087effd019e
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.10'
5
5
  end
@@ -36,7 +36,6 @@ module RuboCop
36
36
  return unless class_node
37
37
 
38
38
  class_name = class_node.value.to_s
39
- puts class_name
40
39
 
41
40
  return if class_exists?(class_name)
42
41
 
@@ -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.10
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