ducalis 0.5.6 → 0.5.7

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: 8a11daa74e66a48aa5dcf55449524a52ce95ccfe
4
- data.tar.gz: be32ea0b59dcbaf77839929724d98ce64562407e
3
+ metadata.gz: 2287c52a483de43813b38fd3dbbb76dbe3780655
4
+ data.tar.gz: 70aabac07f3332f1f93066e8b62a0735e10d312c
5
5
  SHA512:
6
- metadata.gz: d1d720cf2eb513ce4073c5ed10ab6c96314efa49e3d416a1ae55bdba86530b8362da4bd49717322a161b04bbad5d134b38fe62885b498873cc4aec8e1af9d83c
7
- data.tar.gz: f81669117b7f2ddb1c29d536cbe70823c8f435a25e93f517c712ed6f387a9a6aec4f42db6e4460ed266151350e5873de06b3fb03c0a80e1ff321222c10ae44f1
6
+ metadata.gz: c83807a339d46e105dd31d431676215d3e5096ec1a4e24001f2d2f04b9b986a436a4d8f4cce5190d048472d0a52ff0dd98230842be0ec044eca77a37e4a479cd
7
+ data.tar.gz: 7141de63c1e561a7a509d37b461a9bbba0f77da84c1f7e45cb6b181fd6f8162789e23de5edbd473ffeee8a6a3ddd014877ae60d62e8b92762572b02272162685
data/DOCUMENTATION.md CHANGED
@@ -1,3 +1,35 @@
1
+ ## Ducalis::BlackListSuffix
2
+
3
+ Please, avoid using of class suffixes like `Meneger`, `Client`
4
+ and so on. If it has no parts, change the name of the class to what
5
+ each object is managing. It's ok to use Manager as subclass of Person,
6
+ which is there to refine a type of personal that has management
7
+ behavior to it.
8
+ Related [article](<http://www.carlopescio.com/2011/04/your-coding-conventions-are-hurting-you.html>)
9
+
10
+ ![](https://placehold.it/10/f03c15/000000?text=+) raises on classes with suffixes from black list
11
+ ```ruby
12
+
13
+ class ListSorter
14
+ end
15
+
16
+ ```
17
+
18
+ ![](https://placehold.it/10/2cbe4e/000000?text=+) ignores classes with okish suffixes
19
+ ```ruby
20
+
21
+ class SortedList
22
+ end
23
+
24
+ ```
25
+
26
+ ![](https://placehold.it/10/2cbe4e/000000?text=+) ignores classes with full match
27
+ ```ruby
28
+
29
+ class Manager
30
+ end
31
+
32
+ ```
1
33
  ## Ducalis::CallbacksActiverecord
2
34
 
3
35
  Please, avoid using of callbacks for models. It's better to
@@ -449,7 +481,7 @@ end
449
481
  ![](https://placehold.it/10/2cbe4e/000000?text=+) ignores methods which return some statement
450
482
  ```ruby
451
483
 
452
- def stop_terminated_employee
484
+ def stop_terminated_employee
453
485
  if current_user && current_user.terminated?
454
486
  sign_out current_user
455
487
  redirect_to new_user_session_path
@@ -459,13 +491,45 @@ end
459
491
 
460
492
  ```
461
493
 
462
- ![](https://placehold.it/10/2cbe4e/000000?text=+) ignores methods which simply returns instance var without changes
494
+ ![](https://placehold.it/10/2cbe4e/000000?text=+) [bugfix] calling methods on possible tap variable
495
+ ```ruby
496
+
497
+ def create_message_struct(message)
498
+ objects = message.map { |object| process(object) }
499
+ Auditor::Message.new(message.process, objects)
500
+ end
501
+
502
+ ```
503
+
504
+ ![](https://placehold.it/10/2cbe4e/000000?text=+) [bugfix] methods which simply returns instance var without changes
463
505
  ```ruby
464
506
 
465
507
  def employee
466
508
  @employee
467
509
  end
468
510
 
511
+ ```
512
+
513
+ ![](https://placehold.it/10/2cbe4e/000000?text=+) [bugfix] methods which ends with if condition
514
+ ```ruby
515
+
516
+ def complete=(value, complete_at)
517
+ value = value.to_b
518
+ self.complete_at = complete_at if complete && value
519
+ self.complete_at = nil unless value
520
+ end
521
+
522
+ ```
523
+
524
+ ![](https://placehold.it/10/2cbe4e/000000?text=+) [bugfix] methods with args without children nodes
525
+ ```ruby
526
+
527
+ def filtered_admins(reducers)
528
+ reducers
529
+ .map { |reducer| @base_scope.public_send(reducer) }
530
+ .order("admin_users.created_at DESC")
531
+ end
532
+
469
533
  ```
470
534
  ## Ducalis::PreferableMethods
471
535
 
@@ -500,9 +564,9 @@ tempfile.delete
500
564
  ```
501
565
  ## Ducalis::PrivateInstanceAssign
502
566
 
503
- Don't use filters for setting instance variables, use them only for
504
- changing application flow, such as redirecting if a user is not
505
- authenticated. Controller instance variables are forming contract
567
+ Don't use controller's filter methods for setting instance variables, use
568
+ them only for changing application flow, such as redirecting if a user
569
+ is not authenticated. Controller instance variables are forming contract
506
570
  between controller and view. Keeping instance variables defined in one
507
571
  place makes it easier to: reason, refactor and remove old views, test
508
572
  controllers and views, extract actions to new controllers, etc.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ducalis (0.5.6)
4
+ ducalis (0.5.7)
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
@@ -5,6 +5,20 @@ AllCops:
5
5
  - 'node_modules/**/*'
6
6
  - 'vendor/bundle/**/*'
7
7
 
8
+ Ducalis/BlackListSuffix:
9
+ Enabled: true
10
+ BlackList:
11
+ - Sorter
12
+ - Manager
13
+ - Client
14
+ - Object
15
+ - Handler
16
+ - Processor
17
+ - Organizer
18
+ - Analyzer
19
+ - Renderer
20
+ - Loader
21
+
8
22
  Ducalis/PreferableMethods:
9
23
  Enabled: true
10
24
 
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ module Ducalis
6
+ class BlackListSuffix < RuboCop::Cop::Cop
7
+ OFFENSE = <<-MESSAGE.gsub(/^ +\|/, '').strip
8
+ | Please, avoid using of class suffixes like `Meneger`, `Client`
9
+ | and so on. If it has no parts, change the name of the class to what
10
+ | each object is managing. It's ok to use Manager as subclass of Person,
11
+ | which is there to refine a type of personal that has management
12
+ | behavior to it.
13
+ | Related [article](<http://www.carlopescio.com/2011/04/your-coding-conventions-are-hurting-you.html>)
14
+ MESSAGE
15
+
16
+ def on_class(node)
17
+ classdef_node, _superclass, _body = *node
18
+ return unless with_blacklisted_suffix?(classdef_node.source)
19
+ add_offense(node, :expression, OFFENSE)
20
+ end
21
+
22
+ private
23
+
24
+ def with_blacklisted_suffix?(name)
25
+ return if cop_config['BlackList'].to_a.empty?
26
+ cop_config['BlackList'].any? { |suffix| name =~ /#{suffix}\Z/ }
27
+ end
28
+ end
29
+ end
@@ -47,14 +47,20 @@ module Ducalis
47
47
  end
48
48
 
49
49
  def return_var_call?(body)
50
- return unless body.children.last.respond_to?(:children)
51
- subnodes(body.children.last.to_a.first).find do |node|
50
+ return unless last_child(body).respond_to?(:children)
51
+ return if last_child(body).type == :if
52
+ subnodes(last_child(body).to_a.first).find do |node|
52
53
  ASSIGNS.include?(node.type)
53
54
  end
54
55
  end
55
56
 
56
57
  def subnodes(node)
58
+ return [] unless node.respond_to?(:children)
57
59
  ([node] + node.children).select { |child| child.respond_to?(:type) }
58
60
  end
61
+
62
+ def last_child(body)
63
+ body.children.last
64
+ end
59
65
  end
60
66
  end
@@ -6,9 +6,9 @@ module Ducalis
6
6
  class PrivateInstanceAssign < RuboCop::Cop::Cop
7
7
  include RuboCop::Cop::DefNode
8
8
  OFFENSE = <<-MESSAGE.gsub(/^ +\|/, '').strip
9
- | Don't use filters for setting instance variables, use them only for
10
- | changing application flow, such as redirecting if a user is not
11
- | authenticated. Controller instance variables are forming contract
9
+ | Don't use controller's filter methods for setting instance variables, use
10
+ | them only for changing application flow, such as redirecting if a user
11
+ | is not authenticated. Controller instance variables are forming contract
12
12
  | between controller and view. Keeping instance variables defined in one
13
13
  | place makes it easier to: reason, refactor and remove old views, test
14
14
  | controllers and views, extract actions to new controllers, etc.
@@ -62,7 +62,7 @@ class Documentation
62
62
  SIGNAL_WORD = 'raises'
63
63
 
64
64
  def call
65
- Dir['./lib/ducalis/cops/*.rb'].map do |f|
65
+ Dir['./lib/ducalis/cops/*.rb'].sort.map do |f|
66
66
  present_cop(klass_const_for(f), spec_cases_for(f))
67
67
  end.flatten.join("\n")
68
68
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ducalis
4
- VERSION = '0.5.6'
4
+ VERSION = '0.5.7'
5
5
  end
data/lib/ducalis.rb CHANGED
@@ -31,6 +31,7 @@ require 'ducalis/patched_rubocop/git_runner'
31
31
  require 'ducalis/patched_rubocop/git_turget_finder'
32
32
  require 'ducalis/patched_rubocop/rubo_cop'
33
33
 
34
+ require 'ducalis/cops/black_list_suffix'
34
35
  require 'ducalis/cops/callbacks_activerecord'
35
36
  require 'ducalis/cops/case_mapping'
36
37
  require 'ducalis/cops/controllers_except'
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.6
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignat Zakrevsky
@@ -130,6 +130,7 @@ files:
130
130
  - lib/ducalis/cli.rb
131
131
  - lib/ducalis/commentators/console.rb
132
132
  - lib/ducalis/commentators/github.rb
133
+ - lib/ducalis/cops/black_list_suffix.rb
133
134
  - lib/ducalis/cops/callbacks_activerecord.rb
134
135
  - lib/ducalis/cops/case_mapping.rb
135
136
  - lib/ducalis/cops/controllers_except.rb