From 82f8e06ff683ebcac305ac14cd40321f358e304f Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 5 Nov 2021 21:34:37 +0200 Subject: [PATCH] chore: lint using putout --- bin/extract_vtfeatures.js | 6 +++--- bin/publish.js | 8 ++++---- bin/test_api.js | 4 ++-- src/browser/input/MoveToCell.ts | 6 +++--- src/browser/renderer/BaseRenderLayer.ts | 7 +------ src/browser/services/SelectionService.ts | 4 ++-- src/common/input/Keyboard.ts | 2 +- src/common/input/UnicodeV6.test.ts | 2 +- src/common/parser/Params.ts | 5 +++-- test/api/TestUtils.ts | 6 +++--- 10 files changed, 23 insertions(+), 27 deletions(-) diff --git a/bin/extract_vtfeatures.js b/bin/extract_vtfeatures.js index 62ad9ff9..9b5ab898 100644 --- a/bin/extract_vtfeatures.js +++ b/bin/extract_vtfeatures.js @@ -11,13 +11,13 @@ const Mustache = require('mustache'); * regexp to fetch all comments * Fetches all multiline comments and single lines containing '// @vt:'. */ -const REX_COMMENTS = /^\s*?[/][*][*]([\s\S]*?)[*][/]|^\s*?\/\/ ([@]vt[:].*?)$/mug; +const REX_COMMENTS = /^\s*?\/\*\*([\S\s]*?)\*\/|^\s*?\/\/ (@vt:.*?)$/mug; /** * regexp to parse the @vt line * expected data - "@vt: "" "" "" */ -const REX_VT_LINE = /^[@]vt\:\s*(\w+|#\w+|#\w+\[.*?\])\s*(\w+)\s*(\w+)\s*"(.*?)"\s*"(.*?)"\s*"(.*?)".*$/; +const REX_VT_LINE = /^@vt:\s*(\w+|#\w+|#\w+\[.*?\])\s*(\w+)\s*(\w+)\s*"(.*?)"\s*"(.*?)"\s*"(.*?)".*$/; // known vt command types const TYPES = [ @@ -362,7 +362,7 @@ function* parseMultiLineGen(filename, s) { if (!s.includes('@vt:')) { return; } - const lines = s.split('\n').map(el => el.trim().replace(/[*]/, '').replace(/\s/, '')); + const lines = s.split('\n').map(el => el.trim().replace(/\*/, '').replace(/\s/, '')); let grabLine = false; let longDescription = []; let feature = undefined; diff --git a/bin/publish.js b/bin/publish.js index 3c729f6c..75de4b68 100644 --- a/bin/publish.js +++ b/bin/publish.js @@ -92,7 +92,7 @@ function checkAndPublishPackage(packageDir) { } function getNextBetaVersion(packageJson) { - if (!/^[0-9]+\.[0-9]+\.[0-9]+$/.exec(packageJson.version)) { + if (!/^\d+\.\d+\.\d+$/.exec(packageJson.version)) { console.error('The package.json version must be of the form x.y.z'); process.exit(1); } @@ -104,11 +104,11 @@ function getNextBetaVersion(packageJson) { return `${nextStableVersion}-${tag}.1`; } const latestPublishedVersion = publishedVersions.sort((a, b) => { - const aVersion = parseInt(a.substr(a.search(/[0-9]+$/))); - const bVersion = parseInt(b.substr(b.search(/[0-9]+$/))); + const aVersion = parseInt(a.substr(a.search(/\d+$/))); + const bVersion = parseInt(b.substr(b.search(/\d+$/))); return aVersion > bVersion ? -1 : 1; })[0]; - const latestTagVersion = parseInt(latestPublishedVersion.substr(latestPublishedVersion.search(/[0-9]+$/)), 10); + const latestTagVersion = parseInt(latestPublishedVersion.substr(latestPublishedVersion.search(/\d+$/)), 10); return `${nextStableVersion}-${tag}.${latestTagVersion + 1}`; } diff --git a/bin/test_api.js b/bin/test_api.js index f173b417..ff166727 100644 --- a/bin/test_api.js +++ b/bin/test_api.js @@ -21,7 +21,7 @@ let flagArgs = []; if (process.argv.length > 2) { const args = process.argv.slice(2); - flagArgs = args.filter(e => e.startsWith('--')).map(arg => arg.split('=')).reduce((arr, val) => arr.concat([...val], [])); + flagArgs = args.filter(e => e.startsWith('--')).map(arg => arg.split('=')).reduce((arr, val) => arr.concat(val.slice(), [])); console.info(flagArgs); // ability to inject particular test files via // yarn test [testFileA testFileB ...] @@ -44,7 +44,7 @@ const server = cp.spawn('node', ['demo/start'], { server.stdout.on('data', (data) => { // await for the server to fully start - if (data.indexOf("successfully") !== -1) { + if (data.includes("successfully")) { const run = cp.spawnSync( npmBinScript('mocha'), [...testFiles, ...flagArgs], { diff --git a/src/browser/input/MoveToCell.ts b/src/browser/input/MoveToCell.ts index 25e1844d..82e767cd 100644 --- a/src/browser/input/MoveToCell.ts +++ b/src/browser/input/MoveToCell.ts @@ -121,7 +121,7 @@ function wrappedRowsCount(startY: number, targetY: number, bufferService: IBuffe for (let i = 0; i < Math.abs(startRow - endRow); i++) { const direction = verticalDirection(startY, targetY) === Direction.UP ? -1 : 1; const line = bufferService.buffer.lines.get(startRow + (direction * i)); - if (line && line.isWrapped) { + if (line?.isWrapped) { wrappedRows++; } } @@ -136,12 +136,12 @@ function wrappedRowsCount(startY: number, targetY: number, bufferService: IBuffe function wrappedRowsForRow(bufferService: IBufferService, currentRow: number): number { let rowCount = 0; let line = bufferService.buffer.lines.get(currentRow); - let lineWraps = line && line.isWrapped; + let lineWraps = line?.isWrapped; while (lineWraps && currentRow >= 0 && currentRow < bufferService.rows) { rowCount++; line = bufferService.buffer.lines.get(--currentRow); - lineWraps = line && line.isWrapped; + lineWraps = line?.isWrapped; } return rowCount; diff --git a/src/browser/renderer/BaseRenderLayer.ts b/src/browser/renderer/BaseRenderLayer.ts index 40b6e3f9..343ebfe2 100644 --- a/src/browser/renderer/BaseRenderLayer.ts +++ b/src/browser/renderer/BaseRenderLayer.ts @@ -325,12 +325,7 @@ export abstract class BaseRenderLayer implements IRenderLayer { this._currentGlyphIdentifier.bold = !!cell.isBold(); this._currentGlyphIdentifier.dim = !!cell.isDim(); this._currentGlyphIdentifier.italic = !!cell.isItalic(); - const atlasDidDraw = this._charAtlas && this._charAtlas.draw( - this._ctx, - this._currentGlyphIdentifier, - x * this._scaledCellWidth + this._scaledCharLeft, - y * this._scaledCellHeight + this._scaledCharTop - ); + const atlasDidDraw = this._charAtlas?.draw(this._ctx, this._currentGlyphIdentifier, x * this._scaledCellWidth + this._scaledCharLeft, y * this._scaledCellHeight + this._scaledCharTop); if (!atlasDidDraw) { this._drawUncachedChars(cell, x, y); diff --git a/src/browser/services/SelectionService.ts b/src/browser/services/SelectionService.ts index c0547755..fce53ecd 100644 --- a/src/browser/services/SelectionService.ts +++ b/src/browser/services/SelectionService.ts @@ -220,7 +220,7 @@ export class SelectionService extends Disposable implements ISelectionService { for (let i = start[1] + 1; i <= end[1] - 1; i++) { const bufferLine = buffer.lines.get(i); const lineText = buffer.translateBufferLineToString(i, true); - if (bufferLine && bufferLine.isWrapped) { + if (bufferLine?.isWrapped) { result[result.length - 1] += lineText; } else { result.push(lineText); @@ -924,7 +924,7 @@ export class SelectionService extends Disposable implements ISelectionService { if (followWrappedLinesBelow) { if (start + length === this._bufferService.cols && bufferLine.getCodePoint(this._bufferService.cols - 1) !== 32 /* ' ' */) { const nextBufferLine = buffer.lines.get(coords[1] + 1); - if (nextBufferLine && nextBufferLine.isWrapped && nextBufferLine.getCodePoint(0) !== 32 /* ' ' */) { + if (nextBufferLine?.isWrapped && nextBufferLine.getCodePoint(0) !== 32 /* ' ' */) { const nextLineWordPosition = this._getWordAt([0, coords[1] + 1], false, false, true); if (nextLineWordPosition) { length += nextLineWordPosition.length; diff --git a/src/common/input/Keyboard.ts b/src/common/input/Keyboard.ts index 20a28f61..b4b3dce4 100644 --- a/src/common/input/Keyboard.ts +++ b/src/common/input/Keyboard.ts @@ -349,7 +349,7 @@ export function evaluateKeyboardEvent( } else if ((!isMac || macOptionIsMeta) && ev.altKey && !ev.metaKey) { // On macOS this is a third level shift when !macOptionIsMeta. Use instead. const keyMapping = KEYCODE_KEY_MAPPINGS[ev.keyCode]; - const key = keyMapping && keyMapping[!ev.shiftKey ? 0 : 1]; + const key = keyMapping?.[!ev.shiftKey ? 0 : 1]; if (key) { result.key = C0.ESC + key; } else if (ev.keyCode >= 65 && ev.keyCode <= 90) { diff --git a/src/common/input/UnicodeV6.test.ts b/src/common/input/UnicodeV6.test.ts index 9a7fe805..9f89048c 100644 --- a/src/common/input/UnicodeV6.test.ts +++ b/src/common/input/UnicodeV6.test.ts @@ -162,7 +162,7 @@ it('wcwidth should match all values from the old implementation', function(): vo // we are only interested in 2 LSBs, cut off higher bits // ==> n = n & 3 e.g. 000000000000000000000000000000XX return (num: number): number => { - num = num | 0; // get asm.js like optimization under V8 + num |= 0; // get asm.js like optimization under V8 if (num < 32) { return control | 0; } diff --git a/src/common/parser/Params.ts b/src/common/parser/Params.ts index 47ee129d..ce315cf5 100644 --- a/src/common/parser/Params.ts +++ b/src/common/parser/Params.ts @@ -9,6 +9,7 @@ const MAX_VALUE = 0x7FFFFFFF; // max allowed subparams for a single sequence (hardcoded limitation) const MAX_SUBPARAMS = 256; + /** * Params storage class. * This type is used by the parser to accumulate sequence parameters and sub parameters @@ -52,9 +53,9 @@ export class Params implements IParams { return params; } // skip leading sub params - for (let i = (values[0] instanceof Array) ? 1 : 0; i < values.length; ++i) { + for (let i = (Array.isArray(values[0])) ? 1 : 0; i < values.length; ++i) { const value = values[i]; - if (value instanceof Array) { + if (Array.isArray(value)) { for (let k = 0; k < value.length; ++k) { params.addSubParam(value[k]); } diff --git a/test/api/TestUtils.ts b/test/api/TestUtils.ts index 4fa98d43..2acc4d09 100644 --- a/test/api/TestUtils.ts +++ b/test/api/TestUtils.ts @@ -71,11 +71,11 @@ export function getBrowserType(): playwright.BrowserType = { - headless: process.argv.includes('--headless'), - } + headless: process.argv.includes('--headless') + }; const index = process.argv.indexOf('--executablePath'); - if(index > 0 && process.argv.length > index + 1 && typeof process.argv[index + 1] === 'string') { + if (index > 0 && process.argv.length > index + 1 && typeof process.argv[index + 1] === 'string') { options.executablePath = process.argv[index + 1]; }