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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc58534f3d61b3f00faf32d15c18fd4ade02b01d
4
- data.tar.gz: e2e5523eab7bd5dfe942f0e09722e718148ff6c4
3
+ metadata.gz: 75bd9a05b686683a5a460a113fc81089795ddc36
4
+ data.tar.gz: 88fccc0c3fec65985a012b90c303ee6ae907b80e
5
5
  SHA512:
6
- metadata.gz: d84c6cbef793f301ce284c6325f992ea20672f6f01938f9a0feeef6cc76b8b564992aa552d1433a6960e893c08d3aada0682ec6a1eb3f28a8c0d942797f4c6e5
7
- data.tar.gz: cbf69b4a43714b164e21ea3f19b08634504c563ca7f008b030fa625bed221bea0efba9f14bb917e96af25d4c1e180c53634bd9fb0f01f0fd73c443bd26bfdffb
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::OnlyDefsCope
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ducalis (0.5.12)
4
+ ducalis (0.5.13)
5
5
  git (~> 1.3, >= 1.3.0)
6
6
  policial (= 0.0.4)
7
7
  regexp-examples (~> 1.3, >= 1.3.2)
data/config/.ducalis.yml CHANGED
@@ -51,7 +51,7 @@ Ducalis/TooLongWorkers:
51
51
  Enabled: true
52
52
  Max: 25
53
53
 
54
- Ducalis/OnlyDefsCope:
54
+ Ducalis/OnlyDefs:
55
55
  Enabled: true
56
56
 
57
57
  Ducalis/UselessOnly:
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/only_defs_cope'
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 OnlyDefsCope < RuboCop::Cop::Cop
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
- instance_methods = children(body).select(&public_method_definition?)
21
- class_methods = children(body).select(&class_method_definition?)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ducalis
4
- VERSION = '0.5.12'
4
+ VERSION = '0.5.13'
5
5
  end
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.12
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/only_defs_cope.rb
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