ducalis 0.5.12 → 0.5.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/DOCUMENTATION.md +35 -1
- data/Gemfile.lock +1 -1
- data/config/.ducalis.yml +1 -1
- data/lib/ducalis.rb +1 -1
- data/lib/ducalis/cops/{only_defs_cope.rb → only_defs.rb} +13 -5
- data/lib/ducalis/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75bd9a05b686683a5a460a113fc81089795ddc36
|
4
|
+
data.tar.gz: 88fccc0c3fec65985a012b90c303ee6ae907b80e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8085d59b75d50d3db357845b7104e5cce09e3712b9fc76d0bbc1ceff63456335888d947395fda9089fc3421f87f243c537ac46fb617217775e5ed75dbc93fd9e
|
7
|
+
data.tar.gz: 5925c8c9286eb4b6fc758e818782e8467a9390c51897a56eccd7b6dac53145b0a11494f6b7901b11bdc524461ae182bc6fc5b5393638ec03f3f267f0ad2fd954
|
data/DOCUMENTATION.md
CHANGED
@@ -295,7 +295,7 @@ class TaskJournal
|
|
295
295
|
end
|
296
296
|
|
297
297
|
```
|
298
|
-
## Ducalis::
|
298
|
+
## Ducalis::OnlyDefs
|
299
299
|
|
300
300
|
Prefer object instances to class methods because class methods resist refactoring. Begin with an object instance, even if it doesn’t have state or multiple methods right away. If you come back to change it later, you will be more likely to refactor. If it never changes, the difference between the class method approach and the instance is negligible, and you certainly won’t be any worse off.
|
301
301
|
Related article: https://codeclimate.com/blog/why-ruby-class-methods-resist-refactoring/
|
@@ -344,6 +344,40 @@ class TaskJournal
|
|
344
344
|
end
|
345
345
|
end
|
346
346
|
|
347
|
+
```
|
348
|
+
|
349
|
+
![](https://placehold.it/10/f03c15/000000?text=+) raises error for class with ONLY class << self
|
350
|
+
```ruby
|
351
|
+
|
352
|
+
class TaskJournal
|
353
|
+
class << self
|
354
|
+
def call(task)
|
355
|
+
# ...
|
356
|
+
end
|
357
|
+
|
358
|
+
def find(args)
|
359
|
+
# ...
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
```
|
365
|
+
|
366
|
+
![](https://placehold.it/10/2cbe4e/000000?text=+) ignores instance methods mixed with ONLY class << self
|
367
|
+
```ruby
|
368
|
+
|
369
|
+
class TaskJournal
|
370
|
+
class << self
|
371
|
+
def call(task)
|
372
|
+
# ...
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
def find(args)
|
377
|
+
# ...
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
347
381
|
```
|
348
382
|
## Ducalis::OptionsArgument
|
349
383
|
|
data/Gemfile.lock
CHANGED
data/config/.ducalis.yml
CHANGED
data/lib/ducalis.rb
CHANGED
@@ -35,7 +35,7 @@ require 'ducalis/cops/black_list_suffix'
|
|
35
35
|
require 'ducalis/cops/callbacks_activerecord'
|
36
36
|
require 'ducalis/cops/case_mapping'
|
37
37
|
require 'ducalis/cops/controllers_except'
|
38
|
-
require 'ducalis/cops/
|
38
|
+
require 'ducalis/cops/only_defs'
|
39
39
|
require 'ducalis/cops/keyword_defaults'
|
40
40
|
require 'ducalis/cops/module_like_class'
|
41
41
|
require 'ducalis/cops/options_argument'
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'rubocop'
|
4
4
|
|
5
5
|
module Ducalis
|
6
|
-
class
|
6
|
+
class OnlyDefs < RuboCop::Cop::Cop
|
7
7
|
include RuboCop::Cop::DefNode
|
8
8
|
|
9
9
|
OFFENSE = <<-MESSAGE.gsub(/^ +\|\s/, '').strip
|
@@ -17,15 +17,22 @@ module Ducalis
|
|
17
17
|
def on_class(node)
|
18
18
|
_name, inheritance, body = *node
|
19
19
|
return if !inheritance.nil? || body.nil?
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
return unless instance_methods.empty? && class_methods.any?
|
20
|
+
return unless !instance_methods_definitions?(body) &&
|
21
|
+
class_methods_defintions?(body)
|
24
22
|
add_offense(node, :expression, OFFENSE)
|
25
23
|
end
|
26
24
|
|
27
25
|
private
|
28
26
|
|
27
|
+
def instance_methods_definitions?(body)
|
28
|
+
children(body).any?(&public_method_definition?)
|
29
|
+
end
|
30
|
+
|
31
|
+
def class_methods_defintions?(body)
|
32
|
+
children(body).any?(&class_method_definition?) ||
|
33
|
+
children(body).any?(&method(:self_class_defs?))
|
34
|
+
end
|
35
|
+
|
29
36
|
def public_method_definition?
|
30
37
|
lambda do |node|
|
31
38
|
node.type == :def && !non_public?(node) && !initialize?(node)
|
@@ -43,5 +50,6 @@ module Ducalis
|
|
43
50
|
end
|
44
51
|
|
45
52
|
def_node_search :initialize?, '(def :initialize ...)'
|
53
|
+
def_node_search :self_class_defs?, ' (sclass (self) (begin ...))'
|
46
54
|
end
|
47
55
|
end
|
data/lib/ducalis/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ducalis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ignat Zakrevsky
|
@@ -136,7 +136,7 @@ files:
|
|
136
136
|
- lib/ducalis/cops/controllers_except.rb
|
137
137
|
- lib/ducalis/cops/keyword_defaults.rb
|
138
138
|
- lib/ducalis/cops/module_like_class.rb
|
139
|
-
- lib/ducalis/cops/
|
139
|
+
- lib/ducalis/cops/only_defs.rb
|
140
140
|
- lib/ducalis/cops/options_argument.rb
|
141
141
|
- lib/ducalis/cops/params_passing.rb
|
142
142
|
- lib/ducalis/cops/possible_tap.rb
|