Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 03d2f20

Browse files
committed
refactor: unescape quotes
This swaps out quote characters to limit how often we need to escape strings. This is just to improve code readability. Almost all of the changes could be done without changes to .eslintrc, however this amends the lint rule to also permit backtick strings which can be useful to eliminate a few extra instances of quote escaping. Fixes issue #788 Test: npm run lint
1 parent d9d7f4d commit 03d2f20

File tree

16 files changed

+37
-33
lines changed

16 files changed

+37
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ Examples:
794794

795795
```javascript
796796
grep('foo', 'file1.txt', 'file2.txt').sed(/o/g, 'a').to('output.txt');
797-
echo('files with o\'s in the name:\n' + ls().grep('o'));
797+
echo("files with o's in the name:\n" + ls().grep('o'));
798798
cat('test.js').exec('node'); // pipe to exec() call
799799
```
800800

shell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ exports.env = process.env;
6969
//@
7070
//@ ```javascript
7171
//@ grep('foo', 'file1.txt', 'file2.txt').sed(/o/g, 'a').to('output.txt');
72-
//@ echo('files with o\'s in the name:\n' + ls().grep('o'));
72+
//@ echo("files with o's in the name:\n" + ls().grep('o'));
7373
//@ cat('test.js').exec('node'); // pipe to exec() call
7474
//@ ```
7575
//@

test/.eslintrc.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
"new-cap": ["error", {
3333
"capIsNewExceptions": [
3434
"ShellString"
35-
]}
36-
]
35+
]
36+
}],
37+
"quotes": ["error", "single", {
38+
"avoidEscape": true,
39+
"allowTemplateLiterals": true
40+
}]
3741
}
3842
}

test/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ test('Some basic tests on the ShellString type', t => {
311311
});
312312

