Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: replace string concatenations with template literals #16046

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions tools/doc/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const marked = require('marked');
// customized heading without id attribute
const renderer = new marked.Renderer();
renderer.heading = function(text, level) {
return '<h' + level + '>' + text + '</h' + level + '>\n';
return `<h${level}>${text}</h${level}>\n`;
};
marked.setOptions({
renderer: renderer
Expand Down Expand Up @@ -64,8 +64,8 @@ function doJSON(input, filename, cb) {
if (type === 'heading' &&
!text.trim().match(/^example/i)) {
if (tok.depth - depth > 1) {
return cb(new Error('Inappropriate heading level\n' +
JSON.stringify(tok)));
return cb(new Error(`Inappropriate heading level
${JSON.stringify(tok)}`));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit - we actually prefer not to use multiline template strings. This should likely be changed while landing and we might think about adding a eslint rule against this as it comes up more often.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same applies to the other template strings in here.

}

// Sometimes we have two headings with a single
Expand Down Expand Up @@ -245,26 +245,26 @@ function processList(section) {
}
} else if (type === 'list_item_end') {
if (!current) {
throw new Error('invalid list - end without current item\n' +
JSON.stringify(tok) + '\n' +
JSON.stringify(list));
throw new Error(`invalid list - end without current item
${JSON.stringify(tok)}
${JSON.stringify(list)}`);
}
current = stack.pop();
} else if (type === 'text') {
if (!current) {
throw new Error('invalid list - text without current item\n' +
JSON.stringify(tok) + '\n' +
JSON.stringify(list));
throw new Error(`invalid list - text without current item
${JSON.stringify(tok)}
${JSON.stringify(list)}`);
}
current.textRaw = current.textRaw || '';
current.textRaw += tok.text + ' ';
current.textRaw += `${tok.text} `;
}
});

// shove the name in there for properties, since they are always
// just going to be the value etc.
if (section.type === 'property' && values[0]) {
values[0].textRaw = '`' + section.name + '` ' + values[0].textRaw;
values[0].textRaw = `\`${section.name}\` ${values[0].textRaw}`;
}

// now pull the actual values out of the text bits.
Expand Down Expand Up @@ -362,8 +362,8 @@ function parseSignature(text, sig) {
// at this point, the name should match.
if (p !== param.name) {
console.error('Warning: invalid param "%s"', p);
console.error(' > ' + JSON.stringify(param));
console.error(' > ' + text);
console.error(` > ${JSON.stringify(param)}`);
console.error(` > ${text}`);
}
if (optional) param.optional = true;
if (def !== undefined) param.default = def;
Expand Down Expand Up @@ -427,9 +427,9 @@ function parseListItem(item) {

function finishSection(section, parent) {
if (!section || !parent) {
throw new Error('Invalid finishSection call\n' +
JSON.stringify(section) + '\n' +
JSON.stringify(parent));
throw new Error(`Invalid finishSection call
${JSON.stringify(section)}
${JSON.stringify(parent)}`);
}

if (!section.type) {
Expand Down Expand Up @@ -488,11 +488,11 @@ function finishSection(section, parent) {

var plur;
if (section.type.slice(-1) === 's') {
plur = section.type + 'es';
plur = `${section.type}es`;
} else if (section.type.slice(-1) === 'y') {
plur = section.type.replace(/y$/, 'ies');
} else {
plur = section.type + 's';
plur = `${section.type}s`;
}

// if the parent's type is 'misc', then it's just a random
Expand Down