ducalis 0.10.0 → 0.11.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: 32df7c2136c9843336bff23949966d6a557932631bc0d143a0b76111981aef71
4
- data.tar.gz: 0b05601c199203849589a13c5469dccc3a6017dfbe07661c96d5f073846507d7
3
+ metadata.gz: 452d05fc9f37618eee52ef036528d6c931a24a012c41725c1cf2d31e85218815
4
+ data.tar.gz: dcb1cce57dbed25a8bb811cac2e18ff449554e60156345dd8bd0a64e0d400316
5
5
  SHA512:
6
- metadata.gz: 7b2362aacc03c71f192f5fe671c8dd6270311a39f8be31b9fa712b9e67be36a114590ced0c21cd82a0d846d47a6d150592c63d7bf46ee691cd8c821220ace4e8
7
- data.tar.gz: c49866725411c9e47a40967b171338651a0a8fc9ff8d1288c8d688be178e8ec80598971371fa1281dac5efbc94cfbbafc50287c2e20741714e711f39f8911530
6
+ metadata.gz: 522c28511c7ee1c9c8fd951b1cbfe097c8afb8d2f472b281d602ec9de6e5090d225790757ebea7a8a0e747930ca27fb06a32fd56522c86a47ee5906180cc28d0
7
+ data.tar.gz: 0db1d6f104b52f5dfb23f1953d1415e1578736d8743f358839ea310a7ac4a6218301a5333fc59b21ed328742a34a5ef2996951450e1849bb058cf040191fd2f3
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.1
2
+ TargetRubyVersion: 2.2
3
3
  UseCache: false
4
4
  Exclude:
5
5
  - 'client/vendor/bundle/**/*'
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.1
4
3
  - 2.2.9
5
4
  - 2.3.6
6
5
  - 2.4.3
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ducalis (0.10.0)
4
+ ducalis (0.11.0)
5
5
  git (~> 1.3, >= 1.3.0)
6
- octokit (>= 4.1.0)
6
+ octokit (>= 4.7.0)
7
7
  regexp-examples (~> 1.3, >= 1.3.2)
8
8
  rubocop (>= 0.45.0)
9
9
 
@@ -15,24 +15,25 @@ GEM
15
15
  ast (2.4.0)
16
16
  coderay (1.1.2)
17
17
  diff-lcs (1.3)
18
- faraday (0.15.1)
18
+ faraday (0.15.2)
19
19
  multipart-post (>= 1.2, < 3)
20
- git (1.3.0)
20
+ git (1.4.0)
21
+ jaro_winkler (1.5.1)
21
22
  method_source (0.9.0)
22
23
  multipart-post (2.0.0)
23
- octokit (4.6.0)
24
+ octokit (4.9.0)
24
25
  sawyer (~> 0.8.0, >= 0.5.3)
25
26
  parallel (1.12.1)
26
- parser (2.5.0.0)
27
+ parser (2.5.1.2)
27
28
  ast (~> 2.4.0)
28
- powerpack (0.1.1)
29
+ powerpack (0.1.2)
29
30
  pry (0.11.3)
30
31
  coderay (~> 1.1.0)
31
32
  method_source (~> 0.9.0)
32
33
  public_suffix (3.0.2)
33
34
  rainbow (3.0.0)
34
35
  rake (12.3.0)
35
- regexp-examples (1.4.2)
36
+ regexp-examples (1.4.3)
36
37
  rspec (3.7.0)
37
38
  rspec-core (~> 3.7.0)
38
39
  rspec-expectations (~> 3.7.0)
@@ -46,19 +47,20 @@ GEM
46
47
  diff-lcs (>= 1.2.0, < 2.0)
47
48
  rspec-support (~> 3.7.0)
48
49
  rspec-support (3.7.1)
49
- rubocop (0.52.1)
50
+ rubocop (0.58.2)
51
+ jaro_winkler (~> 1.5.1)
50
52
  parallel (~> 1.10)
51
- parser (>= 2.4.0.2, < 3.0)
53
+ parser (>= 2.5, != 2.5.1.1)
52
54
  powerpack (~> 0.1)
53
55
  rainbow (>= 2.2.2, < 4.0)
54
56
  ruby-progressbar (~> 1.7)
55
57
  unicode-display_width (~> 1.0, >= 1.0.1)
56
- ruby-progressbar (1.9.0)
58
+ ruby-progressbar (1.10.0)
57
59
  sawyer (0.8.1)
58
60
  addressable (>= 2.3.5, < 2.6)
59
61
  faraday (~> 0.8, < 1.0)
60
62
  single_cov (1.0.3)
61
- unicode-display_width (1.3.2)
63
+ unicode-display_width (1.4.0)
62
64
 
63
65
  PLATFORMS
64
66
  ruby
@@ -9,7 +9,7 @@ require 'benchmark'
9
9
  cli_arguments = Ducalis::CliArguments.new
10
10
 
11
11
  if cli_arguments.help_command?
12
- puts 'You can start Ducalis in the next modes:'
12
+ puts 'You can start Ducalis in the following modes:'
13
13
  puts ' --branch check files in RuboCop style against branch.'
14
14
  puts ' --index check files in RuboCop style against index.'
15
15
  puts ' --all [default] check all files in RuboCop style.'
@@ -9,16 +9,17 @@ AllCops:
9
9
  Ducalis/BlackListSuffix:
10
10
  Enabled: true
11
11
  BlackList:
12
- - Sorter
13
- - Manager
12
+ - Analyzer
14
13
  - Client
15
- - Object
16
14
  - Handler
17
- - Processor
15
+ - Loader
16
+ - Manager
17
+ - Object
18
18
  - Organizer
19
- - Analyzer
19
+ - Processor
20
20
  - Renderer
21
- - Loader
21
+ - Service
22
+ - Sorter
22
23
 
23
24
  Ducalis/EnforceNamespace:
24
25
  Enabled: true
@@ -27,9 +28,16 @@ Ducalis/EnforceNamespace:
27
28
  Ducalis/PreferableMethods:
28
29
  Enabled: true
29
30
 
31
+ Ducalis/Recursion:
32
+ Enabled: true
33
+
30
34
  Ducalis/CaseMapping:
31
35
  Enabled: true
32
36
 
37
+ Ducalis/FacadePattern:
38
+ Enabled: true
39
+ MaxInstanceVariables: 4
40
+
33
41
  Ducalis/CallbacksActiverecord:
34
42
  Enabled: true
35
43
 
@@ -1,7 +1,6 @@
1
-
2
1
  # frozen_string_literal: true
3
2
 
4
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
5
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
5
  require 'ducalis/version'
7
6
 
@@ -29,7 +28,7 @@ Gem::Specification.new do |spec|
29
28
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
30
29
 
31
30
  spec.add_dependency 'git', '~> 1.3', '>= 1.3.0'
32
- spec.add_dependency 'octokit', '>= 4.1.0'
31
+ spec.add_dependency 'octokit', '>= 4.7.0'
33
32
  spec.add_dependency 'regexp-examples', '~> 1.3', '>= 1.3.2'
34
33
  spec.add_dependency 'rubocop', '>= 0.45.0'
35
34
  end
@@ -39,6 +39,7 @@ require 'ducalis/cops/descriptive_block_names'
39
39
  require 'ducalis/cops/enforce_namespace'
40
40
  require 'ducalis/cops/evlis_overusing'
41
41
  require 'ducalis/cops/extensions/type_resolving'
42
+ require 'ducalis/cops/facade_pattern'
42
43
  require 'ducalis/cops/fetch_expression'
43
44
  require 'ducalis/cops/keyword_defaults'
44
45
  require 'ducalis/cops/module_like_class'
@@ -52,6 +53,7 @@ require 'ducalis/cops/private_instance_assign'
52
53
  require 'ducalis/cops/protected_scope_cop'
53
54
  require 'ducalis/cops/public_send'
54
55
  require 'ducalis/cops/raise_without_error_class'
56
+ require 'ducalis/cops/recursion'
55
57
  require 'ducalis/cops/regex_cop'
56
58
  require 'ducalis/cops/rest_only_cop'
57
59
  require 'ducalis/cops/rubocop_disable'
@@ -53,7 +53,7 @@ module Ducalis
53
53
  end
54
54
 
55
55
  def commented_offenses
56
- @_commented_offenses ||= Utils.octokit.pull_request_comments(@repo, @id)
56
+ @commented_offenses ||= Utils.octokit.pull_request_comments(@repo, @id)
57
57
  end
58
58
  end
59
59
  end
@@ -5,7 +5,7 @@ require 'rubocop'
5
5
  module Ducalis
6
6
  class DescriptiveBlockNames < RuboCop::Cop::Cop
7
7
  OFFENSE = <<-MESSAGE.gsub(/^ +\|\s/, '').strip
8
- | Please, use descriptive names as block arguments. There is no any sanse to save on letters.
8
+ | Please, use descriptive names as block arguments. There is no any sense to save on letters.
9
9
  MESSAGE
10
10
 
11
11
  def on_block(node)
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+ require 'ducalis/cops/extensions/type_resolving'
5
+
6
+ module Ducalis
7
+ class FacadePattern < RuboCop::Cop::Cop
8
+ include RuboCop::Cop::DefNode
9
+ prepend TypeResolving
10
+
11
+ OFFENSE = <<-MESSAGE.gsub(/^ +\|\s/, '').strip
12
+ | There are too many instance variables for one controller action. It's beetter to refactor it with Facade pattern to simplify the controller.
13
+ MESSAGE
14
+
15
+ DETAILS = <<-MESSAGE.gsub(/^ +\|\s/, '').strip
16
+ | Good article about [Facade](<https://medium.com/kkempin/facade-design-pattern-in-ruby-on-rails-710aa88326f>).
17
+ MESSAGE
18
+
19
+ def on_def(node)
20
+ return unless in_controller?
21
+ return if non_public?(node)
22
+ return if instance_variables_matches(node).count < max_instance_variables
23
+ add_offense(node, :expression, OFFENSE)
24
+ end
25
+
26
+ private
27
+
28
+ def max_instance_variables
29
+ cop_config.fetch('MaxInstanceVariables')
30
+ end
31
+
32
+ def_node_search :instance_variables_matches, '(ivasgn ...)'
33
+ end
34
+ end
@@ -69,7 +69,7 @@ module Ducalis
69
69
 
70
70
  def on_send(node)
71
71
  who, what, *args = *node
72
- return unless DESCRIPTION.keys.include?(what)
72
+ return unless DESCRIPTION.key?(what)
73
73
  alternative, reason, condition = DESCRIPTION.fetch(what)
74
74
  return unless condition.call(who, what, args)
75
75
  add_offense(node, :expression, format(OFFENSE, original: what,
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ module Ducalis
6
+ class Recursion < RuboCop::Cop::Cop
7
+ OFFENSE = <<-MESSAGE.gsub(/^ +\|\s/, '').strip
8
+ It seems like you are using recursion in your code. In common, it is not a bad idea, but try to keep your business logic layer free from refursion code.
9
+ MESSAGE
10
+
11
+ def on_def(node)
12
+ @method_name, _args, body = *node
13
+ return unless body
14
+ return unless send_call?(body) || send_self_call?(body)
15
+ add_offense(node, :expression, OFFENSE)
16
+ end
17
+
18
+ private
19
+
20
+ def call_itself?(call_name)
21
+ @method_name == call_name
22
+ end
23
+
24
+ def_node_search :send_call?, '(send nil? #call_itself? ...)'
25
+ def_node_search :send_self_call?, '(send (self) #call_itself? ...)'
26
+ end
27
+ end
@@ -79,8 +79,8 @@ class Documentation
79
79
  end
80
80
 
81
81
  def call
82
- cops.map do |f|
83
- present_cop(klass_const_for(f), spec_cases_for(f))
82
+ cops.map do |file|
83
+ present_cop(klass_const_for(file), spec_cases_for(file))
84
84
  end.flatten.join("\n")
85
85
  end
86
86
 
@@ -103,12 +103,12 @@ class Documentation
103
103
  end
104
104
  end
105
105
 
106
- def prepare(it)
107
- it.sub("#{RULE_WORD} ", '')
106
+ def prepare(it_description)
107
+ it_description.sub("#{RULE_WORD} ", '')
108
108
  end
109
109
 
110
- def mention(it)
111
- it.include?(SIGNAL_WORD) ? '# bad' : '# good'
110
+ def mention(it_description)
111
+ it_description.include?(SIGNAL_WORD) ? '# bad' : '# good'
112
112
  end
113
113
 
114
114
  def message(klass)
@@ -118,10 +118,10 @@ class Documentation
118
118
  ].join("\n")
119
119
  end
120
120
 
121
- def spec_cases_for(f)
121
+ def spec_cases_for(file)
122
122
  source_code = File.read(
123
- f.sub('/lib/', '/spec/')
124
- .sub(/.rb$/, '_spec.rb')
123
+ file.sub('/lib/', '/spec/')
124
+ .sub(/.rb$/, '_spec.rb')
125
125
  )
126
126
  SpecsProcessor.new.tap do |processor|
127
127
  processor.process(Parser::CurrentRuby.parse(source_code))
@@ -133,9 +133,9 @@ class Documentation
133
133
  desc.include?(RULE_WORD)
134
134
  end
135
135
 
136
- def klass_const_for(f)
137
- require f
138
- Ducalis.const_get(camelize(File.basename(f).sub(/.rb$/, '')))
136
+ def klass_const_for(file)
137
+ require file
138
+ Ducalis.const_get(camelize(File.basename(file).sub(/.rb$/, '')))
139
139
  end
140
140
 
141
141
  def camelize(snake_case_word)
@@ -28,18 +28,18 @@ class GitAccess
28
28
  end
29
29
 
30
30
  def for(path)
31
- find(path)
31
+ find(Pathname.new(path).relative_path_from(Pathname.new(Dir.pwd)).to_s)
32
32
  end
33
33
 
34
34
  private
35
35
 
36
36
  def under_git?
37
- @_under_git ||= Dir.exist?(File.join(Dir.pwd, GIT_DIR))
37
+ @under_git ||= Dir.exist?(File.join(Dir.pwd, GIT_DIR))
38
38
  end
39
39
 
40
40
  def changes
41
41
  return default_value if flag.nil? || !under_git?
42
- @_changes ||= patch_diffs
42
+ @changes ||= patch_diffs
43
43
  end
44
44
 
45
45
  def patch_diffs
@@ -9,7 +9,9 @@ module Ducalis
9
9
  def octokit
10
10
  @octokit ||= begin
11
11
  token = ENV.fetch('GITHUB_TOKEN') { raise MissingToken }
12
- Octokit::Client.new(access_token: token)
12
+ Octokit::Client.new(access_token: token).tap do |client|
13
+ client.auto_paginate = true
14
+ end
13
15
  end
14
16
  end
15
17
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ducalis
4
- VERSION = '0.10.0'.freeze
4
+ VERSION = '0.11.0'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ducalis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignat Zakrevsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-13 00:00:00.000000000 Z
11
+ date: 2018-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 4.1.0
39
+ version: 4.7.0
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 4.1.0
46
+ version: 4.7.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: regexp-examples
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -117,6 +117,7 @@ files:
117
117
  - lib/ducalis/cops/enforce_namespace.rb
118
118
  - lib/ducalis/cops/evlis_overusing.rb
119
119
  - lib/ducalis/cops/extensions/type_resolving.rb
120
+ - lib/ducalis/cops/facade_pattern.rb
120
121
  - lib/ducalis/cops/fetch_expression.rb
121
122
  - lib/ducalis/cops/keyword_defaults.rb
122
123
  - lib/ducalis/cops/module_like_class.rb
@@ -130,6 +131,7 @@ files:
130
131
  - lib/ducalis/cops/protected_scope_cop.rb
131
132
  - lib/ducalis/cops/public_send.rb
132
133
  - lib/ducalis/cops/raise_without_error_class.rb
134
+ - lib/ducalis/cops/recursion.rb
133
135
  - lib/ducalis/cops/regex_cop.rb
134
136
  - lib/ducalis/cops/rest_only_cop.rb
135
137
  - lib/ducalis/cops/rubocop_disable.rb