ducalis 0.1.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.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +12 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +6 -0
  7. data/DOCUMENTATION.md +556 -0
  8. data/Dockerfile +33 -0
  9. data/Gemfile +21 -0
  10. data/Gemfile.lock +112 -0
  11. data/LICENSE +21 -0
  12. data/README.md +15 -0
  13. data/Rakefile +17 -0
  14. data/bin/ducalis +38 -0
  15. data/bootstrap.sh +9 -0
  16. data/config.ru +18 -0
  17. data/config/.ducalis.yml +57 -0
  18. data/ducalis.gemspec +39 -0
  19. data/lib/ducalis.rb +47 -0
  20. data/lib/ducalis/adapters/base.rb +17 -0
  21. data/lib/ducalis/adapters/circle_ci.rb +21 -0
  22. data/lib/ducalis/adapters/custom.rb +21 -0
  23. data/lib/ducalis/adapters/pull_request.rb +26 -0
  24. data/lib/ducalis/cli.rb +35 -0
  25. data/lib/ducalis/commentators/console.rb +59 -0
  26. data/lib/ducalis/commentators/github.rb +50 -0
  27. data/lib/ducalis/cops/callbacks_activerecord.rb +47 -0
  28. data/lib/ducalis/cops/controllers_except.rb +38 -0
  29. data/lib/ducalis/cops/keyword_defaults.rb +23 -0
  30. data/lib/ducalis/cops/module_like_class.rb +68 -0
  31. data/lib/ducalis/cops/params_passing.rb +35 -0
  32. data/lib/ducalis/cops/private_instance_assign.rb +39 -0
  33. data/lib/ducalis/cops/protected_scope_cop.rb +38 -0
  34. data/lib/ducalis/cops/raise_withour_error_class.rb +20 -0
  35. data/lib/ducalis/cops/regex_cop.rb +52 -0
  36. data/lib/ducalis/cops/rest_only_cop.rb +33 -0
  37. data/lib/ducalis/cops/rubocop_disable.rb +19 -0
  38. data/lib/ducalis/cops/strings_in_activerecords.rb +39 -0
  39. data/lib/ducalis/cops/uncommented_gem.rb +33 -0
  40. data/lib/ducalis/cops/useless_only.rb +50 -0
  41. data/lib/ducalis/documentation.rb +101 -0
  42. data/lib/ducalis/passed_args.rb +22 -0
  43. data/lib/ducalis/patched_rubocop/diffs.rb +30 -0
  44. data/lib/ducalis/patched_rubocop/ducalis_config_loader.rb +14 -0
  45. data/lib/ducalis/patched_rubocop/git_files_access.rb +42 -0
  46. data/lib/ducalis/patched_rubocop/git_runner.rb +14 -0
  47. data/lib/ducalis/patched_rubocop/git_turget_finder.rb +11 -0
  48. data/lib/ducalis/patched_rubocop/rubo_cop.rb +32 -0
  49. data/lib/ducalis/runner.rb +48 -0
  50. data/lib/ducalis/utils.rb +27 -0
  51. data/lib/ducalis/version.rb +5 -0
  52. metadata +201 -0
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PatchedRubocop
4
+ module DucalisConfigLoader
5
+ def configuration_file_for(target_dir)
6
+ config = super
7
+ if config == RuboCop::ConfigLoader::DEFAULT_FILE
8
+ ::Ducalis::DEFAULT_FILE
9
+ else
10
+ config
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'git'
4
+ require 'singleton'
5
+
6
+ module PatchedRubocop
7
+ class GitFilesAccess
8
+ DELETED = 'deleted'
9
+
10
+ include PatchedRubocop::Diffs
11
+ include Singleton
12
+
13
+ attr_accessor :flag
14
+
15
+ def initialize
16
+ @dir = Dir.pwd
17
+ @git = Git.open(@dir)
18
+ end
19
+
20
+ def changes
21
+ @changes ||= MODES.fetch(@flag)
22
+ .call(@git)
23
+ .map { |diff| GitDiff.new(full_path(diff.path), diff) }
24
+ .reject { |diff| diff.diff.type == DELETED }
25
+ end
26
+
27
+ def changed?(path, line)
28
+ find(path).changed?(line)
29
+ end
30
+
31
+ private
32
+
33
+ def full_path(path)
34
+ [@dir, path].join('/')
35
+ end
36
+
37
+ def find(path)
38
+ return NilDiff.new(full_path(path), nil) if changes.empty?
39
+ changes.find { |x| x.full_path == path }
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PatchedRubocop
4
+ module GitRunner
5
+ def inspect_file(file)
6
+ offenses, updated = super
7
+ offenses = offenses.select do |offense|
8
+ GitFilesAccess.instance.changed?(file.path, offense.line)
9
+ end
10
+
11
+ [offenses, updated]
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PatchedRubocop
4
+ module GitTurgetFinder
5
+ def find_files(base_dir, flags)
6
+ replacement = GitFilesAccess.instance.changes
7
+ return replacement.map(&:full_path) unless replacement.empty?
8
+ super
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ class ConfigLoader
5
+ ::Ducalis::Utils.silence_warnings { DOTFILE = ::Ducalis::DOTFILE }
6
+ class << self
7
+ prepend PatchedRubocop::DucalisConfigLoader
8
+ end
9
+ end
10
+
11
+ class TargetFinder
12
+ prepend PatchedRubocop::GitTurgetFinder
13
+ end
14
+
15
+ class Runner
16
+ prepend PatchedRubocop::GitRunner
17
+ end
18
+ end
19
+
20
+ module PatchedRubocop
21
+ MODES = {
22
+ branch: ->(git) { git.diff('origin/master') },
23
+ index: ->(git) { git.diff('HEAD') },
24
+ all: ->(_git) { [] }
25
+ }.freeze
26
+
27
+ module_function
28
+
29
+ def configure!(flag)
30
+ GitFilesAccess.instance.flag = flag
31
+ end
32
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Policial
4
+ class ConfigLoader
5
+ def raw(filename)
6
+ File.read(filename)
7
+ end
8
+ end
9
+ end
10
+
11
+ module Ducalis
12
+ class Runner
13
+ def initialize(config)
14
+ @config = config
15
+ configure
16
+ end
17
+
18
+ def call
19
+ detective = Policial::Detective.new(Utils.octokit)
20
+ detective.brief(commit_info)
21
+ detective.investigate(ruby: { config_file: Ducalis::DEFAULT_FILE })
22
+ commentator.new(config).call(detective.violations)
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :config
28
+
29
+ def commit_info
30
+ { repo: config.repo, number: config.id, head_sha: config.sha }
31
+ end
32
+
33
+ def configure
34
+ Octokit.auto_paginate = true
35
+ # Style guides were changed to linters in `policial` upstream
36
+ if Policial.respond_to?(:linters)
37
+ Policial.linters = [Policial::Linters::Ruby]
38
+ else
39
+ Policial.style_guides = [Policial::StyleGuides::Ruby]
40
+ end
41
+ end
42
+
43
+ def commentator
44
+ @commentator ||=
45
+ config.dry? ? Commentators::Console : Commentators::Github
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ducalis
4
+ module Utils
5
+ module_function
6
+
7
+ def octokit
8
+ @octokit ||= Octokit::Client.new(access_token: ENV.fetch('GITHUB_TOKEN'))
9
+ end
10
+
11
+ def similarity(string1, string2)
12
+ longer = [string1.size, string2.size].max
13
+ same = string1.each_char
14
+ .zip(string2.each_char)
15
+ .select { |char1, char2| char1 == char2 }
16
+ .size
17
+ 1 - (longer - same) / string1.size.to_f
18
+ end
19
+
20
+ def silence_warnings
21
+ original_verbose = $VERBOSE
22
+ $VERBOSE = nil
23
+ yield
24
+ $VERBOSE = original_verbose
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ducalis
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ducalis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ignat Zakrevsky
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: policial
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.50.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.50.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: regexp-examples
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.3.2
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.3'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.3.2
61
+ - !ruby/object:Gem::Dependency
62
+ name: thor
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.20.0
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.20.0
75
+ - !ruby/object:Gem::Dependency
76
+ name: bundler
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 1.16.a
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 1.16.a
89
+ - !ruby/object:Gem::Dependency
90
+ name: rake
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '12.1'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '12.1'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rspec
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3.0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '3.0'
117
+ description: " Ducalis is RuboCop based static code analyzer for enterprise Rails
118
+ \ applications.\n"
119
+ email:
120
+ - iezakrevsky@gmail.com
121
+ executables:
122
+ - ducalis
123
+ extensions: []
124
+ extra_rdoc_files: []
125
+ files:
126
+ - ".gitignore"
127
+ - ".rspec"
128
+ - ".rubocop.yml"
129
+ - ".ruby-version"
130
+ - ".travis.yml"
131
+ - DOCUMENTATION.md
132
+ - Dockerfile
133
+ - Gemfile
134
+ - Gemfile.lock
135
+ - LICENSE
136
+ - README.md
137
+ - Rakefile
138
+ - bin/ducalis
139
+ - bootstrap.sh
140
+ - config.ru
141
+ - config/.ducalis.yml
142
+ - ducalis.gemspec
143
+ - lib/ducalis.rb
144
+ - lib/ducalis/adapters/base.rb
145
+ - lib/ducalis/adapters/circle_ci.rb
146
+ - lib/ducalis/adapters/custom.rb
147
+ - lib/ducalis/adapters/pull_request.rb
148
+ - lib/ducalis/cli.rb
149
+ - lib/ducalis/commentators/console.rb
150
+ - lib/ducalis/commentators/github.rb
151
+ - lib/ducalis/cops/callbacks_activerecord.rb
152
+ - lib/ducalis/cops/controllers_except.rb
153
+ - lib/ducalis/cops/keyword_defaults.rb
154
+ - lib/ducalis/cops/module_like_class.rb
155
+ - lib/ducalis/cops/params_passing.rb
156
+ - lib/ducalis/cops/private_instance_assign.rb
157
+ - lib/ducalis/cops/protected_scope_cop.rb
158
+ - lib/ducalis/cops/raise_withour_error_class.rb
159
+ - lib/ducalis/cops/regex_cop.rb
160
+ - lib/ducalis/cops/rest_only_cop.rb
161
+ - lib/ducalis/cops/rubocop_disable.rb
162
+ - lib/ducalis/cops/strings_in_activerecords.rb
163
+ - lib/ducalis/cops/uncommented_gem.rb
164
+ - lib/ducalis/cops/useless_only.rb
165
+ - lib/ducalis/documentation.rb
166
+ - lib/ducalis/passed_args.rb
167
+ - lib/ducalis/patched_rubocop/diffs.rb
168
+ - lib/ducalis/patched_rubocop/ducalis_config_loader.rb
169
+ - lib/ducalis/patched_rubocop/git_files_access.rb
170
+ - lib/ducalis/patched_rubocop/git_runner.rb
171
+ - lib/ducalis/patched_rubocop/git_turget_finder.rb
172
+ - lib/ducalis/patched_rubocop/rubo_cop.rb
173
+ - lib/ducalis/runner.rb
174
+ - lib/ducalis/utils.rb
175
+ - lib/ducalis/version.rb
176
+ homepage: https://github.com/ignat-z/ducalis
177
+ licenses:
178
+ - MIT
179
+ metadata:
180
+ source_code_uri: https://github.com/ignat-z/ducalis
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.6.13
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: RuboCop based static code analyzer
201
+ test_files: []