ducalis 0.5.6 → 0.5.7
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 +4 -4
- data/DOCUMENTATION.md +69 -5
- data/Gemfile.lock +1 -1
- data/config/.ducalis.yml +14 -0
- data/lib/ducalis/cops/black_list_suffix.rb +29 -0
- data/lib/ducalis/cops/possible_tap.rb +8 -2
- data/lib/ducalis/cops/private_instance_assign.rb +3 -3
- data/lib/ducalis/documentation.rb +1 -1
- data/lib/ducalis/version.rb +1 -1
- data/lib/ducalis.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2287c52a483de43813b38fd3dbbb76dbe3780655
|
4
|
+
data.tar.gz: 70aabac07f3332f1f93066e8b62a0735e10d312c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+
 raises on classes with suffixes from black list
|
11
|
+
```ruby
|
12
|
+
|
13
|
+
class ListSorter
|
14
|
+
end
|
15
|
+
|
16
|
+
```
|
17
|
+
|
18
|
+
 ignores classes with okish suffixes
|
19
|
+
```ruby
|
20
|
+
|
21
|
+
class SortedList
|
22
|
+
end
|
23
|
+
|
24
|
+
```
|
25
|
+
|
26
|
+
 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
|
 ignores methods which return some statement
|
450
482
|
```ruby
|
451
483
|
|
452
|
-
|
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
|
-

|
494
|
+
 [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
|
+
 [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
|
+
 [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
|
+
 [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
|
504
|
-
changing application flow, such as redirecting if a user
|
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
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.
|
51
|
-
|
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
|
10
|
-
| changing application flow, such as redirecting if a user
|
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.
|
data/lib/ducalis/version.rb
CHANGED
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.
|
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
|