Replace most usage of util module with template strings.

This commit is contained in:
Jeff Williams 2019-05-12 12:05:43 -07:00
parent b88470aefe
commit 5ef86bca6d
8 changed files with 24 additions and 33 deletions

View File

@ -4,7 +4,6 @@ const exec = require('child_process').exec;
const gulp = require('gulp');
const jsonEditor = require('gulp-json-editor');
const path = require('path');
const util = require('util');
function execCb(cb, err, stdout, stderr) {
console.log(stdout);
@ -41,7 +40,7 @@ function bump(cb) {
}
function coverage(cb) {
const cmd = util.format('./node_modules/.bin/nyc --reporter=html %s -T', options.nodeBin);
const cmd = `./node_modules/.bin/nyc --reporter=html ${options.nodeBin} -T`;
exec(cmd, execCb.bind(null, cb));
}
@ -56,7 +55,7 @@ function lint(cb) {
}
function test(cb) {
const cmd = util.format('%s "%s" -T', options.nodePath, options.nodeBin);
const cmd = `${options.nodePath} "${options.nodeBin}" -T`;
exec(cmd, execCb.bind(null, cb));
}

View File

@ -19,7 +19,6 @@ const jsdoc = {
};
const path = require('jsdoc/path');
const Syntax = jsdoc.src.Syntax;
const util = require('util');
function applyTag(doclet, {title, value}) {
if (title === 'name') {
@ -383,10 +382,10 @@ class Doclet {
if (!scopeNames.includes(scope)) {
filepath = getFilepath(this);
errorMessage = util.format('The scope name "%s" is not recognized. Use one of the ' +
'following values: %j', scope, scopeNames);
errorMessage = `The scope name "${scope}" is not recognized. Use one of the ` +
`following values: ${scopeNames}`;
if (filepath) {
errorMessage += util.format(' (Source file: %s)', filepath);
errorMessage += ` (Source file: ${filepath})`;
}
throw new Error(errorMessage);

View File

@ -3,7 +3,6 @@
* @module jsdoc/opts/argparser
*/
const _ = require('lodash');
const util = require('util');
const hasOwnProp = Object.prototype.hasOwnProperty;
@ -252,7 +251,7 @@ class ArgParser {
}
if (option === null) {
throw new Error( util.format('Unknown command-line option "%s".', name) );
throw new Error(`Unknown command-line option "${name}".`);
}
if (option.hasValue) {
@ -260,7 +259,7 @@ class ArgParser {
i++;
if (value === null || value.charAt(0) === '-') {
throw new Error( util.format('The command-line option "%s" requires a value.', name) );
throw new Error(`The command-line option "${name}" requires a value.`);
}
}
else {

View File

@ -4,7 +4,6 @@ const cast = require('jsdoc/util/cast').cast;
const env = require('jsdoc/env');
const name = require('jsdoc/name');
const Syntax = require('jsdoc/src/syntax').Syntax;
const util = require('util');
// Counter for generating unique node IDs.
let uid = 100000000;
@ -203,7 +202,7 @@ const nodeToValue = exports.nodeToValue = node => {
// could be computed (like foo['bar']) or not (like foo.bar)
str = nodeToValue(node.object);
if (node.computed) {
str += util.format('[%s]', node.property.raw);
str += `[${node.property.raw}]`;
}
else {
str += `.${nodeToValue(node.property)}`;
@ -293,8 +292,7 @@ const nodeToValue = exports.nodeToValue = node => {
}
else {
// this shouldn't happen
throw new Error( util.format('Found a UnaryExpression with a postfix operator: %j',
node) );
throw new Error(`Found a UnaryExpression with a postfix operator: ${node}`);
}
break;

View File

@ -21,7 +21,6 @@ const jsdoc = {
}
};
const path = require('jsdoc/path');
const util = require('util');
// Check whether the text is the same as a symbol name with leading or trailing whitespace. If so,
// the whitespace must be preserved, and the text cannot be trimmed.
@ -37,7 +36,7 @@ function trim(text, opts, meta) {
text = String(typeof text === 'undefined' ? '' : text);
if ( mustPreserveWhitespace(text, meta) ) {
text = util.format('"%s"', text);
text = `"${text}"`;
}
else if (opts.keepsWhitespace) {
text = text.replace(/^[\n\r\f]+|[\n\r\f]+$/g, '');

View File

@ -8,7 +8,6 @@ const MarkdownIt = require('markdown-it');
const marked = require('marked');
const mda = require('markdown-it-anchor');
const path = require('jsdoc/path');
const util = require('util');
/**
* Enumeration of Markdown parsers that are available.
@ -110,13 +109,13 @@ function highlight(code, language) {
}
if (language !== 'plain') {
classString = util.format(' class="prettyprint source%s"', langClass);
classString = ` class="prettyprint source${langClass}"`;
}
else {
classString = ' class="source"';
}
return util.format('<pre%s><code>%s</code></pre>', classString, escapeCode(code));
return `<pre${classString}><code>${escapeCode(code)}</code></pre>`;
}
/**
@ -203,7 +202,7 @@ function getParseFunction(parserName, conf) {
renderer = new marked.Renderer();
if (!conf.idInHeadings) {
renderer.heading = (text, level) => util.format('<h%s>%s</h%s>', level, text, level);
renderer.heading = (text, level) => `<h${level}>${text}</h${level}>`;
}
renderer.code = highlighter;

View File

@ -7,7 +7,6 @@ const env = require('jsdoc/env');
const inline = require('jsdoc/tag/inline');
const logger = require('jsdoc/util/logger');
const name = require('jsdoc/name');
const util = require('util');
const hasOwnProp = Object.prototype.hasOwnProperty;
@ -315,7 +314,7 @@ function getShortName(longname) {
* @return {string} The HTML link, or the link text if the link is not available.
*/
function buildLink(longname, linkText, options) {
const classString = options.cssClass ? util.format(' class="%s"', options.cssClass) : '';
const classString = options.cssClass ? ` class="${options.cssClass}"` : '';
let fileUrl;
const fragmentString = fragmentHash(options.fragmentId);
let stripped;
@ -350,8 +349,7 @@ function buildLink(longname, linkText, options) {
return text;
}
else {
return util.format('<a href="%s"%s>%s</a>', encodeURI(fileUrl + fragmentString),
classString, text);
return `<a href="${encodeURI(fileUrl + fragmentString)}"${classString}>${text}</a>`;
}
}

View File

@ -6,7 +6,6 @@ const logger = require('jsdoc/util/logger');
const path = require('jsdoc/path');
const taffy = require('taffydb').taffy;
const template = require('jsdoc/template');
const util = require('util');
const htmlsafe = helper.htmlsafe;
const linkto = helper.linkto;
@ -100,8 +99,7 @@ function updateItemName(item) {
}
if (attributes && attributes.length) {
itemName = util.format( '%s<span class="signature-attributes">%s</span>', itemName,
attributes.join(', ') );
itemName = `${itemName}<span class="signature-attributes">${attributes.join(', ')}</span>`;
}
return itemName;
@ -127,7 +125,7 @@ function buildAttribsString(attribs) {
let attribsString = '';
if (attribs && attribs.length) {
attribsString = htmlsafe( util.format('(%s) ', attribs.join(', ')) );
htmlsafe(`(${attribs.join(', ')}) `);
}
return attribsString;
@ -146,7 +144,7 @@ function addNonParamAttributes(items) {
function addSignatureParams(f) {
const params = f.params ? addParamAttributes(f.params) : [];
f.signature = util.format( '%s(%s)', (f.signature || ''), params.join(', ') );
f.signature = `${f.signature || ''}(${params.join(', ')})`;
}
function addSignatureReturns(f) {
@ -175,23 +173,25 @@ function addSignatureReturns(f) {
returnTypes = addNonParamAttributes(source);
}
if (returnTypes.length) {
returnTypesString = util.format( ' &rarr; %s{%s}', attribsString, returnTypes.join('|') );
returnTypesString = ` &rarr; ${attribsString}{${returnTypes.join('|')}}`;
}
f.signature = `<span class="signature">${f.signature || ''}</span><span class="type-signature">${returnTypesString}</span>`;
f.signature = `<span class="signature">${f.signature || ''}</span>` +
`<span class="type-signature">${returnTypesString}</span>`;
}
function addSignatureTypes(f) {
const types = f.type ? buildItemTypeStrings(f) : [];
f.signature = `${f.signature || ''}<span class="type-signature">${types.length ? ` :${types.join('|')}` : ''}</span>`;
f.signature = `${f.signature || ''}<span class="type-signature">` +
`${types.length ? ` :${types.join('|')}` : ''}</span>`;
}
function addAttribs(f) {
const attribs = helper.getAttribs(f);
const attribsString = buildAttribsString(attribs);
f.attribs = util.format('<span class="type-signature">%s</span>', attribsString);
f.attribs = `<span class="type-signature">${attribsString}</span>`;
}
function shortenPaths(files, commonPrefix) {