313313
test.cb('Commands that fail will still output error messages to stderr', t => {
314-
const script = 'require(\'./global\'); ls(\'noexist\'); cd(\'noexist\');';
314+
const script = "require('./global'); ls('noexist'); cd('noexist');";
315315
utils.runScript(script, (err, stdout, stderr) => {
316316
t.is(stdout, '');
317317
t.is(

test/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ test('config.silent can be set to false', t => {
3434

3535
test.cb('config.fatal = false', t => {
3636
t.falsy(shell.config.fatal);
37-
const script = 'require(\'./global.js\'); config.silent=true; config.fatal=false; cp("this_file_doesnt_exist", "."); echo("got here");';
37+
const script = `require('./global.js'); config.silent=true; config.fatal=false; cp("this_file_doesnt_exist", "."); echo("got here");`;
3838
utils.runScript(script, (err, stdout) => {
3939
t.truthy(stdout.match('got here'));
4040
t.end();
4141
});
4242
});
4343

4444
test.cb('config.fatal = true', t => {
45-
const script = 'require(\'./global.js\'); config.silent=true; config.fatal=true; cp("this_file_doesnt_exist", "."); echo("got here");';
45+
const script = `require('./global.js'); config.silent=true; config.fatal=true; cp("this_file_doesnt_exist", "."); echo("got here");`;
4646
utils.runScript(script, (err, stdout) => {
4747
t.falsy(stdout.match('got here'));
4848
t.end();

test/cp.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ test('-R implies -P', t => {
443443
});
444444
});
445445

446-
test('-Ru respects the -u flag recursively (don\'t update newer file)', t => {
446+
test("-Ru respects the -u flag recursively (don't update newer file)", t => {
447447
// Setup code
448448
const dir = `${t.context.tmp}/cp-Ru`;
449449
const sourceDir = `${dir}/original`;
@@ -521,7 +521,7 @@ test('Recursive, copies entire directory with no symlinks and -L option does not
521521
});
522522
});
523523

524-
test('-u flag won\'t overwrite newer files', t => {
524+
test("-u flag won't overwrite newer files", t => {
525525
shell.touch(`${t.context.tmp}/file1.js`);
526526
shell.cp('-u', 'test/resources/file1.js', t.context.tmp);
527527
t.falsy(shell.error());
@@ -535,7 +535,7 @@ test('-u flag does overwrite older files', t => {
535535
t.is(shell.cat('test/resources/file1.js').toString(), shell.cat(`${t.context.tmp}/file1.js`).toString());
536536
});
537537

538-
test('-u flag works even if it\'s not overwriting a file', t => {
538+
test("-u flag works even if it's not overwriting a file", t => {
539539
t.falsy(fs.existsSync(`${t.context.tmp}/file1.js`));
540540
shell.cp('-u', 'test/resources/file1.js', t.context.tmp);
541541
t.falsy(shell.error());

test/head.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ test('Globbed file', t => {
100100
.join('\n') + '\n');
101101
});
102102

103-
test('With `\'-n\' <num>` option', t => {
103+
test("With '-n <num>' option", t => {
104104
const result = shell.head('-n', 4, 'test/resources/head/file2.txt',
105105
'test/resources/head/file1.txt');
106106
t.falsy(shell.error());
@@ -111,7 +111,7 @@ test('With `\'-n\' <num>` option', t => {
111111
.join('\n') + '\n');
112112
});
113113

114-
test('With `{\'-n\': <num>}` option', t => {
114+
test("With '{-n: <num>}' option", t => {
115115
const result = shell.head({ '-n': 4 }, 'test/resources/head/file2.txt',
116116
'test/resources/head/file1.txt');
117117
t.falsy(shell.error());

test/ls.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test('no such file or dir', t => {
3636
// Valids
3737
//
3838

39-
test('it\'s ok to use no arguments', t => {
39+
test("it's ok to use no arguments", t => {
4040
const result = shell.ls();
4141
t.falsy(shell.error());
4242
t.is(result.code, 0);
@@ -205,15 +205,15 @@ test('wildcard, mid-file with dot (should escape dot for regex)', t => {
205205
t.truthy(result.indexOf('test/resources/ls/file2.js') > -1);
206206
});
207207

208-
test('one file that exists, one that doesn\'t', t => {
208+
test("one file that exists, one that doesn't", t => {
209209
const result = shell.ls('test/resources/ls/file1.js', 'test/resources/ls/thisdoesntexist');
210210
t.truthy(shell.error());
211211
t.is(result.code, 2);
212212
t.is(result.length, 1);
213213
t.truthy(result.indexOf('test/resources/ls/file1.js') > -1);
214214
});
215215

216-
test('one file that exists, one that doesn\'t (other order)', t => {
216+
test("one file that exists, one that doesn't (other order)", t => {
217217
const result = shell.ls('test/resources/ls/thisdoesntexist', 'test/resources/ls/file1.js');
218218
t.truthy(shell.error());
219219
t.is(result.code, 2);
@@ -364,7 +364,7 @@ test('directory option, single arg', t => {
364364
t.is(result.length, 1);
365365
});
366366

367-
test('directory option, single arg with trailing \'/\'', t => {
367+
test("directory option, single arg with trailing '/'", t => {
368368
const result = shell.ls('-d', 'test/resources/ls/');
369369
t.falsy(shell.error());
370370
t.is(result.code, 0);

test/mkdir.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test('dir already exists', t => {
3737
t.is(common.statFollowLinks(t.context.tmp).mtime.toString(), mtime); // didn't mess with dir
3838
});
3939

40-
test('Can\'t overwrite a broken link', t => {
40+
test("Can't overwrite a broken link", t => {
4141
const mtime = common.statNoFollowLinks('test/resources/badlink').mtime.toString();
4242
const result = shell.mkdir('test/resources/badlink');
4343
t.truthy(shell.error());

test/mv.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ test('too many sources (exist, but dest is file)', t => {
121121
t.is(result.stderr, 'mv: dest is not a directory (too many sources)');
122122
});
123123

124-
test('can\'t use wildcard when dest is file', t => {
124+
test("can't use wildcard when dest is file", t => {
125125
const result = shell.mv('file*', 'file1');
126126
t.truthy(shell.error());
127127
t.truthy(fs.existsSync('file1'));

0 commit comments

Comments
 (0)