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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6c89d85d00daa4de08f8ff85f9beb0e6a5bcd29
4
- data.tar.gz: e969f72b56a52533992b579bd16944e3da275c85
3
+ metadata.gz: 2c5b4a2b9fd64fc712fe87e8217705c9fc10fb37
4
+ data.tar.gz: 01cf3213671f4e9a18ad2e355b549dc5ee38ab06
5
5
  SHA512:
6
- metadata.gz: a72344c208f7cf1064a75054a384e8e7a11c1eb02fa8d9835741dbdc30c623b7bb7da614c60ab43122dd3c00155384068ead03b2349b8533c94ead24cc63a521
7
- data.tar.gz: b9e7340a802adb0e5b2bd05cbe741685859e823f85595ef2688197d91b0deed505f25b6ccafd207712c422617004af644f7f4a807b576c7f92250e1b88b9a4bf
6
+ metadata.gz: 256aea1e41241022db13ec4c7f7dabdcd7eeeb878a96282833ab63b679c0411c4d8db2dd193116847c8d42d6f96ebf78c14c4ff152f46d93d01137f8bf917f10
7
+ data.tar.gz: 5a74ed3a93cbdb4951fa3b98acb9b7a4d37581452c04fc651009298ff0b3011abae28bf87915c80b6fdb3acc2bc6eaab981dbbdd93067f621fd3f4a3dff0b46a
@@ -1,3 +1,3 @@
1
1
  module DarkFinger
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -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
- add_offense(
136
- node,
137
- message: "Model elements must appear in order: \n\n* #{required_order.join("\n* ")}\n".freeze
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dark_finger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Professor Wang Matrix PhD