momocop 0.1.7 → 0.1.8

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: 2217b77f50980c7b628b6be000f20a76093b41f13933b5e0e4c04c860215eb68
4
- data.tar.gz: 3fd67a7eb04625b7021db01f453477f804b8e48609c9f41e859579d46239d89e
3
+ metadata.gz: 5441b62d81c8c1015b71ffb8f1457afe3be66007280372c5d239102ab08e9382
4
+ data.tar.gz: 3e030584e817127a5d77d83c7ff25d87438ce11d494556d19c196067503db69a
5
5
  SHA512:
6
- metadata.gz: 5d5dfa8b78691d8cf4bc8938d3bed507969eec0dbc3940032a22eb3ca0fa705abbecc82f1f4586be8e8d9e963afd5144572399c2854abed205f85c866b75fbe4
7
- data.tar.gz: 7feb8e1104912f6d595becbd4b4fa20ec3fd38910892d52da3f64b12f5fc6ac37f4ef352f6a57b29b094d5c2fce434895eb9c54d8bc0e5516c5ce24b9ce9a082
6
+ metadata.gz: 62c93ee8fc1733bf0a7e27e3e1a4636f6e8d70016d97646bf32e7a158ceb2950657993b15a6be622e7a579f9a7341b3ca6ff8f391ef0db53cef43bccb4e24a13
7
+ data.tar.gz: 4f0cde02768b237df824f17e231ac8444a7d18603644873f45974f3dcdb931e6e4e7e946780e4f6eda3ebb88e9cda278b27665e6586da7043377fafa7bbd765b
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Momocop
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.8'
5
5
  end
@@ -43,6 +43,14 @@ module RuboCop
43
43
 
44
44
  block_node = node.block_node
45
45
 
46
+ # Add block if it's missing
47
+ unless block_node
48
+ add_offense(node, message: MSG) do |corrector|
49
+ indentation = ' ' * node.loc.column
50
+ corrector.insert_after(node.source_range.end, " do\n#{indentation}end")
51
+ end
52
+ end
53
+
46
54
  # Check missing associations
47
55
  defined_associations = get_defined_association_names(block_node)
48
56
  model_associations = get_model_association_names(class_name)
@@ -52,8 +60,6 @@ module RuboCop
52
60
  return unless missing_associations.any?
53
61
 
54
62
  add_offense(node, message: MSG) do |corrector|
55
- next unless block_node
56
-
57
63
  # Add newline before closing block if it's a one-liner
58
64
  if one_line_block?(block_node)
59
65
  indentation = ' ' * node.loc.column
@@ -66,6 +72,8 @@ module RuboCop
66
72
 
67
73
  # TODO: calculate indentation size
68
74
  indentation = ' ' * (node.loc.column + 2)
75
+
76
+ # use send node if blockless
69
77
  corrector.insert_after(block_node.loc.begin, "\n#{indentation}#{definition}")
70
78
  end
71
79
  end
@@ -76,6 +84,8 @@ module RuboCop
76
84
  end
77
85
 
78
86
  private def one_line_block?(block_node)
87
+ return false if block_node.nil?
88
+
79
89
  block_node.loc.begin.line == block_node.loc.end.line
80
90
  end
81
91
 
@@ -50,6 +50,14 @@ module RuboCop
50
50
 
51
51
  block_node = node.block_node
52
52
 
53
+ # Add block if it's missing
54
+ unless block_node
55
+ add_offense(node, message: MSG) do |corrector|
56
+ indentation = ' ' * node.loc.column
57
+ corrector.insert_after(node.source_range.end, " do\n#{indentation}end")
58
+ end
59
+ end
60
+
53
61
  # Check missing associations
54
62
 
55
63
  # Exclude defined sequences
@@ -49,6 +49,8 @@ module RuboCop
49
49
  return unless inside_factory_bot_define?(node)
50
50
 
51
51
  block_node = node.block_node
52
+ return unless block_node
53
+
52
54
  entire_definitions = defined_properties(block_node)
53
55
 
54
56
  sections =
@@ -83,11 +85,17 @@ module RuboCop
83
85
 
84
86
  private def defined_properties(block_node)
85
87
  body_node = block_node&.children&.last
86
- body_node&.children&.select { |node| definition_node?(node) }
88
+ body_node&.children&.select { |node| definition_node?(node) } || []
87
89
  end
88
90
 
89
91
  private def definition_node?(node)
90
- node.send_type? || (node.block_type? && node.children.first.send_type?)
92
+ if node.send_type?
93
+ return node.method_name != :trait
94
+ elsif node.block_type? && node.children.first.send_type?
95
+ return node.children.first.method_name != :trait
96
+ end
97
+
98
+ return false
91
99
  end
92
100
 
93
101
  private def definition_type(node)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: momocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - supermomonga
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-19 00:00:00.000000000 Z
11
+ date: 2024-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport