Skip to content

Commit

Permalink
tools: relax max-len lint rule for template strings
Browse files Browse the repository at this point in the history
Splitting template strings across multiple lines can make them harder to
read.

PR-URL: #38097
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott authored and targos committed Sep 4, 2021
1 parent f2e1c22 commit d86d37b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 32 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -163,6 +163,7 @@ module.exports = {
code: 80,
ignorePattern: '^// Flags:',
ignoreRegExpLiterals: true,
ignoreTemplateLiterals: true,
ignoreUrls: true,
tabWidth: 2,
}],
Expand Down
9 changes: 5 additions & 4 deletions lib/internal/util/inspect.js
Expand Up @@ -1537,8 +1537,9 @@ function formatMap(value, ctx, ignored, recurseTimes) {
const output = [];
ctx.indentationLvl += 2;
for (const { 0: k, 1: v } of value) {
output.push(`${formatValue(ctx, k, recurseTimes)} => ` +
formatValue(ctx, v, recurseTimes));
output.push(
`${formatValue(ctx, k, recurseTimes)} => ${formatValue(ctx, v, recurseTimes)}`
);
}
ctx.indentationLvl -= 2;
return output;
Expand Down Expand Up @@ -1578,8 +1579,8 @@ function formatMapIterInner(ctx, recurseTimes, entries, state) {
if (state === kWeak) {
for (; i < maxLength; i++) {
const pos = i * 2;
output[i] = `${formatValue(ctx, entries[pos], recurseTimes)}` +
` => ${formatValue(ctx, entries[pos + 1], recurseTimes)}`;
output[i] =
`${formatValue(ctx, entries[pos], recurseTimes)} => ${formatValue(ctx, entries[pos + 1], recurseTimes)}`;
}
// Sort all entries to have a halfway reliable output (if more entries than
// retrieved ones exist, we can not reliably return the same output) if the
Expand Down
4 changes: 2 additions & 2 deletions tools/doc/apilinks.mjs
Expand Up @@ -61,8 +61,8 @@ inputs.forEach((file) => {
const program = ast.body;

// Build link
const link = `https://github.com/${repo}/blob/${tag}/` +
path.relative('.', file).replace(/\\/g, '/');
const link =
`https://github.com/${repo}/blob/${tag}/${path.relative('.', file).replace(/\\/g, '/')}`;

// Scan for exports.
const exported = { constructors: [], identifiers: [] };
Expand Down
7 changes: 3 additions & 4 deletions tools/doc/checkLinks.mjs
Expand Up @@ -65,10 +65,9 @@ function checkFile(path) {
if (previousDefinitionLabel &&
previousDefinitionLabel > node.label) {
const { line, column } = node.position.start;
console.error((process.env.GITHUB_ACTIONS ?
`::error file=${path},line=${line},col=${column}::` : '') +
`Unordered reference at ${path}:${line}:${column} (` +
`"${node.label}" should be before "${previousDefinitionLabel}")`
console.error(
(process.env.GITHUB_ACTIONS ? `::error file=${path},line=${line},col=${column}::` : '') +
`Unordered reference at ${path}:${line}:${column} ("${node.label}" should be before "${previousDefinitionLabel}")`
);
process.exitCode = 1;
}
Expand Down
28 changes: 10 additions & 18 deletions tools/doc/html.mjs
Expand Up @@ -167,12 +167,10 @@ function linkManPages(text) {
const displayAs = `<code>${name}(${number}${optionalCharacter})</code>`;

if (BSD_ONLY_SYSCALLS.has(name)) {
return `${beginning}<a href="https://www.freebsd.org/cgi/man.cgi` +
`?query=${name}&sektion=${number}">${displayAs}</a>`;
return `${beginning}<a href="https://www.freebsd.org/cgi/man.cgi?query=${name}&sektion=${number}">${displayAs}</a>`;
}

return `${beginning}<a href="http://man7.org/linux/man-pages/man${number}` +
`/${name}.${number}${optionalCharacter}.html">${displayAs}</a>`;
return `${beginning}<a href="http://man7.org/linux/man-pages/man${number}/${name}.${number}${optionalCharacter}.html">${displayAs}</a>`;
});
}

Expand Down Expand Up @@ -210,17 +208,14 @@ export function preprocessElements({ filename }) {
} else if (node.type === 'code') {
if (!node.lang) {
console.warn(
`No language set in ${filename}, ` +
`line ${node.position.start.line}`);
`No language set in ${filename}, line ${node.position.start.line}`
);
}
const className = isJSFlavorSnippet(node) ?
`language-js ${node.lang}` :
`language-${node.lang}`;
const highlighted =
`<code class='${className}'>` +
(getLanguage(node.lang || '') ?
highlight(node.value, { language: node.lang }) : node).value +
'</code>';
`<code class='${className}'>${(getLanguage(node.lang || '') ? highlight(node.value, { language: node.lang }) : node).value}</code>`;
node.type = 'html';

if (isJSFlavorSnippet(node)) {
Expand Down Expand Up @@ -354,8 +349,7 @@ function parseYAML(text) {

result += '</table>\n</details>\n';
} else {
result += `${added.description}${deprecated.description}` +
`${removed.description}\n`;
result += `${added.description}${deprecated.description}${removed.description}\n`;
}

if (meta.napiVersion) {
Expand Down Expand Up @@ -418,15 +412,14 @@ export function buildToc({ filename, apilinks }) {
const hasStability = node.stability !== undefined;
toc += ' '.repeat((depth - 1) * 2) +
(hasStability ? `* <span class="stability_${node.stability}">` : '* ') +
`<a href="#${isDeprecationHeading ? node.data.hProperties.id : id}">` +
`${headingText}</a>${hasStability ? '</span>' : ''}\n`;
`<a href="#${isDeprecationHeading ? node.data.hProperties.id : id}">${headingText}</a>${hasStability ? '</span>' : ''}\n`;

let anchor =
`<span><a class="mark" href="#${id}" id="${id}">#</a></span>`;

if (realFilename === 'errors' && headingText.startsWith('ERR_')) {
anchor += `<span><a class="mark" href="#${headingText}" ` +
`id="${headingText}">#</a></span>`;
anchor +=
`<span><a class="mark" href="#${headingText}" id="${headingText}">#</a></span>`;
}

const api = headingText.replace(/^.*:\s+/, '').replace(/\(.*/, '');
Expand Down Expand Up @@ -476,8 +469,7 @@ function altDocs(filename, docCreated, versions) {
`${host}/docs/latest-v${versionNum}/api/${filename}.html`;

const wrapInListItem = (version) =>
`<li><a href="${getHref(version.num)}">${version.num}` +
`${version.lts ? ' <b>LTS</b>' : ''}</a></li>`;
`<li><a href="${getHref(version.num)}">${version.num}${version.lts ? ' <b>LTS</b>' : ''}</a></li>`;

function isDocInVersion(version) {
const [versionMajor, versionMinor] = version.num.split('.').map(Number);
Expand Down
2 changes: 0 additions & 2 deletions tools/doc/json.mjs
Expand Up @@ -455,7 +455,6 @@ const callWithParams = r`\([^)]*\)`;

const maybeExtends = `(?: +extends +${maybeAncestors}${classId})?`;

/* eslint-disable max-len */
const headingExpressions = [
{ type: 'event', re: RegExp(
`${eventPrefix}${maybeBacktick}${maybeQuote}(${notQuotes})${maybeQuote}${maybeBacktick}$`, 'i') },
Expand All @@ -475,7 +474,6 @@ const headingExpressions = [
{ type: 'property', re: RegExp(
`^${maybeClassPropertyPrefix}${maybeBacktick}${ancestors}(${id})${maybeBacktick}$`, 'i') },
];
/* eslint-enable max-len */

function newSection(header, file) {
const text = textJoin(header.children, file);
Expand Down
3 changes: 1 addition & 2 deletions tools/lint-sh.js
Expand Up @@ -138,8 +138,7 @@ async function checkFiles(...files) {
const data = JSON.parse(stdout);
for (const { file, line, column, message } of data) {
console.error(
`::error file=${file},line=${line},col=${column}::` +
`${file}:${line}:${column}: ${message}`
`::error file=${file},line=${line},col=${column}::${file}:${line}:${column}: ${message}`
);
}
}
Expand Down

0 comments on commit d86d37b

Please sign in to comment.