white 0.1.0
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/.document +5 -0
- data/LICENSE.txt +20 -0
- data/README.md +43 -0
- data/Rakefile +16 -0
- data/VERSION +1 -0
- data/bin/white +4 -0
- data/lib/white.rb +104 -0
- metadata +74 -0
data/.document
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Andrey Tarantsov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
Fix your whitespace
|
2
|
+
===================
|
3
|
+
|
4
|
+
Run from your project folder before committing to Git to avoid whitespace errors.
|
5
|
+
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
sudo gem install white
|
11
|
+
|
12
|
+
|
13
|
+
Usage
|
14
|
+
-----
|
15
|
+
|
16
|
+
cd MyProject
|
17
|
+
...hack hack hack...
|
18
|
+
white
|
19
|
+
git commit -a -m "Add another awesome feature"
|
20
|
+
|
21
|
+
|
22
|
+
Options
|
23
|
+
-------
|
24
|
+
|
25
|
+
$ white --help
|
26
|
+
Usage: white [options]
|
27
|
+
|
28
|
+
Tab expansion:
|
29
|
+
-t, --tabsize=SIZE Expand tabs using the given tab size
|
30
|
+
|
31
|
+
Picking files to process:
|
32
|
+
-e, --ext=EXT Include files with the given extension (e.g. -e inc)
|
33
|
+
-n, --name=NAME Include files with the given name (e.g. -n Cakefile)
|
34
|
+
|
35
|
+
Common options:
|
36
|
+
-v, --verbose Show a full list of processed files
|
37
|
+
-h, --help Show this message
|
38
|
+
|
39
|
+
|
40
|
+
License
|
41
|
+
-------
|
42
|
+
|
43
|
+
Copyright (c) 2011 Andrey Tarantsov. MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new do |gem|
|
6
|
+
gem.name = "white"
|
7
|
+
gem.homepage = "http://github.com/andreyvit/white"
|
8
|
+
gem.license = "MIT"
|
9
|
+
gem.summary = %Q{Fix whitespace errors before committing to Git}
|
10
|
+
gem.description = %Q{Run from your project folder before committing to Git to avoid whitespace errors}
|
11
|
+
gem.email = "andreyvit@gmail.com"
|
12
|
+
gem.authors = ["Andrey Tarantsov"]
|
13
|
+
end
|
14
|
+
Jeweler::RubygemsDotOrgTasks.new
|
15
|
+
|
16
|
+
task :default => :test
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/white
ADDED
data/lib/white.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
class White
|
4
|
+
|
5
|
+
def self.run args
|
6
|
+
extensions = %w/rb java xml md coffee js html css less yml php info install module h m txt/
|
7
|
+
names = %w/Rakefile Cakefile/
|
8
|
+
default_tab_size = nil
|
9
|
+
tab_sizes = {
|
10
|
+
}
|
11
|
+
exclusions = ['**/.git/**']
|
12
|
+
verbose = false
|
13
|
+
|
14
|
+
opts = OptionParser.new do |opts|
|
15
|
+
opts.banner = "Usage: white [options]"
|
16
|
+
|
17
|
+
opts.separator ""
|
18
|
+
opts.separator "Tab expansion:"
|
19
|
+
|
20
|
+
opts.on("-t", "--tabsize=SIZE", "Expand tabs using the given tab size") do |size|
|
21
|
+
default_tab_size = size.to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.separator ""
|
25
|
+
opts.separator "Picking files to process:"
|
26
|
+
|
27
|
+
opts.on("-e", "--ext=EXT", "Include files with the given extension (e.g. -e inc)") do |v|
|
28
|
+
extensions << v
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on("-n", "--name=NAME", "Include files with the given name (e.g. -n Cakefile)") do |v|
|
32
|
+
names << v
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.separator ""
|
36
|
+
opts.separator "Common options:"
|
37
|
+
|
38
|
+
opts.on("-v", "--verbose", "Show a full list of processed files") do
|
39
|
+
verbose = true
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
43
|
+
puts opts
|
44
|
+
exit
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.parse!(args)
|
49
|
+
|
50
|
+
mask = "{" + (names + extensions.collect { |ext| "*.#{ext}" }).join(",") + "}"
|
51
|
+
files = Dir["**/#{mask}"].to_a
|
52
|
+
|
53
|
+
exclusions.each do |exclusion|
|
54
|
+
files -= Dir[exclusion]
|
55
|
+
end
|
56
|
+
|
57
|
+
files_with_tabs = []
|
58
|
+
|
59
|
+
files.each do |file|
|
60
|
+
tab_size = tab_sizes[File.extname(file)] || default_tab_size
|
61
|
+
tab = ' ' * tab_size if default_tab_size
|
62
|
+
|
63
|
+
errors = []
|
64
|
+
|
65
|
+
text = File.read(file)
|
66
|
+
original = text.dup
|
67
|
+
|
68
|
+
prev = text.dup
|
69
|
+
text.gsub! /[ \t]+$/, ''
|
70
|
+
errors << "trailing whitespace" if text != prev
|
71
|
+
|
72
|
+
if text =~ /^ *?\t[\t ]*/
|
73
|
+
if default_tab_size == nil
|
74
|
+
files_with_tabs << file unless files_with_tabs.include?(file)
|
75
|
+
elsif default_tab_size > 0
|
76
|
+
text.gsub!(/^ *?\t[\t ]*/) { |indent| indent.gsub "\t", tab }
|
77
|
+
errors << "tabs"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
if text =~ /\t/
|
82
|
+
if default_tab_size == nil
|
83
|
+
files_with_tabs << file unless files_with_tabs.include?(file)
|
84
|
+
elsif default_tab_size > 0
|
85
|
+
text.gsub!("\t", tab)
|
86
|
+
errors << "tabs inside source"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
if text != original
|
91
|
+
puts "#{file} (#{errors.join(', ')})"
|
92
|
+
File.open(file, 'w') { |f| f.write text }
|
93
|
+
else
|
94
|
+
puts "#{file} OK" if verbose
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
unless files_with_tabs.empty?
|
99
|
+
$stderr.puts "\nThe following file(s) contain tabs. To expand them, please use -t4 option."
|
100
|
+
files_with_tabs.each { |f| $stderr.puts " - #{f}" }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: white
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Andrey Tarantsov
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-09 00:00:00 +07:00
|
19
|
+
default_executable: white
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Run from your project folder before committing to Git to avoid whitespace errors
|
23
|
+
email: andreyvit@gmail.com
|
24
|
+
executables:
|
25
|
+
- white
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- LICENSE.txt
|
30
|
+
- README.md
|
31
|
+
files:
|
32
|
+
- .document
|
33
|
+
- LICENSE.txt
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- VERSION
|
37
|
+
- bin/white
|
38
|
+
- lib/white.rb
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/andreyvit/white
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.3.7
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Fix whitespace errors before committing to Git
|
73
|
+
test_files: []
|
74
|
+
|