dark_finger 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dark_finger/version.rb +1 -1
- data/lib/rubocop/cop/dark_finger/model_structure.rb +42 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c5b4a2b9fd64fc712fe87e8217705c9fc10fb37
|
4
|
+
data.tar.gz: 01cf3213671f4e9a18ad2e355b549dc5ee38ab06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 256aea1e41241022db13ec4c7f7dabdcd7eeeb878a96282833ab63b679c0411c4d8db2dd193116847c8d42d6f96ebf78c14c4ff152f46d93d01137f8bf917f10
|
7
|
+
data.tar.gz: 5a74ed3a93cbdb4951fa3b98acb9b7a4d37581452c04fc651009298ff0b3011abae28bf87915c80b6fdb3acc2bc6eaab981dbbdd93067f621fd3f4a3dff0b46a
|
data/lib/dark_finger/version.rb
CHANGED
@@ -4,6 +4,8 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module DarkFinger
|
6
6
|
class ModelStructure < ::RuboCop::Cop::Cop
|
7
|
+
class InvalidConfigError < StandardError; end
|
8
|
+
|
7
9
|
ASSOCIATION = :association
|
8
10
|
ATTRIBUTES = :attribute
|
9
11
|
CALLBACK = :callback
|
@@ -18,6 +20,22 @@ module RuboCop
|
|
18
20
|
SCOPE = :scope
|
19
21
|
VALIDATION = :validation
|
20
22
|
|
23
|
+
KNOWN_ELEMENTS = [
|
24
|
+
ASSOCIATION,
|
25
|
+
ATTRIBUTES,
|
26
|
+
CALLBACK,
|
27
|
+
CLASS_METHOD,
|
28
|
+
CONSTANT,
|
29
|
+
CONSTRUCTOR,
|
30
|
+
ENUM,
|
31
|
+
INCLUDE,
|
32
|
+
INSTANCE_METHOD,
|
33
|
+
MISC,
|
34
|
+
MODULE,
|
35
|
+
SCOPE,
|
36
|
+
VALIDATION,
|
37
|
+
]
|
38
|
+
|
21
39
|
DEFAULT_REQUIRED_ORDER = [
|
22
40
|
MODULE,
|
23
41
|
INCLUDE,
|
@@ -61,6 +79,8 @@ module RuboCop
|
|
61
79
|
@required_order.map!(&:to_sym)
|
62
80
|
@required_comments = Hash[ @required_comments.map {|k,v| [k.to_sym, v]} ]
|
63
81
|
@misc_method_names.map!(&:to_sym)
|
82
|
+
|
83
|
+
validate_config!
|
64
84
|
end
|
65
85
|
|
66
86
|
def on_send(node)
|
@@ -132,13 +152,17 @@ module RuboCop
|
|
132
152
|
def detect_order_violation(node)
|
133
153
|
if order_violation_detected?
|
134
154
|
@order_violation_reported = true
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
)
|
155
|
+
message = "Model elements must appear in order:#{to_bullet_list(required_order)}\n"
|
156
|
+
message << "Observed order:#{to_bullet_list(class_elements_seen)}"
|
157
|
+
|
158
|
+
add_offense(node, message: message)
|
139
159
|
end
|
140
160
|
end
|
141
161
|
|
162
|
+
def to_bullet_list(array)
|
163
|
+
"\n* #{array.join("\n* ")}\n"
|
164
|
+
end
|
165
|
+
|
142
166
|
def order_violation_detected?
|
143
167
|
required_order_for_elements_seen != class_elements_seen
|
144
168
|
end
|
@@ -148,6 +172,20 @@ module RuboCop
|
|
148
172
|
required_order.index(class_elem_1) <=> required_order.index(class_elem_2)
|
149
173
|
end
|
150
174
|
end
|
175
|
+
|
176
|
+
def validate_config!
|
177
|
+
required_order.each do |i|
|
178
|
+
if !KNOWN_ELEMENTS.include?(i)
|
179
|
+
raise(InvalidConfigError, "Unknown 'required_order' model element: #{i}")
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
required_comments.keys.each do |i|
|
184
|
+
if !KNOWN_ELEMENTS.include?(i)
|
185
|
+
raise(InvalidConfigError, "Unknown 'required_comments' model element: #{i}")
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
151
189
|
end
|
152
190
|
end
|
153
191
|
end
|