zapwhite 2.7.0 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81bcca5ce52c55d266fdfa3cffde9ce3cd270669
4
- data.tar.gz: 9b2c1de397485ca1897e159fc5872dbd56e2ddfe
3
+ metadata.gz: f2423f66a8de55eaf85a5fe00334753d88b11e3b
4
+ data.tar.gz: 4f889dcf0c72139d7b3737824958b78d890489ef
5
5
  SHA512:
6
- metadata.gz: a72c6981d8c3bb449503bc2fad48f21d89c989f27d5cbe8ea0301ddb75409dee025ca69fcb4d441207e89039f74da1019712931beb7fb59f4a2edd30d746558a
7
- data.tar.gz: de3cb47158d66835ae676bfabf4b8c4280a374aa9bdbad90994660de4791014cb2d111cb19cd52782ebae8fec8c7653bdefa39e5bf0d5c771beda9b7490fd009
6
+ metadata.gz: f035b6ad39e25cf9877e3b5d80b43b9b2c83a72bdaf0ffeb906640afe6225fe6a25d0d4f7c06b04de04acab724f3224d2283ee52f62b0d8be50434551a692aac
7
+ data.tar.gz: 40ede83227770a08bb4b5034444550dfe3372fdd00be0631a430977643010d0a86b970f5270f4d2ae7bb118ef7d8c485bdc9fc3348ed904d8e9938ca628818df
@@ -72,10 +72,12 @@ module Reality
72
72
 
73
73
  files.each_pair do |filename, config|
74
74
  full_filename = "#{@base_directory}/#{filename}"
75
- content = File.read(full_filename)
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 != original_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', :encoding => 'UTF8')
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{zapwhite}
5
- s.version = '2.7.0'
5
+ s.version = '2.8.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
 
8
8
  s.authors = ['Peter Donald']
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.7.0
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-18 00:00:00.000000000 Z
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