zapwhite 2.7.0 → 2.8.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.
- checksums.yaml +4 -4
- data/lib/reality/zapwhite.rb +7 -14
- data/test/fixtures/file_with_bom.tsql +1 -0
- data/test/fixtures/utf8.tcss +1 -0
- data/test/reality/test_zapwhite.rb +42 -0
- data/zapwhite.gemspec +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2423f66a8de55eaf85a5fe00334753d88b11e3b
|
4
|
+
data.tar.gz: 4f889dcf0c72139d7b3737824958b78d890489ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f035b6ad39e25cf9877e3b5d80b43b9b2c83a72bdaf0ffeb906640afe6225fe6a25d0d4f7c06b04de04acab724f3224d2283ee52f62b0d8be50434551a692aac
|
7
|
+
data.tar.gz: 40ede83227770a08bb4b5034444550dfe3372fdd00be0631a430977643010d0a86b970f5270f4d2ae7bb118ef7d8c485bdc9fc3348ed904d8e9938ca628818df
|
data/lib/reality/zapwhite.rb
CHANGED
@@ -72,10 +72,12 @@ module Reality
|
|
72
72
|
|
73
73
|
files.each_pair do |filename, config|
|
74
74
|
full_filename = "#{@base_directory}/#{filename}"
|
75
|
-
|
75
|
+
original_bin_content = File.binread(full_filename)
|
76
|
+
|
77
|
+
encoding = config[:encoding].nil? ? 'utf-8' : config[:encoding].gsub(/^UTF/,'utf-')
|
78
|
+
|
79
|
+
content = File.read(full_filename, :encoding => "bom|#{encoding}")
|
76
80
|
|
77
|
-
content = patch_encoding(content) unless config[:encoding]
|
78
|
-
original_content = content.dup
|
79
81
|
content =
|
80
82
|
config[:dos] ?
|
81
83
|
clean_dos_whitespace(filename, content, config[:eofnl]) :
|
@@ -85,7 +87,7 @@ module Reality
|
|
85
87
|
# Keep removing duplicate new lines till they have gone
|
86
88
|
end
|
87
89
|
end
|
88
|
-
if content !=
|
90
|
+
if content.bytes != original_bin_content.bytes
|
89
91
|
normalize_count += 1
|
90
92
|
if check_only?
|
91
93
|
puts "Non-normalized whitespace in #{filename}"
|
@@ -177,15 +179,6 @@ module Reality
|
|
177
179
|
content
|
178
180
|
end
|
179
181
|
|
180
|
-
def patch_encoding(content)
|
181
|
-
content =
|
182
|
-
content.respond_to?(:encode!) ?
|
183
|
-
content.encode!('UTF-8', 'binary', :invalid => :replace, :undef => :replace, :replace => '') :
|
184
|
-
content
|
185
|
-
content.gsub!(/^\xEF\xBB\xBF/, '')
|
186
|
-
content
|
187
|
-
end
|
188
|
-
|
189
182
|
# Evaluate block after changing directory to specified directory
|
190
183
|
def in_dir(dir, &block)
|
191
184
|
original_dir = Dir.pwd
|
@@ -228,7 +221,7 @@ module Reality
|
|
228
221
|
attributes.text_rule('*.rdoc')
|
229
222
|
attributes.text_rule('*.html')
|
230
223
|
attributes.text_rule('*.xhtml')
|
231
|
-
attributes.text_rule('*.css'
|
224
|
+
attributes.text_rule('*.css')
|
232
225
|
attributes.text_rule('*.js')
|
233
226
|
attributes.binary_rule('*.jpg')
|
234
227
|
attributes.binary_rule('*.jpeg')
|
@@ -0,0 +1 @@
|
|
1
|
+
CREATE TYPE [dbo].[Boolean__Yes_No_] FROM [tinyint] NOT NULL
|
@@ -0,0 +1 @@
|
|
1
|
+
→
|
@@ -266,4 +266,46 @@ Fixing: .gitattributes
|
|
266
266
|
OUTPUT
|
267
267
|
end
|
268
268
|
end
|
269
|
+
|
270
|
+
def test_file_with_bom
|
271
|
+
dir = create_git_repo do
|
272
|
+
write_gitattributes_file(<<TEXT)
|
273
|
+
*.tsql text
|
274
|
+
TEXT
|
275
|
+
write_file('test.tsql', IO.binread(File.expand_path(BASE_DIR + '/test/fixtures/file_with_bom.tsql')))
|
276
|
+
end
|
277
|
+
in_dir(dir) do
|
278
|
+
output = run_command("#{ZAPWHITE_BIN} --no-generate-gitattributes", 1)
|
279
|
+
assert_equal "Fixing: test.tsql\n", output
|
280
|
+
assert_equal "CREATE TYPE [dbo].[Boolean__Yes_No_] FROM [tinyint] NOT NULL\n", IO.binread("#{dir}/test.tsql")
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_file_with_utf8_encoding
|
285
|
+
dir = create_git_repo do
|
286
|
+
write_gitattributes_file(<<TEXT)
|
287
|
+
*.tcss text
|
288
|
+
TEXT
|
289
|
+
write_file('test.tcss', IO.binread(File.expand_path(BASE_DIR + '/test/fixtures/utf8.tcss')))
|
290
|
+
end
|
291
|
+
in_dir(dir) do
|
292
|
+
output = run_command("#{ZAPWHITE_BIN} --no-generate-gitattributes", 0)
|
293
|
+
assert_equal '', output
|
294
|
+
assert_equal IO.binread(File.expand_path(BASE_DIR + '/test/fixtures/utf8.tcss')), IO.binread("#{dir}/test.tcss")
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_file_with_bom_encoding_set
|
299
|
+
dir = create_git_repo do
|
300
|
+
write_gitattributes_file(<<TEXT)
|
301
|
+
*.tsql text encoding=utf-8
|
302
|
+
TEXT
|
303
|
+
write_file('test.tsql', IO.binread(File.expand_path(BASE_DIR + '/test/fixtures/file_with_bom.tsql')))
|
304
|
+
end
|
305
|
+
in_dir(dir) do
|
306
|
+
output = run_command("#{ZAPWHITE_BIN} --no-generate-gitattributes", 1)
|
307
|
+
assert_equal "Fixing: test.tsql\n", output
|
308
|
+
assert_equal "CREATE TYPE [dbo].[Boolean__Yes_No_] FROM [tinyint] NOT NULL\n", IO.binread("#{dir}/test.tsql")
|
309
|
+
end
|
310
|
+
end
|
269
311
|
end
|
data/zapwhite.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zapwhite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Donald
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gitattributes
|
@@ -70,6 +70,8 @@ files:
|
|
70
70
|
- Rakefile
|
71
71
|
- bin/zapwhite
|
72
72
|
- lib/reality/zapwhite.rb
|
73
|
+
- test/fixtures/file_with_bom.tsql
|
74
|
+
- test/fixtures/utf8.tcss
|
73
75
|
- test/helper.rb
|
74
76
|
- test/reality/test_zapwhite.rb
|
75
77
|
- zapwhite.gemspec
|