dark_finger 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06f1588f5fdba7fd43a67007cd3c4639b7354fd2ffd087c1e0c8bd08e50354e8
|
4
|
+
data.tar.gz: 7953b82963fb8e05b7399d3da7f2128bd6b0f7533137ca396ceac7a0fd209dcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d29b4d1db2264e116e727558943b4d02a07db7adfc8ce909ec44be254a9981414c851a8fb88db291a2312645c1ff358dd8327599188a1bcc00e6a3bfcca1bc8b
|
7
|
+
data.tar.gz: a0e8ee91d508ba696a3898350ede3b205f08c496bc780102468fa15b4496afe26b5f645eb2abab6ddd22777beb7b8c16b67b2004b96c69af960c60b6109ccf1e
|
data/README.md
CHANGED
@@ -123,9 +123,18 @@ DarkFinger/ModelStructure:
|
|
123
123
|
constant: '## Constants ##'
|
124
124
|
enum: '## Enums ##'
|
125
125
|
include: '## Includes ##'
|
126
|
+
misc: '## Misc ##'
|
126
127
|
module: '## Modules ##'
|
127
128
|
scope: '## Scopes ##'
|
128
129
|
validation: '## Validations ##'
|
130
|
+
|
131
|
+
# specify the methods that are categorized as "misc"
|
132
|
+
misc_method_names:
|
133
|
+
- acts_as_list
|
134
|
+
- acts_as_taggable
|
135
|
+
- friendly_id
|
136
|
+
- serialize
|
137
|
+
- workflow
|
129
138
|
```
|
130
139
|
|
131
140
|
Supported model elements:
|
@@ -148,6 +157,12 @@ Supported model elements:
|
|
148
157
|
| validation | |
|
149
158
|
|
150
159
|
|
160
|
+
Any model elements that are not included in "required order" will be ignored.
|
161
|
+
|
162
|
+
Dark Finger ignores everything that appears after `private`. This may change in
|
163
|
+
future, but for now we have just agreed that anything goes in the private
|
164
|
+
section of our models.
|
165
|
+
|
151
166
|
## License
|
152
167
|
|
153
168
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/dark_finger/version.rb
CHANGED
data/lib/dark_finger.rb
CHANGED
@@ -2,3 +2,5 @@ require 'rubocop'
|
|
2
2
|
require "dark_finger/version"
|
3
3
|
require File.dirname(__FILE__) + "/rubocop/cop/dark_finger/model_structure"
|
4
4
|
require File.dirname(__FILE__) + "/rubocop/cop/dark_finger/active_model_node_decorator"
|
5
|
+
require File.dirname(__FILE__) + "/rubocop/cop/dark_finger/migration_constants"
|
6
|
+
require File.dirname(__FILE__) + "/rubocop/cop/dark_finger/module_ancestor_chain_extractor"
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module RuboCop
|
2
|
+
module Cop
|
3
|
+
module DarkFinger
|
4
|
+
class MigrationConstants < ::RuboCop::Cop::Cop
|
5
|
+
DEFAULT_ALLOWED_CONSTANTS = [
|
6
|
+
'Migration',
|
7
|
+
'ActiveRecord',
|
8
|
+
'ActiveRecord::Migration',
|
9
|
+
'ActiveRecord::Base'
|
10
|
+
]
|
11
|
+
|
12
|
+
attr_reader :allowed_constants
|
13
|
+
|
14
|
+
def initialize(*args)
|
15
|
+
super
|
16
|
+
@allowed_constants = DEFAULT_ALLOWED_CONSTANTS + allowed_top_level_constants
|
17
|
+
end
|
18
|
+
|
19
|
+
def on_const(node)
|
20
|
+
return if allowed_constants.include?(node.const_name)
|
21
|
+
add_offense(node, message: %Q(Undeclared constant: "#{node.const_name}"))
|
22
|
+
end
|
23
|
+
|
24
|
+
def on_casgn(node)
|
25
|
+
add_allowed_constant(node.children[1])
|
26
|
+
end
|
27
|
+
|
28
|
+
def on_class(node)
|
29
|
+
add_allowed_constant(node.children.first.const_name)
|
30
|
+
add_module_parent_chain_for(node)
|
31
|
+
end
|
32
|
+
|
33
|
+
def on_module(node)
|
34
|
+
add_allowed_constant(node.children.first.const_name)
|
35
|
+
add_module_parent_chain_for(node)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def allowed_top_level_constants
|
41
|
+
Module.constants.map(&:to_s) - top_level_model_classes_and_containing_modules
|
42
|
+
end
|
43
|
+
|
44
|
+
def top_level_model_classes_and_containing_modules
|
45
|
+
return [] unless Object.const_defined?('ActiveRecord::Base')
|
46
|
+
|
47
|
+
::ActiveRecord::Base.descendants.map do |klass|
|
48
|
+
klass.name.sub(/::.*/, '').to_s
|
49
|
+
end.uniq
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_allowed_constant(constant)
|
53
|
+
@allowed_constants << constant.to_s
|
54
|
+
@allowed_constants.uniq!
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_module_parent_chain_for(node)
|
58
|
+
chain = ModuleAncestorChainExtractor.new(node).perform
|
59
|
+
add_allowed_constant(chain)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RuboCop
|
2
|
+
module Cop
|
3
|
+
module DarkFinger
|
4
|
+
class ModuleAncestorChainExtractor
|
5
|
+
attr_reader :node
|
6
|
+
|
7
|
+
def initialize(node)
|
8
|
+
@node = node
|
9
|
+
end
|
10
|
+
|
11
|
+
def perform
|
12
|
+
module_chain = [node.children.first.const_name]
|
13
|
+
|
14
|
+
current_node = node
|
15
|
+
while current_node.parent && current_node.parent.module_type?
|
16
|
+
module_chain << current_node.parent.children.first.const_name
|
17
|
+
current_node = current_node.parent
|
18
|
+
end
|
19
|
+
|
20
|
+
module_chain.reverse.join("::")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Professor Wang Matrix PhD
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-11-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -103,7 +103,9 @@ files:
|
|
103
103
|
- lib/dark_finger.rb
|
104
104
|
- lib/dark_finger/version.rb
|
105
105
|
- lib/rubocop/cop/dark_finger/active_model_node_decorator.rb
|
106
|
+
- lib/rubocop/cop/dark_finger/migration_constants.rb
|
106
107
|
- lib/rubocop/cop/dark_finger/model_structure.rb
|
108
|
+
- lib/rubocop/cop/dark_finger/module_ancestor_chain_extractor.rb
|
107
109
|
homepage: https://github.com/the-suBLAM-executive-council/dark_finger
|
108
110
|
licenses:
|
109
111
|
- MIT
|