Skip to content

Commit a9ed9db

Browse files
committed
Ensure non-word character before and parenthesis after replacement. Also, support spaces/tabs/linebreaks around dot separator.
1 parent f7d7a37 commit a9ed9db

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

app.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ botOptions.changesList = [
6666
message: '[fix] path.exists was moved to fs.exists',
6767
func: function (fileList, settings, cb) {
6868
async.map(fileList, function (file, callback) {
69-
var re = /path\.\bexists\b/g;
70-
fileReplace(file, re, "fs.exists", callback);
69+
var re = /([^[0-9a-zA-Z]])path(\s*.\s*exists\s*\()/g;
70+
fileReplace(file, re, "$1fs$2", callback);
7171
}, function (err, results) {
7272
// results is now an array of stats for each file
7373
if (err) {
@@ -85,8 +85,8 @@ botOptions.changesList = [
8585
message: '[fix] path.existsSync was moved to fs.existsSync',
8686
func: function (fileList, settings, cb) {
8787
async.map(fileList, function (file, callback) {
88-
var re = /path\.\bexistsSync\b/g;
89-
fileReplace(file, re, "fs.existsSync", callback);
88+
var re = /([^[0-9a-zA-Z]])path(\s*.\s*existsSync\s*\()/g;
89+
fileReplace(file, re, "$1fs$2", callback);
9090
}, function (err, results) {
9191
// results is now an array of stats for each file
9292
if (err) {
@@ -104,8 +104,8 @@ botOptions.changesList = [
104104
message: '[fix] tty.setRawMode(mode) was moved to tty.ReadStream#setRawMode() (i.e. process.stdin.setRawMode())',
105105
func: function (fileList, settings, cb) {
106106
async.map(fileList, function (file, callback) {
107-
var re = /tty\.\bsetRawMode\b/g;
108-
fileReplace(file, re, "process.stdin.setRawMode", callback);
107+
var re = /([^[0-9a-zA-Z]])tty(\s*.\s*setRawMode\s*\()/g;
108+
fileReplace(file, re, "$1process.stdin$2", callback);
109109
}, function (err, results) {
110110
// results is now an array of stats for each file
111111
if (err) {
@@ -236,9 +236,9 @@ function fileReplace(filename, re, replacement, cb) {
236236
var dataStr = data.toString(),
237237
fixedDoc = '';
238238

239-
if (XRegExp.test(dataStr, re)) {
239+
if (re.test(dataStr)) {
240240

241-
fixedDoc = XRegExp.replace(dataStr, re, replacement, 'all');
241+
fixedDoc = dataStr.replace(re, replacement);
242242

243243
// write changes out to file
244244
fs.writeFile(filename, fixedDoc, function (err) {

0 commit comments

Comments
 (0)