code-cleaner 0.6 → 0.7
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.
- data/README.textile +2 -1
- data/bin/code-cleaner +2 -1
- data/code-cleaner.gemspec +1 -1
- data/support/pre-commit.erb +6 -1
- metadata +2 -1
data/README.textile
CHANGED
@@ -24,7 +24,7 @@ Default behaviour is to ignore everything from vendor and gems directories and f
|
|
24
24
|
You can change this behaviour by setting environment variables @BLACKLIST@ and @WHITELIST@. What you pass to these variables will be treated as a regular expression. The default behaviour respond to @BLACKLIST='/(vendor|gems)/'@ and @WHITELIST='\.(rb|rake|task|thor)$'@. Here's an example how you can use it:
|
25
25
|
|
26
26
|
<pre>
|
27
|
-
WHITELIST=''
|
27
|
+
WHITELIST=''^(Rakefile|Thorfile|.+\.(rb|rake|nake|thor|task))$'' BLACKLIST='/(vendor|gems)/' code-cleaner .
|
28
28
|
</pre>
|
29
29
|
|
30
30
|
Note that these rules aren't applied for explicit arguments, so if you run @code-cleaner README.textile@, your readme actually will be normalized. It's because blacklisting and whitelisting rules are applied just on directories, so if you run @code-cleaner .@, your readme will stay untouched. Because of this reason @code-cleaner .@ and @code-cleaner *@ will be different.
|
@@ -73,6 +73,7 @@ end
|
|
73
73
|
|
74
74
|
Also, if you project run in bundled environment, make sure you have your @bin@ or @script@ directory in your @$PATH@ or change the pre-commit hook to point to the right path to the @code-cleaner@. If you are using Nake or Thor, just specify @--path=bin@ resp. @--path=script@ as an option for the @hooks:whitespace:install@ If you are using Rake, you will have to do it manually.
|
75
75
|
|
76
|
+
|
76
77
|
--encoding=utf-8
|
77
78
|
--whitelist=pattern & --blacklist=pattern
|
78
79
|
|
data/bin/code-cleaner
CHANGED
@@ -24,7 +24,7 @@ require "find"
|
|
24
24
|
|
25
25
|
$-i = "" # Windows compatibility
|
26
26
|
|
27
|
-
WHITELIST = Regexp.new(ENV["WHITELIST"] || '
|
27
|
+
WHITELIST = Regexp.new(ENV["WHITELIST"] || '^(Rakefile|Thorfile|.+\.(rb|rake|nake|thor|task))$')
|
28
28
|
BLACKLIST = Regexp.new(ENV["BLACKLIST"] || '/(vendor|gems)/')
|
29
29
|
|
30
30
|
def permitted?(file)
|
@@ -129,6 +129,7 @@ rescue Errno::EAGAIN, EOFError
|
|
129
129
|
# the position is same as is the line, then it has to be the first line.
|
130
130
|
if line.length == ARGF.pos && encoding && ! line.match(/^#(.*coding|\!)/) # the \! should means shebang. TODO: if there is a shebang on the first line, check if encoding declaration is on the second line
|
131
131
|
puts "# encoding: #{encoding}"
|
132
|
+
puts
|
132
133
|
end
|
133
134
|
# You might be wondering WTF is going on, I'm editing files, so I have to use File.open, do the modification on the original content and then save it. The point is we used -i switch which is good for in place editing
|
134
135
|
# flag that we actually changed the 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.7"
|
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.erb
CHANGED
@@ -25,6 +25,8 @@ function abort() {
|
|
25
25
|
exit 1
|
26
26
|
}
|
27
27
|
|
28
|
+
sleep=false
|
29
|
+
|
28
30
|
# NOTE: we are using printf rather than echo because printf should be
|
29
31
|
# more portable, each echo implementation has quite different behaviour
|
30
32
|
if which code-cleaner &> /dev/null; then
|
@@ -47,7 +49,7 @@ if which code-cleaner &> /dev/null; then
|
|
47
49
|
elif [ $exitstatus -eq 0 ] ; then
|
48
50
|
printf "[\e[33mDONE\e[0m]\n"
|
49
51
|
git add "$file" # so the changes will be committed immediately
|
50
|
-
sleep
|
52
|
+
sleep=true # otherwise it might not work
|
51
53
|
else
|
52
54
|
abort "Unexpected exit status $?"
|
53
55
|
fi
|
@@ -59,3 +61,6 @@ if which code-cleaner &> /dev/null; then
|
|
59
61
|
else
|
60
62
|
abort "You have to have code-cleaner installed and the code-cleaner script has to be in your \$PATH ($PATH)"
|
61
63
|
fi
|
64
|
+
|
65
|
+
$sleep && sleep 0.1 # otherwise it might not work
|
66
|
+
exit 0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code-cleaner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.7"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Jakub \xC5\xA0\xC5\xA5astn\xC3\xBD aka Botanicus"
|
@@ -22,6 +22,7 @@ extra_rdoc_files: []
|
|
22
22
|
|
23
23
|
files:
|
24
24
|
- bin/code-cleaner
|
25
|
+
- code-cleaner-0.7.gem
|
25
26
|
- code-cleaner.gemspec
|
26
27
|
- LICENSE
|
27
28
|
- README.textile
|