-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.rb
144 lines (108 loc) · 2.68 KB
/
template.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Bootstrap
gem 'bootstrap', '~> 4.0.0.beta'
gem 'bootstrap_form', github: 'bootstrap-ruby/rails-bootstrap-forms'
gem 'jquery-rails'
# Exceptions
gem 'exception_notification', github: 'smartinez87/exception_notification'
# Background jobs
gem 'sidekiq'
gem_group :development do
# Code checks
gem 'rubocop', require: false
# Deployment
gem 'capistrano-bundler', require: false
gem 'capistrano-rails', require: false
gem 'capistrano-rails-console', require: false
gem 'capistrano-rbenv', require: false
gem 'capistrano-sidekiq', require: false
gem 'capistrano3-puma', require: false
end
# Rubocop file
file '.rubocop.yml', <<-CODE
AllCops:
Exclude:
- db/schema.rb
- db/seeds.rb
- db/migrate/*
- bin/*
- config/**/
Rails:
Enabled: true
Documentation:
Enabled: false
Rails/OutputSafety:
Enabled: false
DotPosition:
Enabled: false
Layout/EmptyLinesAroundBlockBody:
Enabled: false
Layout/EmptyLinesAroundModuleBody:
Enabled: false
Layout/EmptyLinesAroundClassBody:
Enabled: false
Layout/EmptyLinesAroundMethodBody:
Enabled: false
Layout/DotPosition:
Enabled: false
Layout/IndentHash:
Enabled: false
Style/EmptyMethod:
Enabled: false
Style/RegexpLiteral:
Enabled: false
Lint/AmbiguousBlockAssociation:
Enabled: false
Metrics/BlockLength:
Exclude:
- config/routes.rb
- config/**/*.rb
- test/**/*.rb
Metrics/LineLength:
Max: 125
Exclude:
- config/**/*.rb
Metrics/MethodLength:
Max: 12
Style/ClassAndModuleChildren:
Exclude:
- test/**/*.rb
CODE
# Call Rubocop before comitting
file '.git/hooks/pre-commit', <<-CODE
file
#!/bin/sh
#
# Check for ruby style errors
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
NC='\033[0m'
against=HEAD
# Check if rubocop is installed for the current project
bin/bundle exec rubocop -v >/dev/null 2>&1 || { echo >&2 "${red}[Ruby Style][Fatal]: Add rubocop to your Gemfile"; exit 1; }
# Get only the staged files
FILES="$(git diff --cached --name-only --diff-filter=AMC | grep "\.rb$" | tr '\n' ' ')"
echo "${green}[Ruby Style][Info]: Checking Ruby Style${NC}"
if [ -n "$FILES" ]
then
echo "${green}[Ruby Style][Info]: ${FILES}${NC}"
if [ ! -f '.rubocop.yml' ]; then
echo "${yellow}[Ruby Style][Warning]: No .rubocop.yml config file.${NC}"
fi
# Run rubocop on the staged files
bin/bundle exec rubocop --force-exclusion ${FILES}
if [ $? -ne 0 ]; then
echo "${red}[Ruby Style][Error]: Fix the issues and commit again${NC}"
exit 1
fi
else
echo "${green}[Ruby Style][Info]: No files to check${NC}"
fi
exit 0
CODE
# Make it executable
run 'chmod a+x .git/hooks/pre-commit'
# Run Rubocop
after_bundle do
rails_command 'bundle exec rubocop --auto-correct'
end