From 038608d40105db8447afdf8a1b823eafe98b8a75 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 5 Apr 2021 07:19:42 -0700 Subject: [PATCH] tools: relax max-len lint rule for template strings Splitting template strings across multiple lines can make them harder to read. PR-URL: https://github.com/nodejs/node/pull/38097 Reviewed-By: Antoine du Hamel Reviewed-By: Ruben Bridgewater Reviewed-By: Colin Ihrig Reviewed-By: Darshan Sen Reviewed-By: James M Snell --- .eslintrc.js | 1 + lib/internal/util/inspect.js | 9 +++++---- tools/doc/apilinks.js | 4 ++-- tools/doc/checkLinks.js | 7 +++---- tools/doc/html.js | 28 ++++++++++------------------ tools/doc/json.js | 2 -- tools/lint-sh.js | 3 +-- 7 files changed, 22 insertions(+), 32 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 9579162dcf868c..27dd8aa10c37a1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -141,6 +141,7 @@ module.exports = { code: 80, ignorePattern: '^// Flags:', ignoreRegExpLiterals: true, + ignoreTemplateLiterals: true, ignoreUrls: true, tabWidth: 2, }], diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index a22f1e7a1b6e9b..21699fe2d8e038 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -1551,8 +1551,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; @@ -1593,8 +1594,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 diff --git a/tools/doc/apilinks.js b/tools/doc/apilinks.js index c9ce87ba08ad48..6b80709eb8443c 100644 --- a/tools/doc/apilinks.js +++ b/tools/doc/apilinks.js @@ -62,8 +62,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: [] }; diff --git a/tools/doc/checkLinks.js b/tools/doc/checkLinks.js index cdee7ca600d0c3..21483c5d534477 100644 --- a/tools/doc/checkLinks.js +++ b/tools/doc/checkLinks.js @@ -63,10 +63,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; } diff --git a/tools/doc/html.js b/tools/doc/html.js index 671cb4adf62065..901976a8c915fc 100644 --- a/tools/doc/html.js +++ b/tools/doc/html.js @@ -169,12 +169,10 @@ function linkManPages(text) { const displayAs = `${name}(${number}${optionalCharacter})`; if (BSD_ONLY_SYSCALLS.has(name)) { - return `${beginning}${displayAs}`; + return `${beginning}${displayAs}`; } - return `${beginning}${displayAs}`; + return `${beginning}${displayAs}`; }); } @@ -212,17 +210,14 @@ 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 = - `` + - (getLanguage(node.lang || '') ? - highlight(node.lang, node.value) : node).value + - ''; + `${(getLanguage(node.lang || '') ? highlight(node.lang, node.value) : node).value}`; node.type = 'html'; if (isJSFlavorSnippet(node)) { @@ -356,8 +351,7 @@ function parseYAML(text) { result += '\n\n'; } else { - result += `${added.description}${deprecated.description}` + - `${removed.description}\n`; + result += `${added.description}${deprecated.description}${removed.description}\n`; } if (meta.napiVersion) { @@ -420,15 +414,14 @@ function buildToc({ filename, apilinks }) { const hasStability = node.stability !== undefined; toc += ' '.repeat((depth - 1) * 2) + (hasStability ? `* ` : '* ') + - `` + - `${headingText}${hasStability ? '' : ''}\n`; + `${headingText}${hasStability ? '' : ''}\n`; let anchor = `#`; if (realFilename === 'errors' && headingText.startsWith('ERR_')) { - anchor += `#`; + anchor += + `#`; } const api = headingText.replace(/^.*:\s+/, '').replace(/\(.*/, ''); @@ -478,8 +471,7 @@ function altDocs(filename, docCreated, versions) { `${host}/docs/latest-v${versionNum}/api/${filename}.html`; const wrapInListItem = (version) => - `
  • ${version.num}` + - `${version.lts ? ' LTS' : ''}
  • `; + `
  • ${version.num}${version.lts ? ' LTS' : ''}
  • `; function isDocInVersion(version) { const [versionMajor, versionMinor] = version.num.split('.').map(Number); diff --git a/tools/doc/json.js b/tools/doc/json.js index 5677fd1ce8b664..cf107dc0b132e7 100644 --- a/tools/doc/json.js +++ b/tools/doc/json.js @@ -458,7 +458,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') }, @@ -478,7 +477,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); diff --git a/tools/lint-sh.js b/tools/lint-sh.js index 7b0beaadfe2fb9..42889c16b6af0e 100755 --- a/tools/lint-sh.js +++ b/tools/lint-sh.js @@ -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}` ); } }