Skip to content

Commit 0bb9e10

Browse files
committed
tab replacement is now working
1 parent b7646fb commit 0bb9e10

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/tools/tabs.coffee

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@ util = require '../utils'
77
eyes = require 'eyes'
88
fs = require 'fs'
99

10+
# TODO: make this configurable
11+
# right now, the replacement is hard-coded to replace "hard tabs" with "soft tabs, two spaces"
12+
config = {
13+
tab_identifier: /\t/g,
14+
tab_replacement: ' '
15+
}
16+
17+
1018
exports.exec = (options, callback) ->
1119
file_count = 0
20+
tab_instances = 0
1221

1322
if options._.length == 1
1423
callback({ message: "File name, directory path, or glob is required"});
@@ -31,12 +40,13 @@ exports.exec = (options, callback) ->
3140
# Process the file's contents and then re-save it
3241
# Regex by Fedor Induty
3342
# I've got to assume there are bugs in this Regex, we made it quickly
34-
stripped = data.toString().replace(/(^|\r|\n|\r\n)+\s+(\r|\n|\r\n|$)+/g,'$1$2').replace(/(\r|\n\n|\r\n\n)+/g, '$1')
43+
tab_instances += data.toString().split('\t').length
44+
stripped = data.toString().replace(config.tab_identifier, config.tab_replacement)
3545

3646
fs.writeFile v, stripped, (err, result) ->
3747
file_count = file_count - 1
3848
if file_count == 0
39-
callback null, 'Stripped'
49+
callback null, { "Tabs Replaced": tab_instances, "Files Modified": util.paths(glob).length }
4050

4151
)(v,i)
4252

0 commit comments

Comments
 (0)