From 98dba3abd2b990d02aabba30535437d2b9105f4b Mon Sep 17 00:00:00 2001 From: Anton Shchekota Date: Sun, 25 Apr 2021 16:28:13 +0300 Subject: [PATCH 1/2] refactor: replace leftPad on native implementation padStart --- src/parsers/javascript.js | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/parsers/javascript.js b/src/parsers/javascript.js index 6e9b6ad82..89313bf42 100644 --- a/src/parsers/javascript.js +++ b/src/parsers/javascript.js @@ -8,22 +8,6 @@ const debuglog = util.debuglog('documentation'); const findTarget = require('../infer/finders').findTarget; const { parseToAst } = require('./parse_to_ast'); -/** - * Left-pad a string so that it can be sorted lexicographically. We sort - * comments to keep them in order. - * @param {string} str the string - * @param {number} width the width to pad to - * @returns {string} a padded string with the correct width - * @private - */ -function leftPad(str, width) { - str = str.toString(); - while (str.length < width) { - str = '0' + str; - } - return str; -} - /** * Receives a module-dep item, * reads the file, parses the JavaScript, and parses the JSDoc. @@ -77,7 +61,8 @@ function _addComment( }*/ = { loc: nodeLoc, file: data.file, - sortKey: data.sortKey + ' ' + leftPad(nodeLoc.start.line, 8) + sortKey: + data.sortKey + ' ' + nodeLoc.start.line.toString().padStart(8, '0') }; if (includeContext) { From 67b07f113322b77447e648aff76af8e5c15a3fb3 Mon Sep 17 00:00:00 2001 From: Anton Shchekota Date: Sat, 1 May 2021 19:52:12 +0300 Subject: [PATCH 2/2] refactor: migrate on new Buffer API --- __tests__/fixture/custom_theme/index.js | 2 +- __tests__/lib/server.js | 14 +++++++------- src/default_theme/index.js | 2 +- src/serve/error_page.js | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/__tests__/fixture/custom_theme/index.js b/__tests__/fixture/custom_theme/index.js index e1f1f1ed0..5bd09e836 100644 --- a/__tests__/fixture/custom_theme/index.js +++ b/__tests__/fixture/custom_theme/index.js @@ -9,7 +9,7 @@ module.exports = function(comments, options, callback) { new File({ base: '/', path: '/index.html', - contents: new Buffer('Hello world') + contents: Buffer.from('Hello world') }) ]); }; diff --git a/__tests__/lib/server.js b/__tests__/lib/server.js index 6b5187d94..50d880fd2 100644 --- a/__tests__/lib/server.js +++ b/__tests__/lib/server.js @@ -7,33 +7,33 @@ const jsFile = new File({ cwd: '/', base: '/test/', path: '/test/file.js', - contents: new Buffer('var test = 123;') + contents: Buffer.from('var test = 123;') }); const coffeeFile = new File({ cwd: '/', base: '/test/', path: '/test/file.coffee', - contents: new Buffer('test = 123') + contents: Buffer.from('test = 123') }); const indexFile = new File({ cwd: '/', base: '/test/', path: '/test/index.html', - contents: new Buffer('') + contents: Buffer.from('') }); -test('server - throws on bad port', function() { - expect(function() { +test('server - throws on bad port', function () { + expect(function () { const server = new Server('${port}'); }).toThrow(); - expect(function() { + expect(function () { const server = new Server(); }).toThrow(); }); -test('server', async function() { +test('server', async function () { const port = await getPort(); const server = new Server(port, true); expect(server).toBeTruthy(); diff --git a/src/default_theme/index.js b/src/default_theme/index.js index c0300d319..fe257b504 100644 --- a/src/default_theme/index.js +++ b/src/default_theme/index.js @@ -115,7 +115,7 @@ module.exports = function (comments, config) { files.concat( new File({ path: 'index.html', - contents: new Buffer( + contents: Buffer.from( pageTemplate({ docs: comments, config diff --git a/src/serve/error_page.js b/src/serve/error_page.js index 9177d885b..5a8f59b5f 100644 --- a/src/serve/error_page.js +++ b/src/serve/error_page.js @@ -33,7 +33,7 @@ function errorPage(error) { } return new File({ path: 'index.html', - contents: new Buffer(template + errorText) + contents: Buffer.from(template + errorText) }); }