code-cleaner 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/code-cleaner +1 -1
- data/code-cleaner-0.1.gem +0 -0
- data/code-cleaner.gemspec +1 -1
- data/support/pre-commit +12 -3
- metadata +1 -1
data/bin/code-cleaner
CHANGED
@@ -114,7 +114,7 @@ status = 10
|
|
114
114
|
# NOTE: if this shows as a bad idea, another way might be to put "/dev/null" resp. "NUL" on Windows to the ARGV
|
115
115
|
begin
|
116
116
|
STDIN.read_nonblock(1)
|
117
|
-
rescue Errno::EAGAIN
|
117
|
+
rescue Errno::EAGAIN, EOFError
|
118
118
|
# The point of inspecting if STDIN and ARGV are empty is that we might
|
119
119
|
# have an empty ARGF if anything passed and if so, it will wait for an interactive input which we don't want
|
120
120
|
unless ARGV.empty?
|
Binary file
|
data/code-cleaner.gemspec
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "code-cleaner"
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.2"
|
7
7
|
s.authors = ["Jakub Šťastný aka Botanicus"]
|
8
8
|
s.homepage = "http://github.com/botanicus/code-cleaner"
|
9
9
|
s.summary = "Remove trailing whitespace, append missing \\n and replace tabs by two spaces"
|
data/support/pre-commit
CHANGED
@@ -12,6 +12,11 @@ echo "Entering pre-commit hook ..."
|
|
12
12
|
# directory, but it isn't very good solution.
|
13
13
|
files=$(git diff --staged --name-only 2> /dev/null || echo ".")
|
14
14
|
|
15
|
+
function abort() {
|
16
|
+
printf "[\e[31mERROR\e[0m] $*\n"
|
17
|
+
exit 1
|
18
|
+
}
|
19
|
+
|
15
20
|
# NOTE: we are using printf rather than echo because printf should be
|
16
21
|
# more portable, each echo implementation has quite different behaviour
|
17
22
|
if which code-cleaner &> /dev/null; then
|
@@ -23,15 +28,19 @@ if which code-cleaner &> /dev/null; then
|
|
23
28
|
# so we can be sure that the command just wasn't found
|
24
29
|
if [ $? -eq 10 ]; then # code-cleaner exits with 0 if some changes were made
|
25
30
|
printf "[\e[32mCLEAN\e[0m]\n"
|
26
|
-
|
31
|
+
elif [ $? -eq 1 ]; then # something goes wrong
|
32
|
+
printf "[\e[31mERROR\e[0m]\n"
|
33
|
+
code-cleaner "$file" --apply-rules
|
34
|
+
elif [ $? -eq 0 ] ; then
|
27
35
|
printf "[\e[33mDONE\e[0m]\n"
|
28
36
|
git add "$file" # so the changes will be committed immediately
|
37
|
+
else
|
38
|
+
abort "Unexpected exit status $?"
|
29
39
|
fi
|
30
40
|
else
|
31
41
|
printf "Skipping \"\e[36m$file\e[0m\"\n"
|
32
42
|
fi
|
33
43
|
done
|
34
44
|
else
|
35
|
-
|
36
|
-
exit 1
|
45
|
+
abort "You have to install code-cleaner first!"
|
37
46
|
fi
|