From ca5f40f09e856ba09105a1e6918ac8d7a17735b3 Mon Sep 17 00:00:00 2001 From: Antoine du HAMEL Date: Sat, 16 May 2020 14:01:21 +0200 Subject: [PATCH 1/2] doc: lint deprecation codes Add a rule to make sure deprecation codes are in order. --- doc/api/deprecations.md | 5 +- test/doctool/test-deprecation-codes.js | 25 ++++++ tools/doc/deprecationCodes.js | 105 +++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 test/doctool/test-deprecation-codes.js create mode 100644 tools/doc/deprecationCodes.js diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 79060f1db76db8..e56ad042ddf999 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -1129,7 +1129,7 @@ Type: Documentation-only The [`util.isNumber()`][] API is deprecated. -### DEP0053 `util.isObject()` +### DEP0053: `util.isObject()` + + ### DEP0089: `require('assert')` $/; + +const generateDeprecationCode = (codeAsNumber) => + `DEP${codeAsNumber.toString().padStart(4, '0')}`; + +const addMarkdownPathToErrorStack = (error, node) => { + const { line, column } = node.position.start; + const [header, ...lines] = error.stack.split('\n'); + error.stack = + header + + `\n at (${source}:${line}:${column})\n` + + lines.join('\n'); + return error; +}; + +const testAnchor = (anchorNode, expectedDeprecationCode) => { + try { + assert.strictEqual( + anchorNode?.children[0]?.value, + ``, + `Missing or ill-formed anchor for ${expectedDeprecationCode}.` + ); + } catch (e) { + throw addMarkdownPathToErrorStack(e, anchorNode); + } +}; + +const testHeading = (headingNode, expectedDeprecationCode) => { + try { + assert.strictEqual( + headingNode?.children[0]?.value.substring(0, 9), + `${expectedDeprecationCode}: `, + 'Ill-formed or out-of-order deprecation code.' + ); + } catch (e) { + throw addMarkdownPathToErrorStack(e, headingNode); + } +}; + +const testYAMLComment = (commentNode) => { + try { + assert.strictEqual( + commentNode?.value?.substring(0, 19), + '