ducalis 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,33 @@
1
+ FROM alpine:3.5
2
+
3
+ ARG token
4
+ EXPOSE 8090
5
+ ENV APP_ROOT /ducalis
6
+ ENV GITHUB_TOKEN=$token
7
+
8
+ RUN apk add --no-cache bc build-base \
9
+ ca-certificates \
10
+ git \
11
+ ruby \
12
+ ruby-dev \
13
+ ruby-irb \
14
+ ruby-rdoc \
15
+ ruby-io-console \
16
+ ruby-json \
17
+ ruby-rake \
18
+ sudo \
19
+ openssh \
20
+ nodejs
21
+ RUN gem install bundler
22
+ RUN bundle config silence_root_warning 1
23
+ RUN bundle config git.allow_insecure true
24
+
25
+ RUN mkdir -p "$APP_ROOT"
26
+ WORKDIR $APP_ROOT
27
+
28
+ COPY Gemfile $APP_ROOT
29
+ COPY Gemfile.lock $APP_ROOT
30
+ RUN bundle install
31
+
32
+ COPY . $APP_ROOT
33
+ CMD bundle exec puma -p 8090 -e production
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
+
6
+ gemspec
7
+
8
+ gem 'git'
9
+ gem 'policial', "0.0.4"
10
+ gem 'regexp-examples'
11
+ gem 'thor'
12
+
13
+ group :test, :development do
14
+ gem 'pry'
15
+ gem 'rspec'
16
+ end
17
+
18
+ group :production do
19
+ gem 'puma'
20
+ gem 'sinatra'
21
+ end
@@ -0,0 +1,112 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ducalis (0.1.0)
5
+ policial (= 0.0.4)
6
+ regexp-examples (~> 1.3, >= 1.3.2)
7
+ rubocop (~> 0.50.0)
8
+ thor (~> 0.20.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.5.2)
14
+ public_suffix (>= 2.0.2, < 4.0)
15
+ ast (2.3.0)
16
+ coderay (1.1.2)
17
+ coffee-script (2.4.1)
18
+ coffee-script-source
19
+ execjs
20
+ coffee-script-source (1.12.2)
21
+ coffeelint (1.16.0)
22
+ coffee-script
23
+ execjs
24
+ json
25
+ diff-lcs (1.3)
26
+ eslintrb (2.1.0)
27
+ execjs
28
+ multi_json (>= 1.3)
29
+ rake
30
+ execjs (2.7.0)
31
+ faraday (0.13.1)
32
+ multipart-post (>= 1.2, < 3)
33
+ git (1.3.0)
34
+ json (2.1.0)
35
+ method_source (0.9.0)
36
+ multi_json (1.12.2)
37
+ multipart-post (2.0.0)
38
+ mustermann (1.0.1)
39
+ octokit (4.7.0)
40
+ sawyer (~> 0.8.0, >= 0.5.3)
41
+ parallel (1.12.0)
42
+ parser (2.4.0.0)
43
+ ast (~> 2.2)
44
+ policial (0.0.4)
45
+ coffeelint (~> 1.14)
46
+ eslintrb (~> 2.0)
47
+ octokit (~> 4.3)
48
+ rubocop (~> 0.39)
49
+ powerpack (0.1.1)
50
+ pry (0.11.1)
51
+ coderay (~> 1.1.0)
52
+ method_source (~> 0.9.0)
53
+ public_suffix (3.0.0)
54
+ puma (3.10.0)
55
+ rack (2.0.3)
56
+ rack-protection (2.0.0)
57
+ rack
58
+ rainbow (2.2.2)
59
+ rake
60
+ rake (12.1.0)
61
+ regexp-examples (1.3.2)
62
+ rspec (3.6.0)
63
+ rspec-core (~> 3.6.0)
64
+ rspec-expectations (~> 3.6.0)
65
+ rspec-mocks (~> 3.6.0)
66
+ rspec-core (3.6.0)
67
+ rspec-support (~> 3.6.0)
68
+ rspec-expectations (3.6.0)
69
+ diff-lcs (>= 1.2.0, < 2.0)
70
+ rspec-support (~> 3.6.0)
71
+ rspec-mocks (3.6.0)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.6.0)
74
+ rspec-support (3.6.0)
75
+ rubocop (0.50.0)
76
+ parallel (~> 1.10)
77
+ parser (>= 2.3.3.1, < 3.0)
78
+ powerpack (~> 0.1)
79
+ rainbow (>= 2.2.2, < 3.0)
80
+ ruby-progressbar (~> 1.7)
81
+ unicode-display_width (~> 1.0, >= 1.0.1)
82
+ ruby-progressbar (1.9.0)
83
+ sawyer (0.8.1)
84
+ addressable (>= 2.3.5, < 2.6)
85
+ faraday (~> 0.8, < 1.0)
86
+ sinatra (2.0.0)
87
+ mustermann (~> 1.0)
88
+ rack (~> 2.0)
89
+ rack-protection (= 2.0.0)
90
+ tilt (~> 2.0)
91
+ thor (0.20.0)
92
+ tilt (2.0.8)
93
+ unicode-display_width (1.3.0)
94
+
95
+ PLATFORMS
96
+ ruby
97
+
98
+ DEPENDENCIES
99
+ bundler (~> 1.16.a)
100
+ ducalis!
101
+ git
102
+ policial (= 0.0.4)
103
+ pry
104
+ puma
105
+ rake (~> 12.1)
106
+ regexp-examples
107
+ rspec
108
+ sinatra
109
+ thor
110
+
111
+ BUNDLED WITH
112
+ 1.16.0.pre.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Ignat Zakrevsky
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,15 @@
1
+ # Ducalis
2
+
3
+ __Ducalis__ is RuboCop based static code analyzer for enterprise Rails applications.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ducalis'
11
+ ```
12
+
13
+ ## License
14
+
15
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ RuboCop::RakeTask.new do |task|
8
+ task.options = %w[--auto-correct]
9
+ end
10
+
11
+ task :documentation do
12
+ require './lib/ducalis/documentation'
13
+ File.write('DOCUMENTATION.md', Documentation.new.call)
14
+ end
15
+
16
+ RSpec::Core::RakeTask.new(:spec)
17
+ task default: %i[rubocop spec]
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
5
+
6
+ require 'ducalis'
7
+ require 'benchmark'
8
+
9
+ if Ducalis::PassedArgs.help_command?
10
+ puts 'You can start Ducalis in the next modes:'
11
+ puts " --ci check files from remote PR. \
12
+ Env `GITHUB_TOKEN` should be available to receive PRs files."
13
+ puts ' --branch check files in RuboCop style against branch.'
14
+ puts ' --index check files in RuboCop style against index.'
15
+ puts ' --all [default] check all files in RuboCop style.'
16
+ puts ''
17
+
18
+ Ducalis::CLI.start(ARGV)
19
+ RuboCop::CLI.new.run
20
+ exit 0
21
+ end
22
+
23
+ if Ducalis::PassedArgs.ci_mode?
24
+ Ducalis::CLI.start(ARGV - %w[--ci])
25
+ else
26
+ Ducalis::PassedArgs.process_args!
27
+
28
+ result = 0
29
+ cli = RuboCop::CLI.new
30
+ time = Benchmark.realtime do
31
+ result = cli.run
32
+ end
33
+
34
+ puts "Finished in #{time} seconds" if cli.options[:debug]
35
+ puts "\033[42mBuild still green. Nothing to worry about\033[0m" if result == 1
36
+ end
37
+
38
+ exit 0
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+
5
+ cd ~/
6
+ git clone git@github.com:ignat-zakrevsky/ducalis.git
7
+ cd ducalis
8
+ bundle install
9
+ bundle exec ruby lib/cli.rb --adapter circle
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/lib")
4
+ require 'ducalis'
5
+
6
+ require 'sinatra/base'
7
+ require 'sinatra'
8
+ require 'json'
9
+
10
+ post '/webhook' do
11
+ options = JSON.parse(request.body.read)
12
+ Thread.new do
13
+ Runner.new(Adapters::PullRequest.new(options)).call
14
+ end.abort_on_exception = true
15
+ code 200
16
+ end
17
+
18
+ run Sinatra::Application
@@ -0,0 +1,57 @@
1
+ AllCops:
2
+ DisabledByDefault: true
3
+ TargetRubyVersion: 2.4
4
+ Exclude:
5
+ - 'node_modules/**/*'
6
+ - 'vendor/bundle/**/*'
7
+
8
+ Ducalis/CallbacksActiverecord:
9
+ Enabled: true
10
+
11
+ Ducalis/ProtectedScopeCop:
12
+ Enabled: true
13
+
14
+ Ducalis/RegexCop:
15
+ Enabled: true
16
+ Exclude:
17
+ - 'spec/**/*.rb'
18
+
19
+ Ducalis/StringsInActiverecords:
20
+ Enabled: true
21
+
22
+ Ducalis/UselessOnly:
23
+ Enabled: true
24
+
25
+ Ducalis/RestOnlyCop:
26
+ Enabled: true
27
+
28
+ Ducalis/KeywordDefaults:
29
+ Enabled: true
30
+
31
+ Ducalis/RubocopDisable:
32
+ Enabled: true
33
+
34
+ Ducalis/UncommentedGem:
35
+ Enabled: true
36
+ Include:
37
+ - '**/Gemfile'
38
+ - '**/gems.rb'
39
+
40
+ Ducalis/ParamsPassing:
41
+ Enabled: true
42
+
43
+ Ducalis/ControllersExcept:
44
+ Enabled: true
45
+
46
+ Ducalis/PrivateInstanceAssign:
47
+ Enabled: true
48
+
49
+ Ducalis/RaiseWithourErrorClass:
50
+ Enabled: true
51
+
52
+ Ducalis/ModuleLikeClass:
53
+ Enabled: true
54
+ AllowedIncludes:
55
+ - Sidekiq::Worker
56
+ - Singleton
57
+ - ActiveModel::Model
@@ -0,0 +1,39 @@
1
+
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'ducalis/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'ducalis'
10
+ spec.version = Ducalis::VERSION
11
+ spec.authors = ['Ignat Zakrevsky']
12
+ spec.email = ['iezakrevsky@gmail.com']
13
+ spec.summary = 'RuboCop based static code analyzer'
14
+ spec.description = <<-DESCRIPTION
15
+ Ducalis is RuboCop based static code analyzer for enterprise Rails \
16
+ applications.
17
+ DESCRIPTION
18
+
19
+ spec.homepage = 'https://github.com/ignat-z/ducalis'
20
+ spec.license = 'MIT'
21
+
22
+ if spec.respond_to?(:metadata)
23
+ spec.metadata['source_code_uri'] = 'https://github.com/ignat-z/ducalis'
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features|Dockerfile)/})
28
+ end
29
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
30
+
31
+ spec.add_dependency 'policial', '0.0.4'
32
+ spec.add_dependency 'rubocop', '~> 0.50.0'
33
+ spec.add_dependency 'regexp-examples', '~> 1.3', '>= 1.3.2'
34
+ spec.add_dependency 'thor', '~> 0.20.0'
35
+
36
+ spec.add_development_dependency 'bundler', '~> 1.16.a'
37
+ spec.add_development_dependency 'rake', '~> 12.1'
38
+ spec.add_development_dependency 'rspec', '~> 3.0'
39
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'parser/current'
4
+ require 'policial'
5
+
6
+ require 'ducalis/version'
7
+
8
+ module Ducalis
9
+ DOTFILE = '.ducalis.yml'
10
+ DUCALIS_HOME = File.realpath(File.join(File.dirname(__FILE__), '..'))
11
+ DEFAULT_FILE = File.join(DUCALIS_HOME, 'config', DOTFILE)
12
+ end
13
+
14
+ require 'ducalis/adapters/base'
15
+ require 'ducalis/adapters/circle_ci'
16
+ require 'ducalis/adapters/custom'
17
+ require 'ducalis/adapters/pull_request'
18
+
19
+ require 'ducalis/commentators/console'
20
+ require 'ducalis/commentators/github'
21
+
22
+ require 'ducalis/cli'
23
+ require 'ducalis/passed_args'
24
+ require 'ducalis/runner'
25
+ require 'ducalis/utils'
26
+
27
+ require 'ducalis/patched_rubocop/diffs'
28
+ require 'ducalis/patched_rubocop/ducalis_config_loader'
29
+ require 'ducalis/patched_rubocop/git_files_access'
30
+ require 'ducalis/patched_rubocop/git_runner'
31
+ require 'ducalis/patched_rubocop/git_turget_finder'
32
+ require 'ducalis/patched_rubocop/rubo_cop'
33
+
34
+ require 'ducalis/cops/callbacks_activerecord'
35
+ require 'ducalis/cops/controllers_except'
36
+ require 'ducalis/cops/keyword_defaults'
37
+ require 'ducalis/cops/module_like_class'
38
+ require 'ducalis/cops/params_passing'
39
+ require 'ducalis/cops/private_instance_assign'
40
+ require 'ducalis/cops/protected_scope_cop'
41
+ require 'ducalis/cops/raise_withour_error_class'
42
+ require 'ducalis/cops/regex_cop'
43
+ require 'ducalis/cops/rest_only_cop'
44
+ require 'ducalis/cops/rubocop_disable'
45
+ require 'ducalis/cops/strings_in_activerecords'
46
+ require 'ducalis/cops/uncommented_gem'
47
+ require 'ducalis/cops/useless_only'
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ducalis
4
+ module Adapters
5
+ class Base
6
+ attr_reader :options
7
+
8
+ def initialize(options)
9
+ @options = options
10
+ end
11
+
12
+ def dry?
13
+ @dry ||= @options.fetch(:dry, false)
14
+ end
15
+ end
16
+ end
17
+ end