Skip to content

Commit f158a86

Browse files
Trottbenjamingr
authored andcommitted
src,tools: use template literals
Convert string concatenation to template literals. Enforce with lint rule. PR-URL: #5778 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
1 parent e5f8a6a commit f158a86

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
rules:
2+
# ECMAScript-6
3+
# http://eslint.org/docs/rules/#ecmascript-6
4+
prefer-template: 2
25
# Custom rules in tools/eslint-rules
36
buffer-constructor: 2

src/node.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -566,19 +566,19 @@
566566
module.paths = Module._nodeModulePaths(cwd);
567567
var script = process._eval;
568568
var body = script;
569-
script = 'global.__filename = ' + JSON.stringify(name) + ';\n' +
569+
script = `global.__filename = ${JSON.stringify(name)};\n` +
570570
'global.exports = exports;\n' +
571571
'global.module = module;\n' +
572572
'global.__dirname = __dirname;\n' +
573573
'global.require = require;\n' +
574574
'return require("vm").runInThisContext(' +
575-
JSON.stringify(body) + ', { filename: ' +
576-
JSON.stringify(name) + ', displayErrors: true });\n';
575+
`${JSON.stringify(body)}, { filename: ` +
576+
`${JSON.stringify(name)}, displayErrors: true });\n`;
577577
// Defer evaluation for a tick. This is a workaround for deferred
578578
// events not firing when evaluating scripts from the command line,
579579
// see https://github.com/nodejs/node/issues/1600.
580580
process.nextTick(function() {
581-
var result = module._compile(script, name + '-wrapper');
581+
var result = module._compile(script, `${name}-wrapper`);
582582
if (process._print_eval) console.log(result);
583583
});
584584
}
@@ -770,7 +770,7 @@
770770
sig.slice(0, 3) === 'SIG') {
771771
err = process._kill(pid, startup.lazyConstants()[sig]);
772772
} else {
773-
throw new Error('Unknown signal: ' + sig);
773+
throw new Error(`Unknown signal: ${sig}`);
774774
}
775775
}
776776

@@ -875,7 +875,7 @@
875875
}
876876

877877
function NativeModule(id) {
878-
this.filename = id + '.js';
878+
this.filename = `${id}.js`;
879879
this.id = id;
880880
this.exports = {};
881881
this.loaded = false;
@@ -895,10 +895,10 @@
895895
}
896896

897897
if (!NativeModule.exists(id)) {
898-
throw new Error('No such native module ' + id);
898+
throw new Error(`No such native module ${id}`);
899899
}
900900

901-
process.moduleLoadList.push('NativeModule ' + id);
901+
process.moduleLoadList.push(`NativeModule ${id}`);
902902

903903
var nativeModule = new NativeModule(id);
904904

0 commit comments

Comments
 (0)