Skip to content

Commit 2cf0855

Browse files
author
Konstantin Gredeskoul
committed
Adding RuboCop to pre-commit hook to pretty format
1 parent 44ee5e3 commit 2cf0855

File tree

31 files changed

+166
-55
lines changed

31 files changed

+166
-55
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/bazel-*
1+
**/bazel-*
2+
**/.idea

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
inherit_gem:
2+
relaxed-rubocop: .rubocop.yml

bin/deps

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# vim: ft=shell
2+
3+
export BashMatic="${HOME}/.bashmatic"
4+
5+
[[ -s ${BashMatic}/init.sh ]] || {
6+
rm -rf "${BashMatic}" 2>/dev/null
7+
git clone https://github.com/kigster/bashmatic "${BashMatic}" 2>&1 1>/dev/null
8+
}
9+
10+
source "${BashMatic}/init.sh"
11+

bin/post-commit

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
[[ -x bin/deps ]] && source bin/deps
4+
[[ -x bin/setup ]] && source bin/setup
5+
6+
[[ -z ${BashMatic} ]] && {
7+
echo "Failed to initialize BASH library."
8+
exit 1
9+
}
10+
11+
set +e
12+
13+
info "Running Rubocop, please wait..."
14+
rubocop -F -D
15+
code=$?
16+
17+
if [[ ${code} -ne 0 ]]; then
18+
run::set-next show-output-on
19+
run "rubocop -a -D -P"
20+
21+
run::set-next abort-on-error
22+
run "rubocop -D -P"
23+
fi
24+
25+
success "RuboCop ran successfully."

bin/setup

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
[[ -x bin/deps ]] && source bin/deps
4+
5+
[[ -z ${BashMatic} ]] && {
6+
echo "Failed to initialize BASH library."
7+
exit 1
8+
}
9+
10+
# abort on error
11+
run::set-all abort-on-error
12+
13+
# install rubocop
14+
lib::gem::install relaxed-rubocop
15+
lib::gem::install rubocop
16+
17+
[[ -f .rubocop.yml ]] || {
18+
info "Setting up .rubocop.yml file..."
19+
echo "
20+
inherit_gem:
21+
relaxed-rubocop: .rubocop.yml
22+
" > .rubocop.yml
23+
}
24+
25+
26+

examples/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
source "https://rubygems.org"
44

5-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
66

77
gem 'rspec', '~> 3.7.0'

examples/bin/show_version.rb

100644100755
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/ruby
2+
# frozen_string_literal: true
23

34
require 'foo'
45

56
bar = Foo::Bar.new
7+
68
puts Foo::VERSION
9+
puts bar.inspect

examples/lib/foo.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Foo
24
require 'foo/bar'
35
require 'foo/version'

examples/lib/foo/bar.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'openssl'
24

35
module Foo

examples/lib/foo/version.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Foo
24
VERSION = "0.0.1"
35
end

0 commit comments

Comments
 (0)