From a8213b5e2ab1cfaed2a14014f41d0dcd2dceed12 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 22 Jun 2021 09:17:01 +0200 Subject: [PATCH] Refactor code-style --- index.js | 43 +++++++++++++++++++++---------------------- package.json | 14 ++++++-------- test.js | 2 +- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/index.js b/index.js index 2100909..b7e3278 100644 --- a/index.js +++ b/index.js @@ -19,39 +19,37 @@ import repeat from 'repeat-string' * @returns {string} */ export function markdownTable(table, options) { - var settings = options || {} - var align = (settings.align || []).concat() - var stringLength = settings.stringLength || defaultStringLength + const settings = options || {} + const align = (settings.align || []).concat() + const stringLength = settings.stringLength || defaultStringLength /** @type {number[]} Character codes as symbols for alignment per column. */ - var alignments = [] - var rowIndex = -1 + const alignments = [] + let rowIndex = -1 /** @type {string[][]} Cells per row. */ - var cellMatrix = [] + const cellMatrix = [] /** @type {number[][]} Sizes of each cell per row. */ - var sizeMatrix = [] + const sizeMatrix = [] /** @type {number[]} */ - var longestCellByColumn = [] - var mostCellsPerRow = 0 + const longestCellByColumn = [] + let mostCellsPerRow = 0 /** @type {number} */ - var columnIndex + let columnIndex /** @type {string[]} Cells of current row */ - var row + let row /** @type {number[]} Sizes of current row */ - var sizes + let sizes /** @type {number} Sizes of current cell */ - var size + let size /** @type {string} Current cell */ - var cell - /** @type {string[]} */ - var lines + let cell /** @type {string[]} Chunks of current line. */ - var line + let line /** @type {string} */ - var before + let before /** @type {string} */ - var after + let after /** @type {number} */ - var code + let code // This is a superfluous loop if we don’t align delimiters, but otherwise we’d // do superfluous work when aligning, so optimize for aligning. @@ -149,7 +147,8 @@ export function markdownTable(table, options) { sizeMatrix.splice(1, 0, sizes) rowIndex = -1 - lines = [] + /** @type {string[]} */ + const lines = [] while (++rowIndex < cellMatrix.length) { row = cellMatrix[rowIndex] @@ -248,7 +247,7 @@ function defaultStringLength(value) { * @returns {number} */ function toAlignment(value) { - var code = typeof value === 'string' ? value.charCodeAt(0) : 0 + const code = typeof value === 'string' ? value.charCodeAt(0) : 0 return code === 67 /* `C` */ || code === 99 /* `c` */ ? 99 /* `c` */ diff --git a/package.json b/package.json index 159be99..8d7d304 100644 --- a/package.json +++ b/package.json @@ -55,11 +55,6 @@ "test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js", "test": "npm run build && npm run format && npm run test-coverage" }, - "remarkConfig": { - "plugins": [ - "preset-wooorm" - ] - }, "prettier": { "tabWidth": 2, "useTabs": false, @@ -72,11 +67,14 @@ "prettier": true, "rules": { "complexity": "off", - "unicorn/prefer-switch": "off", - "no-var": "off", - "prefer-arrow-callback": "off" + "unicorn/prefer-switch": "off" } }, + "remarkConfig": { + "plugins": [ + "preset-wooorm" + ] + }, "typeCoverage": { "atLeast": 100, "detail": true, diff --git a/test.js b/test.js index 4a41885..89cfc91 100644 --- a/test.js +++ b/test.js @@ -3,7 +3,7 @@ import chalk from 'chalk' import strip from 'strip-ansi' import {markdownTable} from './index.js' -test('markdownTable()', function (t) { +test('markdownTable()', (t) => { t.equal( markdownTable([ ['Branch', 'Commit'],