From 2ea218f545bad8e5e26d8883925c2e77ded18876 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Sat, 21 Sep 2019 22:22:43 +0300 Subject: [PATCH 01/31] build(package): replace TSLint by ESLint --- .eslintrc.json | 3 +++ .gitignore | 1 + .npmignore | 7 +++++-- package.json | 8 ++++---- tslint.json | 5 ----- 5 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 .eslintrc.json delete mode 100644 tslint.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..3d484842 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "mrmlnc" +} diff --git a/.gitignore b/.gitignore index c748eaf5..76707907 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ npm-debug.log* node_modules/ # Compiled and temporary files +.eslintcache .tmp/ .benchmark/ out/ diff --git a/.npmignore b/.npmignore index e1f08aa4..662e444f 100644 --- a/.npmignore +++ b/.npmignore @@ -4,9 +4,12 @@ .gitignore .vsts tsconfig.json -tslint.json +.eslintrc.json -# Builded files +# Log & Cache files +.eslintcache + +# Build files out/benchmark out/tests out/**/*.js.map diff --git a/package.json b/package.json index c462e44f..338768e2 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,8 @@ "@types/sinon": "^7.0.13", "compute-stdev": "^1.0.0", "easy-table": "^1.1.1", + "eslint": "^6.3.0", + "eslint-config-mrmlnc": "^1.0.0", "execa": "^1.0.0", "fast-glob": "^3.0.2", "glob": "^7.1.4", @@ -43,9 +45,7 @@ "rimraf": "^2.6.3", "sinon": "^7.3.2", "tiny-glob": "^0.2.6", - "tslint": "^5.18.0", - "tslint-config-mrmlnc": "^2.1.0", - "typescript": "^3.5.2" + "typescript": "^3.5.3" }, "dependencies": { "@nodelib/fs.stat": "^2.0.1", @@ -56,7 +56,7 @@ }, "scripts": { "clean": "rimraf out", - "lint": "tslint \"src/**/*.ts\" -p . -t stylish", + "lint": "eslint \"src/**/*.ts\" --cache", "compile": "tsc", "test": "mocha \"out/**/*.spec.js\" -s 0", "smoke": "mocha \"out/**/*.smoke.js\" -s 0", diff --git a/tslint.json b/tslint.json deleted file mode 100644 index a07a9e65..00000000 --- a/tslint.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": [ - "tslint-config-mrmlnc" - ] -} From 72fa5d0b209b2fbc6a7228728850d4b7cd337162 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:03:51 +0300 Subject: [PATCH 02/31] style: fix `ban-types` rule --- src/benchmark/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/benchmark/utils.ts b/src/benchmark/utils.ts index d5073b9d..f6a122ec 100644 --- a/src/benchmark/utils.ts +++ b/src/benchmark/utils.ts @@ -44,8 +44,8 @@ export function getEnvAsInteger(name: string): number | undefined { return env ? parseInt(env, 10) : undefined; } -export function getEnvAsObject(name: string): Object | undefined { +export function getEnvAsObject(name: string): object | undefined { const env = process.env[name]; - return env ? JSON.parse(env) as Object : undefined; + return env ? JSON.parse(env) as object : undefined; } From 9a755f47cf308f32112dbbd25f627ee8ff4d9544 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:08:08 +0300 Subject: [PATCH 03/31] style: fix `explicit-function-return-type` rule --- src/settings.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings.spec.ts b/src/settings.spec.ts index 0323471a..c9dcc838 100644 --- a/src/settings.spec.ts +++ b/src/settings.spec.ts @@ -57,7 +57,7 @@ describe('Settings', () => { }); it('should return the `fs` option with custom method', () => { - const customReaddirSync = () => []; + const customReaddirSync = (): never[] => []; const settings = new Settings({ fs: { readdirSync: customReaddirSync } From ad7afaeaf5efdb93047fce38ad55f8f338649436 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:09:07 +0300 Subject: [PATCH 04/31] style: fix `generic-type-naming` rule --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6602c50a..569be631 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,8 +7,8 @@ import Settings, { Options as OptionsInternal } from './settings'; import { Entry as EntryInternal, EntryItem, FileSystemAdapter as FileSystemAdapterInternal, Pattern as PatternInternal } from './types/index'; import * as utils from './utils/index'; -type EntryObjectModePredicate = { [P in keyof Pick]-?: true }; -type EntryStatsPredicate = { [P in keyof Pick]-?: true }; +type EntryObjectModePredicate = { [TKey in keyof Pick]-?: true }; +type EntryStatsPredicate = { [TKey in keyof Pick]-?: true }; type EntryObjectPredicate = EntryObjectModePredicate | EntryStatsPredicate; function FastGlob(source: PatternInternal | PatternInternal[], options: OptionsInternal & EntryObjectPredicate): Promise; From 5363bd4db38c7df049654783d402b4304c8596ec Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:09:44 +0300 Subject: [PATCH 05/31] style: fix `member-ordering` rule --- src/types/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/index.ts b/src/types/index.ts index cafcffbc..0f990366 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -10,12 +10,12 @@ export type PatternRe = RegExp; export type PatternsGroup = Record; export interface ReaderOptions extends fsWalk.Options { + transform(entry: Entry): EntryItem; deepFilter: DeepFilterFunction; entryFilter: EntryFilterFunction; errorFilter: ErrorFilterFunction; fs: FileSystemAdapter; stats: boolean; - transform(entry: Entry): EntryItem; } export type ErrorFilterFunction = fsWalk.ErrorFilterFunction; From 88367f92dbe3260895f30becd0a2312f36f2418b Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:12:48 +0300 Subject: [PATCH 06/31] style: fix `no-extra-parens` rule --- src/benchmark/utils.ts | 4 ++-- src/tests/smoke/smoke.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/benchmark/utils.ts b/src/benchmark/utils.ts index f6a122ec..b820c886 100644 --- a/src/benchmark/utils.ts +++ b/src/benchmark/utils.ts @@ -3,9 +3,9 @@ import stdev = require('compute-stdev'); import { SuiteMeasures } from './runner'; export function convertHrtimeToMilliseconds(hrtime: [number, number]): number { - const nanoseconds = (hrtime[0] * 1e9) + hrtime[1]; + const nanoseconds = hrtime[0] * 1e9; - return nanoseconds / 1e6; + return (nanoseconds + hrtime[1]) / 1e6; } export function convertBytesToMegaBytes(bytes: number): number { diff --git a/src/tests/smoke/smoke.ts b/src/tests/smoke/smoke.ts index e0b117c0..2f478013 100644 --- a/src/tests/smoke/smoke.ts +++ b/src/tests/smoke/smoke.ts @@ -89,7 +89,8 @@ async function testCaseRunner(test: SmokeTest, func: typeof getFastGlobEntriesSy assert.fail("This test is marked as «correct», but it doesn't have a reason."); } - const assertAction = (test.broken || test.correct) ? assert.notDeepStrictEqual : assert.deepStrictEqual; + const isInvertedTest = test.broken || test.correct; + const assertAction = isInvertedTest ? assert.notDeepStrictEqual : assert.deepStrictEqual; assertAction(actual, expected); } From 57425a0318aa9bd95a21afdec26281ba9ec9502e Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:14:28 +0300 Subject: [PATCH 07/31] style: fix `no-unnecessary-condition` rule --- src/readers/stream.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/readers/stream.ts b/src/readers/stream.ts index f1c91e00..ba631097 100644 --- a/src/readers/stream.ts +++ b/src/readers/stream.ts @@ -57,7 +57,7 @@ export default class ReaderStream extends Reader { private _getStat(filepath: string): Promise { return new Promise((resolve, reject) => { - this._stat(filepath, this._fsStatSettings, (error, stats) => { + this._stat(filepath, this._fsStatSettings, (error: NodeJS.ErrnoException | null, stats) => { error ? reject(error) : resolve(stats); }); }); From 16a9803ef08e20a5cf806c102fd5a834b21b080e Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:16:12 +0300 Subject: [PATCH 08/31] style: fix `no-explicit-any` rule --- src/index.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.spec.ts b/src/index.spec.ts index d9235bc9..c555ffdb 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -7,7 +7,7 @@ import { EntryItem, ErrnoException } from './types/index'; describe('Package', () => { describe('.sync', () => { it('should throw an error when input values can not pass validation', () => { - /* tslint:disable-next-line no-any */ + /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ assert.throws(() => pkg.sync(null as any), /TypeError: Patterns must be a string or an array of strings/); }); @@ -50,7 +50,7 @@ describe('Package', () => { describe('.async', () => { it('should throw an error when input values can not pass validation', async () => { try { - /* tslint:disable-next-line no-any */ + /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ await pkg(null as any); throw new Error('An unexpected error was found.'); } catch (error) { @@ -96,7 +96,7 @@ describe('Package', () => { describe('.stream', () => { it('should throw an error when input values can not pass validation', () => { - /* tslint:disable-next-line no-any */ + /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ assert.throws(() => pkg.stream(null as any), /TypeError: Patterns must be a string or an array of strings/); }); @@ -150,7 +150,7 @@ describe('Package', () => { describe('.generateTasks', () => { it('should throw an error when input values can not pass validation', () => { - /* tslint:disable-next-line no-any */ + /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ assert.throws(() => pkg.generateTasks(null as any), /TypeError: Patterns must be a string or an array of strings/); }); From c5ac139ee85232e30d787c84b19b66be1fda0767 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:16:57 +0300 Subject: [PATCH 09/31] style: fix `prefer-includes` rule --- src/tests/smoke/smoke.ts | 2 +- src/utils/pattern.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/smoke/smoke.ts b/src/tests/smoke/smoke.ts index 2f478013..ddf9096d 100644 --- a/src/tests/smoke/smoke.ts +++ b/src/tests/smoke/smoke.ts @@ -115,7 +115,7 @@ function generateDebugReport(expected: string[], actual: string[]): string | nul } function getTestMarker(items: string[], item: string): DebugCompareTestMarker { - return items.indexOf(item) !== -1 ? '+' : '-'; + return items.includes(item) ? '+' : '-'; } function getNodeGlobEntries(pattern: Pattern, ignore?: Pattern, cwd?: string, opts?: glob.IOptions): string[] { diff --git a/src/utils/pattern.ts b/src/utils/pattern.ts index c22f8cad..c07410c0 100644 --- a/src/utils/pattern.ts +++ b/src/utils/pattern.ts @@ -77,7 +77,7 @@ export function getBaseDirectory(pattern: Pattern): string { } export function hasGlobStar(pattern: Pattern): boolean { - return pattern.indexOf(GLOBSTAR) !== -1; + return pattern.includes(GLOBSTAR); } export function endsWithSlashGlobStar(pattern: Pattern): boolean { From 1ce795295ab73878fe916fed85576e3592e19cda Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:17:59 +0300 Subject: [PATCH 10/31] style: fix `import/order` rule --- src/index.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.spec.ts b/src/index.spec.ts index c555ffdb..71dddb6e 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -1,8 +1,8 @@ import * as assert from 'assert'; -import * as pkg from './index'; import * as tests from './tests/index'; import { EntryItem, ErrnoException } from './types/index'; +import * as pkg from './index'; describe('Package', () => { describe('.sync', () => { From b9e594c8c47e028f15910813cbcf28b44bdb415e Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:18:48 +0300 Subject: [PATCH 11/31] style: fix `no-unused-expressions` rule --- src/readers/stream.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/readers/stream.ts b/src/readers/stream.ts index ba631097..0af303c1 100644 --- a/src/readers/stream.ts +++ b/src/readers/stream.ts @@ -58,7 +58,7 @@ export default class ReaderStream extends Reader { private _getStat(filepath: string): Promise { return new Promise((resolve, reject) => { this._stat(filepath, this._fsStatSettings, (error: NodeJS.ErrnoException | null, stats) => { - error ? reject(error) : resolve(stats); + return error ? reject(error) : resolve(stats); }); }); } From 97bd53cce9b7b56219752513e8a139467da493f3 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:19:42 +0300 Subject: [PATCH 12/31] style: fix `no-useless-escape` rule --- src/utils/pattern.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/pattern.ts b/src/utils/pattern.ts index c07410c0..d1c1c231 100644 --- a/src/utils/pattern.ts +++ b/src/utils/pattern.ts @@ -125,7 +125,7 @@ export function convertPatternsToRe(patterns: Pattern[], options: MicromatchOpti } export function matchAny(entry: string, patternsRe: PatternRe[]): boolean { - const filepath = entry.replace(/^\.[\\\/]/, ''); + const filepath = entry.replace(/^\.[\\/]/, ''); return patternsRe.some((patternRe) => patternRe.test(filepath)); } From 5bb3e0d23086bff0ea33997d2ad4181370fc39b0 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:20:37 +0300 Subject: [PATCH 13/31] style: fix `custom-error-definition` rule --- src/tests/utils/errno.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/utils/errno.ts b/src/tests/utils/errno.ts index 14df3317..c9f083fc 100644 --- a/src/tests/utils/errno.ts +++ b/src/tests/utils/errno.ts @@ -3,6 +3,7 @@ import { ErrnoException } from '../../types'; class SystemError extends Error implements ErrnoException { constructor(public readonly code: string, message: string) { super(`${code}: ${message}`); + this.name = 'SystemError'; } } From 5855ce1994bb1b05a97967a43591bdf25ca7e42f Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:21:16 +0300 Subject: [PATCH 14/31] style: fix `padding-line-between-statements` rule --- src/settings.ts | 1 + src/tests/smoke/smoke.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/settings.ts b/src/settings.ts index afdf9516..9ee192d6 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -179,6 +179,7 @@ export default class Settings { if (this.onlyDirectories) { this.onlyFiles = false; } + if (this.stats) { this.objectMode = true; } diff --git a/src/tests/smoke/smoke.ts b/src/tests/smoke/smoke.ts index ddf9096d..21d29002 100644 --- a/src/tests/smoke/smoke.ts +++ b/src/tests/smoke/smoke.ts @@ -57,9 +57,11 @@ function getTestCaseTitle(test: SmokeTest): string { if (test.ignore) { title += `, ignore: '${test.ignore}'`; } + if (test.broken) { title += ` (broken - ${test.issue})`; } + if (test.correct) { title += ' (correct)'; } From 2aa6fe0ee6875aaa59474be88374ef5fe14b2a47 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:28:15 +0300 Subject: [PATCH 15/31] style: fix `unicorn/prefer-spread` rule --- src/benchmark/suites/product/stream/fast-glob.ts | 2 +- src/benchmark/suites/regression/stream/fast-glob-current.ts | 2 +- src/benchmark/suites/regression/stream/fast-glob-previous.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/benchmark/suites/product/stream/fast-glob.ts b/src/benchmark/suites/product/stream/fast-glob.ts index a436a851..75519593 100644 --- a/src/benchmark/suites/product/stream/fast-glob.ts +++ b/src/benchmark/suites/product/stream/fast-glob.ts @@ -20,7 +20,7 @@ stream.on('data', (entry: string) => entries.push(entry)); stream.once('end', () => { const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.getMeasures(Array.from(entries).length, time, memory); + const measures = utils.getMeasures([...entries].length, time, memory); console.info(measures); }); diff --git a/src/benchmark/suites/regression/stream/fast-glob-current.ts b/src/benchmark/suites/regression/stream/fast-glob-current.ts index 1771279e..427a7d74 100644 --- a/src/benchmark/suites/regression/stream/fast-glob-current.ts +++ b/src/benchmark/suites/regression/stream/fast-glob-current.ts @@ -20,7 +20,7 @@ stream.on('data', (entry: string) => entries.push(entry)); stream.once('end', () => { const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.getMeasures(Array.from(entries).length, time, memory); + const measures = utils.getMeasures([...entries].length, time, memory); console.info(measures); }); diff --git a/src/benchmark/suites/regression/stream/fast-glob-previous.ts b/src/benchmark/suites/regression/stream/fast-glob-previous.ts index 3d94d481..8e2212d9 100644 --- a/src/benchmark/suites/regression/stream/fast-glob-previous.ts +++ b/src/benchmark/suites/regression/stream/fast-glob-previous.ts @@ -21,7 +21,7 @@ stream.on('data', (entry: string) => entries.push(entry)); stream.once('end', () => { const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.getMeasures(Array.from(entries).length, time, memory); + const measures = utils.getMeasures([...entries].length, time, memory); console.info(measures); }); From 5540cfec52dfdd7908c06a0e3a4784155e12f182 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:28:50 +0300 Subject: [PATCH 16/31] style: fix `import/first` rule --- src/benchmark/index.ts | 4 ++-- src/benchmark/runner.ts | 4 ++-- src/benchmark/suites/product/async/node-glob.ts | 4 ++-- src/benchmark/suites/product/async/tiny-glob.ts | 4 ++-- src/benchmark/suites/product/sync/node-glob.ts | 4 ++-- src/benchmark/suites/regression/async/fast-glob-previous.ts | 4 ++-- .../suites/regression/stream/fast-glob-previous.ts | 4 ++-- src/benchmark/suites/regression/sync/fast-glob-previous.ts | 4 ++-- src/benchmark/utils.ts | 4 ++-- src/tests/smoke/smoke.ts | 6 +++--- src/utils/pattern.ts | 4 ++-- 11 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/benchmark/index.ts b/src/benchmark/index.ts index c53cefd2..88a5e211 100644 --- a/src/benchmark/index.ts +++ b/src/benchmark/index.ts @@ -1,9 +1,9 @@ -import minimist = require('minimist'); - import * as logger from './logger'; import Runner, { RunnerOptions } from './runner'; import * as utils from './utils'; +import minimist = require('minimist'); + interface Arguments extends RunnerOptions { basedir: string; } diff --git a/src/benchmark/runner.ts b/src/benchmark/runner.ts index bd648bab..bdf50331 100644 --- a/src/benchmark/runner.ts +++ b/src/benchmark/runner.ts @@ -1,12 +1,12 @@ import * as fs from 'fs'; import * as path from 'path'; -import execa = require('execa'); - import { Options } from '../settings'; import Reporter from './reporter'; import * as utils from './utils'; +import execa = require('execa'); + export interface RunnerOptions { type: string; mode: string; diff --git a/src/benchmark/suites/product/async/node-glob.ts b/src/benchmark/suites/product/async/node-glob.ts index 491cab7c..6dd5475b 100644 --- a/src/benchmark/suites/product/async/node-glob.ts +++ b/src/benchmark/suites/product/async/node-glob.ts @@ -1,9 +1,9 @@ import * as path from 'path'; -import glob = require('glob'); - import * as utils from '../../../utils'; +import glob = require('glob'); + const options: glob.IOptions = { cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string), nosort: true, diff --git a/src/benchmark/suites/product/async/tiny-glob.ts b/src/benchmark/suites/product/async/tiny-glob.ts index cc7d7b41..3bb65044 100644 --- a/src/benchmark/suites/product/async/tiny-glob.ts +++ b/src/benchmark/suites/product/async/tiny-glob.ts @@ -1,9 +1,9 @@ import * as path from 'path'; -import glob = require('tiny-glob'); - import * as utils from '../../../utils'; +import glob = require('tiny-glob'); + const options = { cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string), flush: true diff --git a/src/benchmark/suites/product/sync/node-glob.ts b/src/benchmark/suites/product/sync/node-glob.ts index 7fe208c3..2333a22f 100644 --- a/src/benchmark/suites/product/sync/node-glob.ts +++ b/src/benchmark/suites/product/sync/node-glob.ts @@ -1,9 +1,9 @@ import * as path from 'path'; -import glob = require('glob'); - import * as utils from '../../../utils'; +import glob = require('glob'); + const options: glob.IOptions = { cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string), nosort: true, diff --git a/src/benchmark/suites/regression/async/fast-glob-previous.ts b/src/benchmark/suites/regression/async/fast-glob-previous.ts index 91705d07..30bca401 100644 --- a/src/benchmark/suites/regression/async/fast-glob-previous.ts +++ b/src/benchmark/suites/regression/async/fast-glob-previous.ts @@ -1,9 +1,9 @@ import * as path from 'path'; -import fg = require('fast-glob'); - import * as utils from '../../../utils'; +import fg = require('fast-glob'); + const options: fg.Options = { cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string), unique: false, diff --git a/src/benchmark/suites/regression/stream/fast-glob-previous.ts b/src/benchmark/suites/regression/stream/fast-glob-previous.ts index 8e2212d9..a3de2a42 100644 --- a/src/benchmark/suites/regression/stream/fast-glob-previous.ts +++ b/src/benchmark/suites/regression/stream/fast-glob-previous.ts @@ -1,9 +1,9 @@ import * as path from 'path'; -import fg = require('fast-glob'); - import * as utils from '../../../utils'; +import fg = require('fast-glob'); + const options: fg.Options = { cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string), unique: false, diff --git a/src/benchmark/suites/regression/sync/fast-glob-previous.ts b/src/benchmark/suites/regression/sync/fast-glob-previous.ts index 0189866d..aa589362 100644 --- a/src/benchmark/suites/regression/sync/fast-glob-previous.ts +++ b/src/benchmark/suites/regression/sync/fast-glob-previous.ts @@ -1,9 +1,9 @@ import * as path from 'path'; -import fg = require('fast-glob'); - import * as utils from '../../../utils'; +import fg = require('fast-glob'); + const options: fg.Options = { cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string), unique: false, diff --git a/src/benchmark/utils.ts b/src/benchmark/utils.ts index b820c886..c3c0a834 100644 --- a/src/benchmark/utils.ts +++ b/src/benchmark/utils.ts @@ -1,7 +1,7 @@ -import stdev = require('compute-stdev'); - import { SuiteMeasures } from './runner'; +import stdev = require('compute-stdev'); + export function convertHrtimeToMilliseconds(hrtime: [number, number]): number { const nanoseconds = hrtime[0] * 1e9; diff --git a/src/tests/smoke/smoke.ts b/src/tests/smoke/smoke.ts index 21d29002..653a1c9a 100644 --- a/src/tests/smoke/smoke.ts +++ b/src/tests/smoke/smoke.ts @@ -1,12 +1,12 @@ import * as assert from 'assert'; -import Table = require('easy-table'); -import glob = require('glob'); - import * as fg from '../../index'; import { Options } from '../../settings'; import { Pattern } from '../../types/index'; +import Table = require('easy-table'); +import glob = require('glob'); + export interface SmokeTest { pattern: Pattern; ignore?: Pattern; diff --git a/src/utils/pattern.ts b/src/utils/pattern.ts index d1c1c231..ab01b7a0 100644 --- a/src/utils/pattern.ts +++ b/src/utils/pattern.ts @@ -1,10 +1,10 @@ import * as path from 'path'; +import { MicromatchOptions, Pattern, PatternRe } from '../types/index'; + import globParent = require('glob-parent'); import micromatch = require('micromatch'); -import { MicromatchOptions, Pattern, PatternRe } from '../types/index'; - const GLOBSTAR = '**'; const ESCAPE_SYMBOL = '\\'; From 38aecef04d58154388846f2f9d4fd6142ddd5096 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:34:08 +0300 Subject: [PATCH 17/31] style: fix `require-array-sort-compare` rule --- src/index.spec.ts | 24 +++++++++++++----------- src/tests/smoke/smoke.ts | 8 ++++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/index.spec.ts b/src/index.spec.ts index 71dddb6e..4a4b977c 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -24,7 +24,7 @@ describe('Package', () => { const actual = pkg.sync(['fixtures/**/*.md']); - actual.sort(); + actual.sort((a, b) => a.localeCompare(b)); assert.deepStrictEqual(actual, expected); }); @@ -41,7 +41,7 @@ describe('Package', () => { const actual = pkg.sync(['fixtures/first/**/*.md', 'fixtures/second/**/*.md']); - actual.sort(); + actual.sort((a, b) => a.localeCompare(b)); assert.deepStrictEqual(actual, expected); }); @@ -71,7 +71,7 @@ describe('Package', () => { const actual = await pkg(['fixtures/**/*.md']); - actual.sort(); + actual.sort((a, b) => a.localeCompare(b)); assert.deepStrictEqual(actual, expected); }); @@ -88,7 +88,7 @@ describe('Package', () => { const actual = await pkg(['fixtures/first/**/*.md', 'fixtures/second/**/*.md']); - actual.sort(); + actual.sort((a, b) => a.localeCompare(b)); assert.deepStrictEqual(actual, expected); }); @@ -101,7 +101,7 @@ describe('Package', () => { }); it('should returns entries', (done) => { - const expected: EntryItem[] = [ + const expected: string[] = [ 'fixtures/file.md', 'fixtures/first/file.md', 'fixtures/first/nested/directory/file.md', @@ -111,14 +111,15 @@ describe('Package', () => { 'fixtures/second/nested/file.md' ]; - const actual: EntryItem[] = []; + const actual: string[] = []; const stream = pkg.stream(['fixtures/**/*.md']); - stream.on('data', (entry: EntryItem) => actual.push(entry)); + stream.on('data', (entry: string) => actual.push(entry)); stream.once('error', (error: ErrnoException) => assert.fail(error)); stream.once('end', () => { - actual.sort(); + actual.sort((a, b) => a.localeCompare(b)); + assert.deepStrictEqual(actual, expected); done(); }); @@ -134,14 +135,15 @@ describe('Package', () => { 'fixtures/second/nested/file.md' ]; - const actual: EntryItem[] = []; + const actual: string[] = []; const stream = pkg.stream(['fixtures/first/**/*.md', 'fixtures/second/**/*.md']); - stream.on('data', (entry: EntryItem) => actual.push(entry)); + stream.on('data', (entry: string) => actual.push(entry)); stream.once('error', (error: ErrnoException) => assert.fail(error)); stream.once('end', () => { - actual.sort(); + actual.sort((a, b) => a.localeCompare(b)); + assert.deepStrictEqual(actual, expected); done(); }); diff --git a/src/tests/smoke/smoke.ts b/src/tests/smoke/smoke.ts index 653a1c9a..8e6996f0 100644 --- a/src/tests/smoke/smoke.ts +++ b/src/tests/smoke/smoke.ts @@ -127,16 +127,16 @@ function getNodeGlobEntries(pattern: Pattern, ignore?: Pattern, cwd?: string, op ...opts }; - return glob.sync(pattern, options).sort(); + return glob.sync(pattern, options).sort((a, b) => a.localeCompare(b)); } function getFastGlobEntriesSync(pattern: Pattern, ignore?: Pattern, cwd?: string, opts?: Options): string[] { - return fg.sync(pattern, getFastGlobOptions(ignore, cwd, opts)).sort(); + return fg.sync(pattern, getFastGlobOptions(ignore, cwd, opts)).sort((a, b) => a.localeCompare(b)); } function getFastGlobEntriesAsync(pattern: Pattern, ignore?: Pattern, cwd?: string, opts?: Options): Promise { return fg(pattern, getFastGlobOptions(ignore, cwd, opts)).then((entries) => { - entries.sort(); + entries.sort((a, b) => a.localeCompare(b)); return entries; }); @@ -151,7 +151,7 @@ function getFastGlobEntriesStream(pattern: Pattern, ignore?: Pattern, cwd?: stri stream.on('data', (entry: string) => entries.push(entry)); stream.once('error', reject); stream.once('end', () => { - entries.sort(); + entries.sort((a, b) => a.localeCompare(b)); resolve(entries); }); From e63b0cb4c6e9a56fa4387a4566a0617c432226c4 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:34:51 +0300 Subject: [PATCH 18/31] style: fix `capitalized-comments` rule --- src/index.ts | 1 - src/settings.ts | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 569be631..a6a2aebf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -98,7 +98,6 @@ function assertPatternsInput(source: unknown): void | never { } function isString(source: unknown): source is string { - /* tslint:disable-next-line strict-type-predicates */ return typeof source === 'string'; } diff --git a/src/settings.ts b/src/settings.ts index 9ee192d6..b66738c1 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -14,7 +14,6 @@ export const DEFAULT_FILE_SYSTEM_ADAPTER: FileSystemAdapter = { readdirSync: fs.readdirSync }; -// tslint:disable no-redundant-jsdoc export interface Options { /** * Return the absolute path for entries. @@ -150,7 +149,6 @@ export interface Options { */ unique?: boolean; } -// tslint:enable no-redundant-jsdoc export default class Settings { public readonly absolute: boolean = this._getValue(this._options.absolute, false); From 1858f51a8df81d765b467a2b2e7b24556862a067 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:41:19 +0300 Subject: [PATCH 19/31] style: fix `no-magic-numbers` rule --- src/benchmark/index.ts | 13 +++++++++---- src/benchmark/reporter.ts | 6 ++++-- src/benchmark/utils.spec.ts | 2 +- src/benchmark/utils.ts | 12 ++++++++---- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/benchmark/index.ts b/src/benchmark/index.ts index 88a5e211..3e025f25 100644 --- a/src/benchmark/index.ts +++ b/src/benchmark/index.ts @@ -4,6 +4,11 @@ import * as utils from './utils'; import minimist = require('minimist'); +const PROCESS_FIRST_ARGUMENT_INDEX = 2; +const DEFAULT_BENCHMARK_LAUNCHES = 10; +const DEFAULT_BENCHMARK_MAX_STDEV = 3; +const DEFAULT_BENCHMARK_RETRIES = 5; + interface Arguments extends RunnerOptions { basedir: string; } @@ -13,13 +18,13 @@ const defaultArgv: Arguments = { type: process.env.BENCHMARK_TYPE || 'product', mode: process.env.BENCHMARK_MODE || 'async', pattern: process.env.BENCHMARK_PATTERN || '*', - launches: utils.getEnvAsInteger('BENCHMARK_LAUNCHES') || 10, - maxStdev: utils.getEnvAsInteger('BENCHMARK_MAX_STDEV') || 3, - retries: utils.getEnvAsInteger('BENCHMARK_RETRIES') || 5, + launches: utils.getEnvAsInteger('BENCHMARK_LAUNCHES') || DEFAULT_BENCHMARK_LAUNCHES, + maxStdev: utils.getEnvAsInteger('BENCHMARK_MAX_STDEV') || DEFAULT_BENCHMARK_MAX_STDEV, + retries: utils.getEnvAsInteger('BENCHMARK_RETRIES') || DEFAULT_BENCHMARK_RETRIES, options: utils.getEnvAsObject('BENCHMARK_OPTIONS') || {} }; -const argv = minimist(process.argv.slice(2), { +const argv = minimist(process.argv.slice(PROCESS_FIRST_ARGUMENT_INDEX), { default: defaultArgv }); diff --git a/src/benchmark/reporter.ts b/src/benchmark/reporter.ts index 2fb7a233..30d013d1 100644 --- a/src/benchmark/reporter.ts +++ b/src/benchmark/reporter.ts @@ -1,5 +1,7 @@ import { SuitePackResult } from './runner'; +const FRACTION_DIGITS = 3; + export default class Reporter { constructor(private readonly _results: SuitePackResult) { } @@ -28,8 +30,8 @@ export default class Reporter { return [ '(' + name.toUpperCase() + ')', - this._formatValue(data.average, data.units, 3), - '±' + this._formatValue(data.stdev, '%', 3) + this._formatValue(data.average, data.units, FRACTION_DIGITS), + '±' + this._formatValue(data.stdev, '%', FRACTION_DIGITS) ].join(' '); } diff --git a/src/benchmark/utils.spec.ts b/src/benchmark/utils.spec.ts index 673b8d0b..09064da0 100644 --- a/src/benchmark/utils.spec.ts +++ b/src/benchmark/utils.spec.ts @@ -11,7 +11,7 @@ describe('Benchmark → Utils', () => { process.env.FG_TEST_ENV_OBJECT = '{ "value": true }'; process.hrtime = (() => [0, 1e7]) as NodeJS.HRTime; - process.memoryUsage = () => ({ external: 0, rss: 0, heapTotal: 0, heapUsed: 10 * 1024 * 1024 }); + process.memoryUsage = () => ({ external: 0, rss: 0, heapTotal: 0, heapUsed: 10 * 1e6 }); }); after(() => { diff --git a/src/benchmark/utils.ts b/src/benchmark/utils.ts index c3c0a834..54036796 100644 --- a/src/benchmark/utils.ts +++ b/src/benchmark/utils.ts @@ -2,14 +2,18 @@ import { SuiteMeasures } from './runner'; import stdev = require('compute-stdev'); +const NANOSECONDS_IN_SECOND = 1e9; +const MICROSECONDS_IN_SECOND = 1e6; +const BYTES_IN_MEGABYTE = 1e6; + export function convertHrtimeToMilliseconds(hrtime: [number, number]): number { - const nanoseconds = hrtime[0] * 1e9; + const nanoseconds = hrtime[0] * NANOSECONDS_IN_SECOND; - return (nanoseconds + hrtime[1]) / 1e6; + return (nanoseconds + hrtime[1]) / MICROSECONDS_IN_SECOND; } export function convertBytesToMegaBytes(bytes: number): number { - return bytes / 1e6; + return bytes / MICROSECONDS_IN_SECOND; } export function timeStart(): [number, number] { @@ -23,7 +27,7 @@ export function timeEnd(start: [number, number]): number { } export function getMemory(): number { - return process.memoryUsage().heapUsed / 1024 / 1024; + return process.memoryUsage().heapUsed / BYTES_IN_MEGABYTE; } export function getMeasures(matches: number, time: number, memory: number): string { From c06f89f1e59a2801868b46eb370b93aa3c36dc94 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 30 Sep 2019 22:43:09 +0300 Subject: [PATCH 20/31] style: fix `consistent-type-definitions` rule --- src/benchmark/index.ts | 4 ++-- src/benchmark/runner.ts | 20 ++++++++++---------- src/managers/tasks.ts | 4 ++-- src/settings.ts | 4 ++-- src/tests/smoke/smoke.ts | 4 ++-- src/types/index.ts | 8 ++++---- src/utils/pattern.ts | 4 ++-- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/benchmark/index.ts b/src/benchmark/index.ts index 3e025f25..d0ef0786 100644 --- a/src/benchmark/index.ts +++ b/src/benchmark/index.ts @@ -9,9 +9,9 @@ const DEFAULT_BENCHMARK_LAUNCHES = 10; const DEFAULT_BENCHMARK_MAX_STDEV = 3; const DEFAULT_BENCHMARK_RETRIES = 5; -interface Arguments extends RunnerOptions { +type Arguments = { basedir: string; -} +} & RunnerOptions; const defaultArgv: Arguments = { basedir: '.', diff --git a/src/benchmark/runner.ts b/src/benchmark/runner.ts index bdf50331..d87ed689 100644 --- a/src/benchmark/runner.ts +++ b/src/benchmark/runner.ts @@ -7,7 +7,7 @@ import * as utils from './utils'; import execa = require('execa'); -export interface RunnerOptions { +export type RunnerOptions = { type: string; mode: string; pattern: string; @@ -15,33 +15,33 @@ export interface RunnerOptions { maxStdev: number; retries: number; options: Options; -} +}; -export interface SuiteMeasures { +export type SuiteMeasures = { matches: number; time: number; memory: number; -} +}; -export interface Measure { +export type Measure = { units: string; raw: number[]; average: number; stdev: number; -} +}; -export interface SuitePackMeasures extends Record { +export type SuitePackMeasures = { time: Measure; memory: Measure; -} +} & Record; -export interface SuitePackResult { +export type SuitePackResult = { name: string; errors: number; entries: number; retries: number; measures: SuitePackMeasures; -} +}; export default class Runner { constructor(private readonly _basedir: string, private readonly _options: RunnerOptions) { } diff --git a/src/managers/tasks.ts b/src/managers/tasks.ts index 2b733df3..cac9103b 100644 --- a/src/managers/tasks.ts +++ b/src/managers/tasks.ts @@ -2,13 +2,13 @@ import Settings from '../settings'; import { Pattern, PatternsGroup } from '../types/index'; import * as utils from '../utils/index'; -export interface Task { +export type Task = { base: string; dynamic: boolean; patterns: Pattern[]; positive: Pattern[]; negative: Pattern[]; -} +}; export function generate(patterns: Pattern[], settings: Settings): Task[] { const positivePatterns = getPositivePatterns(patterns); diff --git a/src/settings.ts b/src/settings.ts index b66738c1..1440eb13 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -14,7 +14,7 @@ export const DEFAULT_FILE_SYSTEM_ADAPTER: FileSystemAdapter = { readdirSync: fs.readdirSync }; -export interface Options { +export type Options = { /** * Return the absolute path for entries. * @@ -148,7 +148,7 @@ export interface Options { * @default true */ unique?: boolean; -} +}; export default class Settings { public readonly absolute: boolean = this._getValue(this._options.absolute, false); diff --git a/src/tests/smoke/smoke.ts b/src/tests/smoke/smoke.ts index 8e6996f0..a2f5b775 100644 --- a/src/tests/smoke/smoke.ts +++ b/src/tests/smoke/smoke.ts @@ -7,7 +7,7 @@ import { Pattern } from '../../types/index'; import Table = require('easy-table'); import glob = require('glob'); -export interface SmokeTest { +export type SmokeTest = { pattern: Pattern; ignore?: Pattern; cwd?: string; @@ -27,7 +27,7 @@ export interface SmokeTest { */ correct?: boolean; reason?: string; -} +}; type MochaDefinition = (desc: string, cb: (this: Mocha.Context) => void) => void; type DebugCompareTestMarker = '+' | '-'; diff --git a/src/types/index.ts b/src/types/index.ts index 0f990366..eea108ef 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -9,21 +9,21 @@ export type Pattern = string; export type PatternRe = RegExp; export type PatternsGroup = Record; -export interface ReaderOptions extends fsWalk.Options { +export type ReaderOptions = { transform(entry: Entry): EntryItem; deepFilter: DeepFilterFunction; entryFilter: EntryFilterFunction; errorFilter: ErrorFilterFunction; fs: FileSystemAdapter; stats: boolean; -} +} & fsWalk.Options; export type ErrorFilterFunction = fsWalk.ErrorFilterFunction; export type EntryFilterFunction = fsWalk.EntryFilterFunction; export type DeepFilterFunction = fsWalk.DeepFilterFunction; export type EntryTransformerFunction = (entry: Entry) => EntryItem; -export interface MicromatchOptions { +export type MicromatchOptions = { dot?: boolean; matchBase?: boolean; nobrace?: boolean; @@ -32,6 +32,6 @@ export interface MicromatchOptions { noglobstar?: boolean; posix?: boolean; strictSlashes?: boolean; -} +}; export type FileSystemAdapter = fsWalk.FileSystemAdapter; diff --git a/src/utils/pattern.ts b/src/utils/pattern.ts index ab01b7a0..e66c2ca2 100644 --- a/src/utils/pattern.ts +++ b/src/utils/pattern.ts @@ -14,11 +14,11 @@ const REGEX_GROUP_SYMBOLS_RE = /(?:^|[^@!*?+])\(.*\|.*\)/; const GLOB_EXTENSION_SYMBOLS_RE = /[@!*?+]\(.*\)/; const BRACE_EXPANSIONS_SYMBOLS_RE = /{.*(?:,|\.\.).*}/; -interface PatternTypeOptions { +type PatternTypeOptions = { braceExpansion?: boolean; caseSensitiveMatch?: boolean; extglob?: boolean; -} +}; export function isStaticPattern(pattern: Pattern, options: PatternTypeOptions = {}): boolean { return !isDynamicPattern(pattern, options); From bfc3b674ab636fc745dd861d576b4faf3502dac3 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Tue, 1 Oct 2019 08:55:04 +0300 Subject: [PATCH 21/31] style: fix `no-redeclare` rule --- src/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.ts b/src/index.ts index a6a2aebf..aca3bc63 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,6 +25,8 @@ function FastGlob(source: PatternInternal | PatternInternal[], options?: Options return Promise.all(works).then(utils.array.flatten); } +// https://github.com/typescript-eslint/typescript-eslint/issues/60 +// eslint-disable-next-line no-redeclare namespace FastGlob { export type Options = OptionsInternal; export type Entry = EntryInternal; From cbcabd00071b6b394361cb2c29369f1f8fe666a2 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Tue, 1 Oct 2019 08:58:19 +0300 Subject: [PATCH 22/31] style: fix `unicorn/import-index` rule --- src/benchmark/suites/product/async/fast-glob.ts | 2 +- src/benchmark/suites/product/stream/fast-glob.ts | 2 +- src/benchmark/suites/product/sync/fast-glob.ts | 2 +- src/benchmark/suites/regression/async/fast-glob-current.ts | 2 +- src/benchmark/suites/regression/stream/fast-glob-current.ts | 2 +- src/benchmark/suites/regression/sync/fast-glob-current.ts | 2 +- src/index.spec.ts | 6 +++--- src/index.ts | 4 ++-- src/managers/tasks.spec.ts | 4 ++-- src/managers/tasks.ts | 4 ++-- src/providers/async.spec.ts | 4 ++-- src/providers/async.ts | 2 +- src/providers/filters/deep.spec.ts | 2 +- src/providers/filters/deep.ts | 4 ++-- src/providers/filters/entry.spec.ts | 2 +- src/providers/filters/entry.ts | 4 ++-- src/providers/filters/error.spec.ts | 4 ++-- src/providers/filters/error.ts | 2 +- src/providers/provider.spec.ts | 4 ++-- src/providers/provider.ts | 2 +- src/providers/stream.spec.ts | 4 ++-- src/providers/stream.ts | 2 +- src/providers/sync.spec.ts | 2 +- src/providers/sync.ts | 2 +- src/providers/transformers/entry.spec.ts | 4 ++-- src/providers/transformers/entry.ts | 2 +- src/readers/reader.ts | 4 ++-- src/readers/stream.spec.ts | 2 +- src/readers/stream.ts | 2 +- src/readers/sync.spec.ts | 2 +- src/readers/sync.ts | 2 +- src/settings.ts | 2 +- src/tests/smoke/smoke.ts | 4 ++-- src/tests/utils/task.ts | 2 +- src/utils/errno.spec.ts | 2 +- src/utils/pattern.spec.ts | 2 +- src/utils/pattern.ts | 2 +- 37 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/benchmark/suites/product/async/fast-glob.ts b/src/benchmark/suites/product/async/fast-glob.ts index a1ef0044..76f83109 100644 --- a/src/benchmark/suites/product/async/fast-glob.ts +++ b/src/benchmark/suites/product/async/fast-glob.ts @@ -1,6 +1,6 @@ import * as path from 'path'; -import * as glob from '../../../../index'; +import * as glob from '../../../..'; import * as utils from '../../../utils'; const options: glob.Options = { diff --git a/src/benchmark/suites/product/stream/fast-glob.ts b/src/benchmark/suites/product/stream/fast-glob.ts index 75519593..60356bbf 100644 --- a/src/benchmark/suites/product/stream/fast-glob.ts +++ b/src/benchmark/suites/product/stream/fast-glob.ts @@ -1,6 +1,6 @@ import * as path from 'path'; -import * as glob from '../../../../index'; +import * as glob from '../../../..'; import * as utils from '../../../utils'; const options: glob.Options = { diff --git a/src/benchmark/suites/product/sync/fast-glob.ts b/src/benchmark/suites/product/sync/fast-glob.ts index bdd36f72..11c7cd76 100644 --- a/src/benchmark/suites/product/sync/fast-glob.ts +++ b/src/benchmark/suites/product/sync/fast-glob.ts @@ -1,6 +1,6 @@ import * as path from 'path'; -import * as glob from '../../../../index'; +import * as glob from '../../../..'; import * as utils from '../../../utils'; const options: glob.Options = { diff --git a/src/benchmark/suites/regression/async/fast-glob-current.ts b/src/benchmark/suites/regression/async/fast-glob-current.ts index e5388e84..1b1bfa62 100644 --- a/src/benchmark/suites/regression/async/fast-glob-current.ts +++ b/src/benchmark/suites/regression/async/fast-glob-current.ts @@ -1,6 +1,6 @@ import * as path from 'path'; -import * as glob from '../../../../index'; +import * as glob from '../../../..'; import * as utils from '../../../utils'; const options: glob.Options = { diff --git a/src/benchmark/suites/regression/stream/fast-glob-current.ts b/src/benchmark/suites/regression/stream/fast-glob-current.ts index 427a7d74..21bf5fa6 100644 --- a/src/benchmark/suites/regression/stream/fast-glob-current.ts +++ b/src/benchmark/suites/regression/stream/fast-glob-current.ts @@ -1,6 +1,6 @@ import * as path from 'path'; -import * as glob from '../../../../index'; +import * as glob from '../../../..'; import * as utils from '../../../utils'; const options: glob.Options = { diff --git a/src/benchmark/suites/regression/sync/fast-glob-current.ts b/src/benchmark/suites/regression/sync/fast-glob-current.ts index 0a0060b9..48d56f57 100644 --- a/src/benchmark/suites/regression/sync/fast-glob-current.ts +++ b/src/benchmark/suites/regression/sync/fast-glob-current.ts @@ -1,6 +1,6 @@ import * as path from 'path'; -import * as glob from '../../../../index'; +import * as glob from '../../../..'; import * as utils from '../../../utils'; const options: glob.Options = { diff --git a/src/index.spec.ts b/src/index.spec.ts index 4a4b977c..18a646fb 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -1,8 +1,8 @@ import * as assert from 'assert'; -import * as tests from './tests/index'; -import { EntryItem, ErrnoException } from './types/index'; -import * as pkg from './index'; +import * as tests from './tests'; +import { EntryItem, ErrnoException } from './types'; +import * as pkg from '.'; describe('Package', () => { describe('.sync', () => { diff --git a/src/index.ts b/src/index.ts index aca3bc63..1085b69a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,8 +4,8 @@ import Provider from './providers/provider'; import ProviderStream from './providers/stream'; import ProviderSync from './providers/sync'; import Settings, { Options as OptionsInternal } from './settings'; -import { Entry as EntryInternal, EntryItem, FileSystemAdapter as FileSystemAdapterInternal, Pattern as PatternInternal } from './types/index'; -import * as utils from './utils/index'; +import { Entry as EntryInternal, EntryItem, FileSystemAdapter as FileSystemAdapterInternal, Pattern as PatternInternal } from './types'; +import * as utils from './utils'; type EntryObjectModePredicate = { [TKey in keyof Pick]-?: true }; type EntryStatsPredicate = { [TKey in keyof Pick]-?: true }; diff --git a/src/managers/tasks.spec.ts b/src/managers/tasks.spec.ts index ded56054..99f4b624 100644 --- a/src/managers/tasks.spec.ts +++ b/src/managers/tasks.spec.ts @@ -1,8 +1,8 @@ import * as assert from 'assert'; import Settings from '../settings'; -import * as tests from '../tests/index'; -import { PatternsGroup } from '../types/index'; +import * as tests from '../tests'; +import { PatternsGroup } from '../types'; import * as manager from './tasks'; describe('Managers → Task', () => { diff --git a/src/managers/tasks.ts b/src/managers/tasks.ts index cac9103b..7515cfb4 100644 --- a/src/managers/tasks.ts +++ b/src/managers/tasks.ts @@ -1,6 +1,6 @@ import Settings from '../settings'; -import { Pattern, PatternsGroup } from '../types/index'; -import * as utils from '../utils/index'; +import { Pattern, PatternsGroup } from '../types'; +import * as utils from '../utils'; export type Task = { base: string; diff --git a/src/providers/async.spec.ts b/src/providers/async.spec.ts index 34a398c2..8dc39721 100644 --- a/src/providers/async.spec.ts +++ b/src/providers/async.spec.ts @@ -6,8 +6,8 @@ import * as sinon from 'sinon'; import { Task } from '../managers/tasks'; import ReaderStream from '../readers/stream'; import Settings, { Options } from '../settings'; -import * as tests from '../tests/index'; -import { Entry, EntryItem, ErrnoException } from '../types/index'; +import * as tests from '../tests'; +import { Entry, EntryItem, ErrnoException } from '../types'; import ProviderAsync from './async'; class TestProvider extends ProviderAsync { diff --git a/src/providers/async.ts b/src/providers/async.ts index e15bc8ad..5efc6882 100644 --- a/src/providers/async.ts +++ b/src/providers/async.ts @@ -1,6 +1,6 @@ import { Task } from '../managers/tasks'; import ReaderStream from '../readers/stream'; -import { Entry, EntryItem, ReaderOptions } from '../types/index'; +import { Entry, EntryItem, ReaderOptions } from '../types'; import Provider from './provider'; export default class ProviderAsync extends Provider> { diff --git a/src/providers/filters/deep.spec.ts b/src/providers/filters/deep.spec.ts index b1841535..2f070aca 100644 --- a/src/providers/filters/deep.spec.ts +++ b/src/providers/filters/deep.spec.ts @@ -2,7 +2,7 @@ import * as assert from 'assert'; import Settings, { Options } from '../../settings'; import * as tests from '../../tests'; -import { EntryFilterFunction, Pattern } from '../../types/index'; +import { EntryFilterFunction, Pattern } from '../../types'; import DeepFilter from './deep'; function getDeepFilterInstance(options?: Options): DeepFilter { diff --git a/src/providers/filters/deep.ts b/src/providers/filters/deep.ts index aa24f588..c8f3d4bc 100644 --- a/src/providers/filters/deep.ts +++ b/src/providers/filters/deep.ts @@ -1,6 +1,6 @@ import Settings from '../../settings'; -import { Entry, EntryFilterFunction, MicromatchOptions, Pattern, PatternRe } from '../../types/index'; -import * as utils from '../../utils/index'; +import { Entry, EntryFilterFunction, MicromatchOptions, Pattern, PatternRe } from '../../types'; +import * as utils from '../../utils'; export default class DeepFilter { constructor(private readonly _settings: Settings, private readonly _micromatchOptions: MicromatchOptions) { } diff --git a/src/providers/filters/entry.spec.ts b/src/providers/filters/entry.spec.ts index ab0a8597..85a018d9 100644 --- a/src/providers/filters/entry.spec.ts +++ b/src/providers/filters/entry.spec.ts @@ -2,7 +2,7 @@ import * as assert from 'assert'; import Settings, { Options } from '../../settings'; import * as tests from '../../tests'; -import { EntryFilterFunction, Pattern } from '../../types/index'; +import { EntryFilterFunction, Pattern } from '../../types'; import EntryFilter from './entry'; function getEntryFilterInstance(options?: Options): EntryFilter { diff --git a/src/providers/filters/entry.ts b/src/providers/filters/entry.ts index f412d1c4..9a8a1081 100644 --- a/src/providers/filters/entry.ts +++ b/src/providers/filters/entry.ts @@ -1,6 +1,6 @@ import Settings from '../../settings'; -import { Entry, EntryFilterFunction, MicromatchOptions, Pattern, PatternRe } from '../../types/index'; -import * as utils from '../../utils/index'; +import { Entry, EntryFilterFunction, MicromatchOptions, Pattern, PatternRe } from '../../types'; +import * as utils from '../../utils'; export default class EntryFilter { public readonly index: Map = new Map(); diff --git a/src/providers/filters/error.spec.ts b/src/providers/filters/error.spec.ts index 1fd8829f..67d9b7eb 100644 --- a/src/providers/filters/error.spec.ts +++ b/src/providers/filters/error.spec.ts @@ -1,8 +1,8 @@ import * as assert from 'assert'; import Settings, { Options } from '../../settings'; -import * as tests from '../../tests/index'; -import { ErrorFilterFunction } from '../../types/index'; +import * as tests from '../../tests'; +import { ErrorFilterFunction } from '../../types'; import ErrorFilter from './error'; function getErrorFilterInstance(options?: Options): ErrorFilter { diff --git a/src/providers/filters/error.ts b/src/providers/filters/error.ts index c3516a5f..52b0e812 100644 --- a/src/providers/filters/error.ts +++ b/src/providers/filters/error.ts @@ -1,6 +1,6 @@ import Settings from '../../settings'; import { ErrnoException, ErrorFilterFunction } from '../../types'; -import * as utils from '../../utils/index'; +import * as utils from '../../utils'; export default class ErrorFilter { constructor(private readonly _settings: Settings) { } diff --git a/src/providers/provider.spec.ts b/src/providers/provider.spec.ts index 5f637788..2343bc58 100644 --- a/src/providers/provider.spec.ts +++ b/src/providers/provider.spec.ts @@ -3,8 +3,8 @@ import * as path from 'path'; import { Task } from '../managers/tasks'; import Settings, { Options } from '../settings'; -import * as tests from '../tests/index'; -import { MicromatchOptions, ReaderOptions } from '../types/index'; +import * as tests from '../tests'; +import { MicromatchOptions, ReaderOptions } from '../types'; import Provider from './provider'; export class TestProvider extends Provider> { diff --git a/src/providers/provider.ts b/src/providers/provider.ts index cf3bee55..5e293f0b 100644 --- a/src/providers/provider.ts +++ b/src/providers/provider.ts @@ -2,7 +2,7 @@ import * as path from 'path'; import { Task } from '../managers/tasks'; import Settings from '../settings'; -import { MicromatchOptions, ReaderOptions } from '../types/index'; +import { MicromatchOptions, ReaderOptions } from '../types'; import DeepFilter from './filters/deep'; import EntryFilter from './filters/entry'; import ErrorFilter from './filters/error'; diff --git a/src/providers/stream.spec.ts b/src/providers/stream.spec.ts index 53e3a949..a2d02332 100644 --- a/src/providers/stream.spec.ts +++ b/src/providers/stream.spec.ts @@ -6,8 +6,8 @@ import * as sinon from 'sinon'; import { Task } from '../managers/tasks'; import ReaderStream from '../readers/stream'; import Settings, { Options } from '../settings'; -import * as tests from '../tests/index'; -import { Entry, EntryItem, ErrnoException } from '../types/index'; +import * as tests from '../tests'; +import { Entry, EntryItem, ErrnoException } from '../types'; import ProviderStream from './stream'; class TestProvider extends ProviderStream { diff --git a/src/providers/stream.ts b/src/providers/stream.ts index f7086920..83d18503 100644 --- a/src/providers/stream.ts +++ b/src/providers/stream.ts @@ -2,7 +2,7 @@ import { Readable } from 'stream'; import { Task } from '../managers/tasks'; import ReaderStream from '../readers/stream'; -import { Entry, ErrnoException, ReaderOptions } from '../types/index'; +import { Entry, ErrnoException, ReaderOptions } from '../types'; import Provider from './provider'; export default class ProviderStream extends Provider { diff --git a/src/providers/sync.spec.ts b/src/providers/sync.spec.ts index 37ebeb4e..80a26f1a 100644 --- a/src/providers/sync.spec.ts +++ b/src/providers/sync.spec.ts @@ -4,7 +4,7 @@ import * as sinon from 'sinon'; import ReaderSync from '../readers/sync'; import Settings, { Options } from '../settings'; -import * as tests from '../tests/index'; +import * as tests from '../tests'; import ProviderSync from './sync'; class TestProvider extends ProviderSync { diff --git a/src/providers/sync.ts b/src/providers/sync.ts index a6ef0245..079819d9 100644 --- a/src/providers/sync.ts +++ b/src/providers/sync.ts @@ -1,6 +1,6 @@ import { Task } from '../managers/tasks'; import ReaderSync from '../readers/sync'; -import { Entry, EntryItem, ReaderOptions } from '../types/index'; +import { Entry, EntryItem, ReaderOptions } from '../types'; import Provider from './provider'; export default class ProviderSync extends Provider { diff --git a/src/providers/transformers/entry.spec.ts b/src/providers/transformers/entry.spec.ts index 04fd273d..090fe0ff 100644 --- a/src/providers/transformers/entry.spec.ts +++ b/src/providers/transformers/entry.spec.ts @@ -2,9 +2,9 @@ import * as assert from 'assert'; import * as path from 'path'; import Settings, { Options } from '../../settings'; -import * as tests from '../../tests/index'; +import * as tests from '../../tests'; import { EntryTransformerFunction } from '../../types'; -import * as utils from '../../utils/index'; +import * as utils from '../../utils'; import EntryTransformer from './entry'; function getEntryTransformer(options?: Options): EntryTransformer { diff --git a/src/providers/transformers/entry.ts b/src/providers/transformers/entry.ts index e614342c..54ab5e3a 100644 --- a/src/providers/transformers/entry.ts +++ b/src/providers/transformers/entry.ts @@ -1,6 +1,6 @@ import Settings from '../../settings'; import { Entry, EntryItem, EntryTransformerFunction } from '../../types'; -import * as utils from '../../utils/index'; +import * as utils from '../../utils'; export default class EntryTransformer { constructor(private readonly _settings: Settings) { } diff --git a/src/readers/reader.ts b/src/readers/reader.ts index f8dbc71e..a06be6a5 100644 --- a/src/readers/reader.ts +++ b/src/readers/reader.ts @@ -4,8 +4,8 @@ import * as path from 'path'; import * as fsStat from '@nodelib/fs.stat'; import Settings from '../settings'; -import { Entry, ErrnoException, Pattern, ReaderOptions } from '../types/index'; -import * as utils from '../utils/index'; +import { Entry, ErrnoException, Pattern, ReaderOptions } from '../types'; +import * as utils from '../utils'; export default abstract class Reader { protected readonly _fsStatSettings: fsStat.Settings = new fsStat.Settings({ diff --git a/src/readers/stream.spec.ts b/src/readers/stream.spec.ts index 3204b05b..b254cd56 100644 --- a/src/readers/stream.spec.ts +++ b/src/readers/stream.spec.ts @@ -6,7 +6,7 @@ import * as fsWalk from '@nodelib/fs.walk'; import * as sinon from 'sinon'; import Settings, { Options } from '../settings'; -import * as tests from '../tests/index'; +import * as tests from '../tests'; import { Entry, ErrnoException, ReaderOptions } from '../types'; import ReaderStream from './stream'; diff --git a/src/readers/stream.ts b/src/readers/stream.ts index 0af303c1..00e5e805 100644 --- a/src/readers/stream.ts +++ b/src/readers/stream.ts @@ -4,7 +4,7 @@ import { PassThrough } from 'stream'; import * as fsStat from '@nodelib/fs.stat'; import * as fsWalk from '@nodelib/fs.walk'; -import { Entry, ErrnoException, Pattern, ReaderOptions } from '../types/index'; +import { Entry, ErrnoException, Pattern, ReaderOptions } from '../types'; import Reader from './reader'; export default class ReaderStream extends Reader { diff --git a/src/readers/sync.spec.ts b/src/readers/sync.spec.ts index 0c8adb05..74d3fe47 100644 --- a/src/readers/sync.spec.ts +++ b/src/readers/sync.spec.ts @@ -6,7 +6,7 @@ import * as fsWalk from '@nodelib/fs.walk'; import * as sinon from 'sinon'; import Settings, { Options } from '../settings'; -import * as tests from '../tests/index'; +import * as tests from '../tests'; import { ReaderOptions } from '../types'; import ReaderSync from './sync'; diff --git a/src/readers/sync.ts b/src/readers/sync.ts index 650b2281..39096f14 100644 --- a/src/readers/sync.ts +++ b/src/readers/sync.ts @@ -3,7 +3,7 @@ import * as fs from 'fs'; import * as fsStat from '@nodelib/fs.stat'; import * as fsWalk from '@nodelib/fs.walk'; -import { Entry, ErrnoException, Pattern, ReaderOptions } from '../types/index'; +import { Entry, ErrnoException, Pattern, ReaderOptions } from '../types'; import Reader from './reader'; export default class ReaderSync extends Reader { diff --git a/src/settings.ts b/src/settings.ts index 1440eb13..7b8aacb1 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1,7 +1,7 @@ import * as fs from 'fs'; import * as os from 'os'; -import { FileSystemAdapter, Pattern } from './types/index'; +import { FileSystemAdapter, Pattern } from './types'; const CPU_COUNT = os.cpus().length; diff --git a/src/tests/smoke/smoke.ts b/src/tests/smoke/smoke.ts index a2f5b775..499dd0f6 100644 --- a/src/tests/smoke/smoke.ts +++ b/src/tests/smoke/smoke.ts @@ -1,8 +1,8 @@ import * as assert from 'assert'; -import * as fg from '../../index'; +import * as fg from '../..'; import { Options } from '../../settings'; -import { Pattern } from '../../types/index'; +import { Pattern } from '../../types'; import Table = require('easy-table'); import glob = require('glob'); diff --git a/src/tests/utils/task.ts b/src/tests/utils/task.ts index 9931c889..80fcb73c 100644 --- a/src/tests/utils/task.ts +++ b/src/tests/utils/task.ts @@ -1,5 +1,5 @@ import { Task } from '../../managers/tasks'; -import { Pattern } from '../../types/index'; +import { Pattern } from '../../types'; class TaskBuilder { private readonly _task: Task = { diff --git a/src/utils/errno.spec.ts b/src/utils/errno.spec.ts index c985b071..838cf149 100644 --- a/src/utils/errno.spec.ts +++ b/src/utils/errno.spec.ts @@ -1,6 +1,6 @@ import * as assert from 'assert'; -import * as tests from '../tests/index'; +import * as tests from '../tests'; import * as util from './errno'; describe('Utils → Errno', () => { diff --git a/src/utils/pattern.spec.ts b/src/utils/pattern.spec.ts index 0f0793d8..20941629 100644 --- a/src/utils/pattern.spec.ts +++ b/src/utils/pattern.spec.ts @@ -1,6 +1,6 @@ import * as assert from 'assert'; -import { Pattern } from '../types/index'; +import { Pattern } from '../types'; import * as util from './pattern'; describe('Utils → Pattern', () => { diff --git a/src/utils/pattern.ts b/src/utils/pattern.ts index e66c2ca2..1a343b49 100644 --- a/src/utils/pattern.ts +++ b/src/utils/pattern.ts @@ -1,6 +1,6 @@ import * as path from 'path'; -import { MicromatchOptions, Pattern, PatternRe } from '../types/index'; +import { MicromatchOptions, Pattern, PatternRe } from '../types'; import globParent = require('glob-parent'); import micromatch = require('micromatch'); From 376b8fa1c02429c529261970d7a199e4fc4484ce Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Tue, 1 Oct 2019 10:04:46 +0300 Subject: [PATCH 23/31] =?UTF-8?q?style(benchmark):=20rename=20`getMeasures?= =?UTF-8?q?`=20=E2=86=92=20`formatMeasures`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/benchmark/suites/product/async/fast-glob.ts | 2 +- src/benchmark/suites/product/async/node-glob.ts | 2 +- src/benchmark/suites/product/async/tiny-glob.ts | 2 +- src/benchmark/suites/product/stream/fast-glob.ts | 2 +- src/benchmark/suites/product/sync/fast-glob.ts | 2 +- src/benchmark/suites/product/sync/node-glob.ts | 2 +- src/benchmark/suites/regression/async/fast-glob-current.ts | 2 +- src/benchmark/suites/regression/async/fast-glob-previous.ts | 2 +- src/benchmark/suites/regression/stream/fast-glob-current.ts | 2 +- src/benchmark/suites/regression/stream/fast-glob-previous.ts | 2 +- src/benchmark/suites/regression/sync/fast-glob-current.ts | 2 +- src/benchmark/suites/regression/sync/fast-glob-previous.ts | 2 +- src/benchmark/utils.spec.ts | 2 +- src/benchmark/utils.ts | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/benchmark/suites/product/async/fast-glob.ts b/src/benchmark/suites/product/async/fast-glob.ts index 76f83109..28fe6662 100644 --- a/src/benchmark/suites/product/async/fast-glob.ts +++ b/src/benchmark/suites/product/async/fast-glob.ts @@ -14,7 +14,7 @@ glob(process.env.BENCHMARK_PATTERN as string, options) .then((matches) => { const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.getMeasures(matches.length, time, memory); + const measures = utils.formatMeasures(matches.length, time, memory); console.info(measures); }) diff --git a/src/benchmark/suites/product/async/node-glob.ts b/src/benchmark/suites/product/async/node-glob.ts index 6dd5475b..f75efdc5 100644 --- a/src/benchmark/suites/product/async/node-glob.ts +++ b/src/benchmark/suites/product/async/node-glob.ts @@ -20,7 +20,7 @@ glob(process.env.BENCHMARK_PATTERN as string, options, (error, matches) => { const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.getMeasures(matches.length, time, memory); + const measures = utils.formatMeasures(matches.length, time, memory); console.info(measures); }); diff --git a/src/benchmark/suites/product/async/tiny-glob.ts b/src/benchmark/suites/product/async/tiny-glob.ts index 3bb65044..b9b37d01 100644 --- a/src/benchmark/suites/product/async/tiny-glob.ts +++ b/src/benchmark/suites/product/async/tiny-glob.ts @@ -15,7 +15,7 @@ glob(process.env.BENCHMARK_PATTERN as string, options) .then((matches) => { const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.getMeasures(matches.length, time, memory); + const measures = utils.formatMeasures(matches.length, time, memory); console.info(measures); }) diff --git a/src/benchmark/suites/product/stream/fast-glob.ts b/src/benchmark/suites/product/stream/fast-glob.ts index 60356bbf..bd55d29a 100644 --- a/src/benchmark/suites/product/stream/fast-glob.ts +++ b/src/benchmark/suites/product/stream/fast-glob.ts @@ -20,7 +20,7 @@ stream.on('data', (entry: string) => entries.push(entry)); stream.once('end', () => { const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.getMeasures([...entries].length, time, memory); + const measures = utils.formatMeasures([...entries].length, time, memory); console.info(measures); }); diff --git a/src/benchmark/suites/product/sync/fast-glob.ts b/src/benchmark/suites/product/sync/fast-glob.ts index 11c7cd76..f0671ec6 100644 --- a/src/benchmark/suites/product/sync/fast-glob.ts +++ b/src/benchmark/suites/product/sync/fast-glob.ts @@ -14,7 +14,7 @@ try { const matches = glob.sync(process.env.BENCHMARK_PATTERN as string, options); const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.getMeasures(matches.length, time, memory); + const measures = utils.formatMeasures(matches.length, time, memory); console.info(measures); } catch { diff --git a/src/benchmark/suites/product/sync/node-glob.ts b/src/benchmark/suites/product/sync/node-glob.ts index 2333a22f..232bb4cd 100644 --- a/src/benchmark/suites/product/sync/node-glob.ts +++ b/src/benchmark/suites/product/sync/node-glob.ts @@ -17,7 +17,7 @@ try { const matches = glob.sync(process.env.BENCHMARK_PATTERN as string, options); const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.getMeasures(matches.length, time, memory); + const measures = utils.formatMeasures(matches.length, time, memory); console.info(measures); } catch { diff --git a/src/benchmark/suites/regression/async/fast-glob-current.ts b/src/benchmark/suites/regression/async/fast-glob-current.ts index 1b1bfa62..b004f454 100644 --- a/src/benchmark/suites/regression/async/fast-glob-current.ts +++ b/src/benchmark/suites/regression/async/fast-glob-current.ts @@ -15,7 +15,7 @@ glob(process.env.BENCHMARK_PATTERN as string, options) .then((matches) => { const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.getMeasures(matches.length, time, memory); + const measures = utils.formatMeasures(matches.length, time, memory); console.info(measures); }) diff --git a/src/benchmark/suites/regression/async/fast-glob-previous.ts b/src/benchmark/suites/regression/async/fast-glob-previous.ts index 30bca401..f25510e0 100644 --- a/src/benchmark/suites/regression/async/fast-glob-previous.ts +++ b/src/benchmark/suites/regression/async/fast-glob-previous.ts @@ -16,7 +16,7 @@ fg(process.env.BENCHMARK_PATTERN as string, options) .then((matches) => { const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.getMeasures(matches.length, time, memory); + const measures = utils.formatMeasures(matches.length, time, memory); console.info(measures); }) diff --git a/src/benchmark/suites/regression/stream/fast-glob-current.ts b/src/benchmark/suites/regression/stream/fast-glob-current.ts index 21bf5fa6..85ce0ab5 100644 --- a/src/benchmark/suites/regression/stream/fast-glob-current.ts +++ b/src/benchmark/suites/regression/stream/fast-glob-current.ts @@ -20,7 +20,7 @@ stream.on('data', (entry: string) => entries.push(entry)); stream.once('end', () => { const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.getMeasures([...entries].length, time, memory); + const measures = utils.formatMeasures([...entries].length, time, memory); console.info(measures); }); diff --git a/src/benchmark/suites/regression/stream/fast-glob-previous.ts b/src/benchmark/suites/regression/stream/fast-glob-previous.ts index a3de2a42..84481088 100644 --- a/src/benchmark/suites/regression/stream/fast-glob-previous.ts +++ b/src/benchmark/suites/regression/stream/fast-glob-previous.ts @@ -21,7 +21,7 @@ stream.on('data', (entry: string) => entries.push(entry)); stream.once('end', () => { const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.getMeasures([...entries].length, time, memory); + const measures = utils.formatMeasures([...entries].length, time, memory); console.info(measures); }); diff --git a/src/benchmark/suites/regression/sync/fast-glob-current.ts b/src/benchmark/suites/regression/sync/fast-glob-current.ts index 48d56f57..a7113ebb 100644 --- a/src/benchmark/suites/regression/sync/fast-glob-current.ts +++ b/src/benchmark/suites/regression/sync/fast-glob-current.ts @@ -15,7 +15,7 @@ try { const matches = glob.sync(process.env.BENCHMARK_PATTERN as string, options); const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.getMeasures(matches.length, time, memory); + const measures = utils.formatMeasures(matches.length, time, memory); console.info(measures); } catch { diff --git a/src/benchmark/suites/regression/sync/fast-glob-previous.ts b/src/benchmark/suites/regression/sync/fast-glob-previous.ts index aa589362..ac225d9d 100644 --- a/src/benchmark/suites/regression/sync/fast-glob-previous.ts +++ b/src/benchmark/suites/regression/sync/fast-glob-previous.ts @@ -16,7 +16,7 @@ try { const matches = fg.sync(process.env.BENCHMARK_PATTERN as string, options); const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.getMeasures(matches.length, time, memory); + const measures = utils.formatMeasures(matches.length, time, memory); console.info(measures); } catch { diff --git a/src/benchmark/utils.spec.ts b/src/benchmark/utils.spec.ts index 09064da0..5799582c 100644 --- a/src/benchmark/utils.spec.ts +++ b/src/benchmark/utils.spec.ts @@ -78,7 +78,7 @@ describe('Benchmark → Utils', () => { it('should return measures', () => { const expected = '{"matches":1,"time":1,"memory":1}'; - const actual = utils.getMeasures(1, 1, 1); + const actual = utils.formatMeasures(1, 1, 1); assert.strictEqual(actual, expected); }); diff --git a/src/benchmark/utils.ts b/src/benchmark/utils.ts index 54036796..2d5e868e 100644 --- a/src/benchmark/utils.ts +++ b/src/benchmark/utils.ts @@ -30,7 +30,7 @@ export function getMemory(): number { return process.memoryUsage().heapUsed / BYTES_IN_MEGABYTE; } -export function getMeasures(matches: number, time: number, memory: number): string { +export function formatMeasures(matches: number, time: number, memory: number): string { return JSON.stringify({ matches, time, memory } as SuiteMeasures); } From 4a6c2449c1525260884be8db04134d15b2de5859 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Tue, 1 Oct 2019 10:07:24 +0300 Subject: [PATCH 24/31] style: fix `consistent-type-assertions` rule --- src/benchmark/runner.spec.ts | 4 ++-- src/benchmark/utils.ts | 4 +++- src/managers/tasks.ts | 4 +++- src/readers/stream.spec.ts | 2 +- src/readers/sync.spec.ts | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/benchmark/runner.spec.ts b/src/benchmark/runner.spec.ts index e12ac047..643c5771 100644 --- a/src/benchmark/runner.spec.ts +++ b/src/benchmark/runner.spec.ts @@ -39,7 +39,7 @@ describe('Benchmark → Runner', () => { describe('.suite', () => { it('should returns measures', () => { - const runner = new RunnerFakeProcess('basedir', {} as RunnerOptions); + const runner = new RunnerFakeProcess('basedir', runnerOptions); const expected: SuiteMeasures = { matches: 1, @@ -53,7 +53,7 @@ describe('Benchmark → Runner', () => { }); it('should throw error', () => { - const runner = new RunnerFakeProcessError('basedir', {} as RunnerOptions); + const runner = new RunnerFakeProcessError('basedir', runnerOptions); assert.throws(() => runner.suite('suitePath'), /Ops! Broken suite run\./); }); diff --git a/src/benchmark/utils.ts b/src/benchmark/utils.ts index 2d5e868e..90e256b3 100644 --- a/src/benchmark/utils.ts +++ b/src/benchmark/utils.ts @@ -31,7 +31,9 @@ export function getMemory(): number { } export function formatMeasures(matches: number, time: number, memory: number): string { - return JSON.stringify({ matches, time, memory } as SuiteMeasures); + const measures: SuiteMeasures = { matches, time, memory }; + + return JSON.stringify(measures); } export function getAverageValue(values: number[]): number { diff --git a/src/managers/tasks.ts b/src/managers/tasks.ts index 7515cfb4..9694058c 100644 --- a/src/managers/tasks.ts +++ b/src/managers/tasks.ts @@ -49,6 +49,8 @@ export function getNegativePatternsAsPositive(patterns: Pattern[], ignore: Patte } export function groupPatternsByBaseDirectory(patterns: Pattern[]): PatternsGroup { + const group: PatternsGroup = {}; + return patterns.reduce((collection, pattern) => { const base = utils.pattern.getBaseDirectory(pattern); @@ -59,7 +61,7 @@ export function groupPatternsByBaseDirectory(patterns: Pattern[]): PatternsGroup } return collection; - }, {} as PatternsGroup); + }, group); } export function convertPatternGroupsToTasks(positive: PatternsGroup, negative: Pattern[], dynamic: boolean): Task[] { diff --git a/src/readers/stream.spec.ts b/src/readers/stream.spec.ts index b254cd56..f7312500 100644 --- a/src/readers/stream.spec.ts +++ b/src/readers/stream.spec.ts @@ -35,7 +35,7 @@ function getReader(options?: Options): TestReader { } function getReaderOptions(options: Partial = {}): ReaderOptions { - return { ...options } as ReaderOptions; + return { ...options } as unknown as ReaderOptions; } describe('Readers → ReaderStream', () => { diff --git a/src/readers/sync.spec.ts b/src/readers/sync.spec.ts index 74d3fe47..06994a0d 100644 --- a/src/readers/sync.spec.ts +++ b/src/readers/sync.spec.ts @@ -35,7 +35,7 @@ function getReader(options?: Options): TestReader { } function getReaderOptions(options: Partial = {}): ReaderOptions { - return { ...options } as ReaderOptions; + return { ...options } as unknown as ReaderOptions; } describe('Readers → ReaderSync', () => { From 027dab549cd199e29c85264e8affce1550fa9041 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Tue, 1 Oct 2019 10:25:57 +0300 Subject: [PATCH 25/31] style: fix `unicorn/prevent-abbreviations` rule --- src/benchmark/index.ts | 8 ++++---- src/benchmark/runner.ts | 7 +++++-- src/benchmark/utils.spec.ts | 22 +++++++++++----------- src/benchmark/utils.ts | 12 ++++++------ src/providers/stream.ts | 10 +++++----- src/tests/smoke/smoke.ts | 28 +++++++++++++++------------- src/utils/stream.ts | 2 +- 7 files changed, 47 insertions(+), 42 deletions(-) diff --git a/src/benchmark/index.ts b/src/benchmark/index.ts index d0ef0786..db82a86b 100644 --- a/src/benchmark/index.ts +++ b/src/benchmark/index.ts @@ -18,10 +18,10 @@ const defaultArgv: Arguments = { type: process.env.BENCHMARK_TYPE || 'product', mode: process.env.BENCHMARK_MODE || 'async', pattern: process.env.BENCHMARK_PATTERN || '*', - launches: utils.getEnvAsInteger('BENCHMARK_LAUNCHES') || DEFAULT_BENCHMARK_LAUNCHES, - maxStdev: utils.getEnvAsInteger('BENCHMARK_MAX_STDEV') || DEFAULT_BENCHMARK_MAX_STDEV, - retries: utils.getEnvAsInteger('BENCHMARK_RETRIES') || DEFAULT_BENCHMARK_RETRIES, - options: utils.getEnvAsObject('BENCHMARK_OPTIONS') || {} + launches: utils.getEnvironmentAsInteger('BENCHMARK_LAUNCHES') || DEFAULT_BENCHMARK_LAUNCHES, + maxStdev: utils.getEnvironmentAsInteger('BENCHMARK_MAX_STDEV') || DEFAULT_BENCHMARK_MAX_STDEV, + retries: utils.getEnvironmentAsInteger('BENCHMARK_RETRIES') || DEFAULT_BENCHMARK_RETRIES, + options: utils.getEnvironmentAsObject('BENCHMARK_OPTIONS') || {} }; const argv = minimist(process.argv.slice(PROCESS_FIRST_ARGUMENT_INDEX), { diff --git a/src/benchmark/runner.ts b/src/benchmark/runner.ts index d87ed689..b5a8cd99 100644 --- a/src/benchmark/runner.ts +++ b/src/benchmark/runner.ts @@ -54,14 +54,17 @@ export default class Runner { * Runs a single suite in the child process and returns the measurements of his work. */ public suite(suitePath: string): SuiteMeasures { - const env: NodeJS.ProcessEnv = { + const environment: NodeJS.ProcessEnv = { NODE_ENV: 'production', BENCHMARK_BASE_DIR: this._basedir, BENCHMARK_PATTERN: this._options.pattern, BENCHMARK_OPTIONS: JSON.stringify(this._options.options) }; - const stdout = this.execNodeProcess([suitePath], { env, extendEnv: true }); + // eslint-disable-next-line unicorn/prevent-abbreviations + const execaOptions: execa.SyncOptions = { env: environment, extendEnv: true }; + + const stdout = this.execNodeProcess([suitePath], execaOptions); try { return JSON.parse(stdout) as SuiteMeasures; diff --git a/src/benchmark/utils.spec.ts b/src/benchmark/utils.spec.ts index 5799582c..7423d2f7 100644 --- a/src/benchmark/utils.spec.ts +++ b/src/benchmark/utils.spec.ts @@ -104,39 +104,39 @@ describe('Benchmark → Utils', () => { }); }); - describe('.getEnvAsInteger', () => { + describe('.getEnvironmentAsInteger', () => { it('should return integer', () => { const expected = 1; - const actual = utils.getEnvAsInteger('FG_TEST_ENV_INTEGER'); + const actual = utils.getEnvironmentAsInteger('FG_TEST_ENV_INTEGER', 0); assert.strictEqual(actual, expected); }); - it('should return undefined', () => { - const expected = undefined; + it('should return default value', () => { + const expected = 0; - const actual = utils.getEnvAsInteger('NON_EXIST_ENV_VARIABLE'); + const actual = utils.getEnvironmentAsInteger('NON_EXIST_ENV_VARIABLE', 0); assert.strictEqual(actual, expected); }); }); - describe('.getEnvAsObject', () => { + describe('.getEnvironmentAsObject', () => { it('should return object', () => { const expected = { value: true }; - const actual = utils.getEnvAsObject('FG_TEST_ENV_OBJECT'); + const actual = utils.getEnvironmentAsObject('FG_TEST_ENV_OBJECT', {}); assert.deepStrictEqual(actual, expected); }); - it('should return undefined', () => { - const expected = undefined; + it('should return default value', () => { + const expected = {}; - const actual = utils.getEnvAsObject('NON_EXIST_ENV_VARIABLE'); + const actual = utils.getEnvironmentAsObject('NON_EXIST_ENV_VARIABLE', {}); - assert.strictEqual(actual, expected); + assert.deepStrictEqual(actual, expected); }); }); }); diff --git a/src/benchmark/utils.ts b/src/benchmark/utils.ts index 90e256b3..53e79a85 100644 --- a/src/benchmark/utils.ts +++ b/src/benchmark/utils.ts @@ -44,14 +44,14 @@ export function getStdev(values: number[]): number { return stdev(values); } -export function getEnvAsInteger(name: string): number | undefined { - const env = process.env[name]; +export function getEnvironmentAsInteger(name: string): number | undefined { + const environment = process.env[name]; - return env ? parseInt(env, 10) : undefined; + return environment ? parseInt(environment, 10) : undefined; } -export function getEnvAsObject(name: string): object | undefined { - const env = process.env[name]; +export function getEnvironmentAsObject(name: string): object | undefined { + const environment = process.env[name]; - return env ? JSON.parse(env) as object : undefined; + return environment ? JSON.parse(environment) as object : undefined; } diff --git a/src/providers/stream.ts b/src/providers/stream.ts index 83d18503..d3a775ac 100644 --- a/src/providers/stream.ts +++ b/src/providers/stream.ts @@ -13,14 +13,14 @@ export default class ProviderStream extends Provider { const options = this._getReaderOptions(task); const source = this.api(root, task, options); - const dest = new Readable({ objectMode: true, read: () => { /* noop */ } }); + const destination = new Readable({ objectMode: true, read: () => { /* noop */ } }); source - .once('error', (error: ErrnoException) => dest.emit('error', error)) - .on('data', (entry: Entry) => dest.emit('data', options.transform(entry))) - .once('end', () => dest.emit('end')); + .once('error', (error: ErrnoException) => destination.emit('error', error)) + .on('data', (entry: Entry) => destination.emit('data', options.transform(entry))) + .once('end', () => destination.emit('end')); - return dest; + return destination; } public api(root: string, task: Task, options: ReaderOptions): NodeJS.ReadableStream { diff --git a/src/tests/smoke/smoke.ts b/src/tests/smoke/smoke.ts index 499dd0f6..ce184990 100644 --- a/src/tests/smoke/smoke.ts +++ b/src/tests/smoke/smoke.ts @@ -120,32 +120,34 @@ function getTestMarker(items: string[], item: string): DebugCompareTestMarker { return items.includes(item) ? '+' : '-'; } -function getNodeGlobEntries(pattern: Pattern, ignore?: Pattern, cwd?: string, opts?: glob.IOptions): string[] { - const options: glob.IOptions = { +function getNodeGlobEntries(pattern: Pattern, ignore?: Pattern, cwd?: string, options?: glob.IOptions): string[] { + const entries = glob.sync(pattern, { cwd: cwd || process.cwd(), ignore: ignore ? [ignore] : [], - ...opts - }; + ...options + }); + + entries.sort((a, b) => a.localeCompare(b)); - return glob.sync(pattern, options).sort((a, b) => a.localeCompare(b)); + return entries; } -function getFastGlobEntriesSync(pattern: Pattern, ignore?: Pattern, cwd?: string, opts?: Options): string[] { - return fg.sync(pattern, getFastGlobOptions(ignore, cwd, opts)).sort((a, b) => a.localeCompare(b)); +function getFastGlobEntriesSync(pattern: Pattern, ignore?: Pattern, cwd?: string, options?: Options): string[] { + return fg.sync(pattern, getFastGlobOptions(ignore, cwd, options)).sort((a, b) => a.localeCompare(b)); } -function getFastGlobEntriesAsync(pattern: Pattern, ignore?: Pattern, cwd?: string, opts?: Options): Promise { - return fg(pattern, getFastGlobOptions(ignore, cwd, opts)).then((entries) => { +function getFastGlobEntriesAsync(pattern: Pattern, ignore?: Pattern, cwd?: string, options?: Options): Promise { + return fg(pattern, getFastGlobOptions(ignore, cwd, options)).then((entries) => { entries.sort((a, b) => a.localeCompare(b)); return entries; }); } -function getFastGlobEntriesStream(pattern: Pattern, ignore?: Pattern, cwd?: string, opts?: Options): Promise { +function getFastGlobEntriesStream(pattern: Pattern, ignore?: Pattern, cwd?: string, options?: Options): Promise { const entries: string[] = []; - const stream = fg.stream(pattern, getFastGlobOptions(ignore, cwd, opts)); + const stream = fg.stream(pattern, getFastGlobOptions(ignore, cwd, options)); return new Promise((resolve, reject) => { stream.on('data', (entry: string) => entries.push(entry)); @@ -158,11 +160,11 @@ function getFastGlobEntriesStream(pattern: Pattern, ignore?: Pattern, cwd?: stri }); } -function getFastGlobOptions(ignore?: Pattern, cwd?: string, opts?: Options): Options { +function getFastGlobOptions(ignore?: Pattern, cwd?: string, options?: Options): Options { return { cwd: cwd || process.cwd(), ignore: ignore ? [ignore] : [], onlyFiles: false, - ...opts + ...options }; } diff --git a/src/utils/stream.ts b/src/utils/stream.ts index bcb8ff75..c76d226f 100644 --- a/src/utils/stream.ts +++ b/src/utils/stream.ts @@ -4,7 +4,7 @@ export function merge(streams: NodeJS.ReadableStream[]): NodeJS.ReadableStream { const mergedStream = merge2(streams); streams.forEach((stream) => { - stream.once('error', (err) => mergedStream.emit('error', err)); + stream.once('error', (error) => mergedStream.emit('error', error)); }); return mergedStream; From 89266ef7fc1e9496baa5014f4b99818f288efada Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Tue, 1 Oct 2019 10:36:39 +0300 Subject: [PATCH 26/31] style: fix `strict-boolean-expressions` rule --- src/benchmark/index.ts | 14 +++++------ .../suites/product/async/node-glob.ts | 2 +- src/benchmark/utils.spec.ts | 18 ++++++++++++++ src/benchmark/utils.ts | 14 +++++++---- src/providers/provider.spec.ts | 2 +- src/readers/stream.ts | 2 +- src/tests/smoke/smoke.ts | 24 +++++++++---------- 7 files changed, 50 insertions(+), 26 deletions(-) diff --git a/src/benchmark/index.ts b/src/benchmark/index.ts index db82a86b..c2baa37e 100644 --- a/src/benchmark/index.ts +++ b/src/benchmark/index.ts @@ -15,13 +15,13 @@ type Arguments = { const defaultArgv: Arguments = { basedir: '.', - type: process.env.BENCHMARK_TYPE || 'product', - mode: process.env.BENCHMARK_MODE || 'async', - pattern: process.env.BENCHMARK_PATTERN || '*', - launches: utils.getEnvironmentAsInteger('BENCHMARK_LAUNCHES') || DEFAULT_BENCHMARK_LAUNCHES, - maxStdev: utils.getEnvironmentAsInteger('BENCHMARK_MAX_STDEV') || DEFAULT_BENCHMARK_MAX_STDEV, - retries: utils.getEnvironmentAsInteger('BENCHMARK_RETRIES') || DEFAULT_BENCHMARK_RETRIES, - options: utils.getEnvironmentAsObject('BENCHMARK_OPTIONS') || {} + type: utils.getEnvironmentAsString('BENCHMARK_TYPE', 'product'), + mode: utils.getEnvironmentAsString('BENCHMARK_MODE', 'async'), + pattern: utils.getEnvironmentAsString('BENCHMARK_PATTERN', '*'), + launches: utils.getEnvironmentAsInteger('BENCHMARK_LAUNCHES', DEFAULT_BENCHMARK_LAUNCHES), + maxStdev: utils.getEnvironmentAsInteger('BENCHMARK_MAX_STDEV', DEFAULT_BENCHMARK_MAX_STDEV), + retries: utils.getEnvironmentAsInteger('BENCHMARK_RETRIES', DEFAULT_BENCHMARK_RETRIES), + options: utils.getEnvironmentAsObject('BENCHMARK_OPTIONS', {}) }; const argv = minimist(process.argv.slice(PROCESS_FIRST_ARGUMENT_INDEX), { diff --git a/src/benchmark/suites/product/async/node-glob.ts b/src/benchmark/suites/product/async/node-glob.ts index f75efdc5..e0e2948f 100644 --- a/src/benchmark/suites/product/async/node-glob.ts +++ b/src/benchmark/suites/product/async/node-glob.ts @@ -14,7 +14,7 @@ const options: glob.IOptions = { const timeStart = utils.timeStart(); glob(process.env.BENCHMARK_PATTERN as string, options, (error, matches) => { - if (error) { + if (error !== null) { process.exit(0); } diff --git a/src/benchmark/utils.spec.ts b/src/benchmark/utils.spec.ts index 7423d2f7..3b558082 100644 --- a/src/benchmark/utils.spec.ts +++ b/src/benchmark/utils.spec.ts @@ -104,6 +104,24 @@ describe('Benchmark → Utils', () => { }); }); + describe('.getEnvironmentAsString', () => { + it('should return string', () => { + const expected = 'text'; + + const actual = utils.getEnvironmentAsString('FG_TEST_ENV_STRING', 'text'); + + assert.strictEqual(actual, expected); + }); + + it('should return default value', () => { + const expected = ''; + + const actual = utils.getEnvironmentAsString('NON_EXIST_ENV_VARIABLE', ''); + + assert.strictEqual(actual, expected); + }); + }); + describe('.getEnvironmentAsInteger', () => { it('should return integer', () => { const expected = 1; diff --git a/src/benchmark/utils.ts b/src/benchmark/utils.ts index 53e79a85..4b4358cf 100644 --- a/src/benchmark/utils.ts +++ b/src/benchmark/utils.ts @@ -44,14 +44,20 @@ export function getStdev(values: number[]): number { return stdev(values); } -export function getEnvironmentAsInteger(name: string): number | undefined { +export function getEnvironmentAsString(name: string, value: string): string { const environment = process.env[name]; - return environment ? parseInt(environment, 10) : undefined; + return environment === undefined ? value : environment; } -export function getEnvironmentAsObject(name: string): object | undefined { +export function getEnvironmentAsInteger(name: string, value: number): number { const environment = process.env[name]; - return environment ? JSON.parse(environment) as object : undefined; + return environment === undefined ? value : parseInt(environment, 10); +} + +export function getEnvironmentAsObject(name: string, value: object): object { + const environment = process.env[name]; + + return environment === undefined ? value : JSON.parse(environment) as object; } diff --git a/src/providers/provider.spec.ts b/src/providers/provider.spec.ts index 2343bc58..105c5fd1 100644 --- a/src/providers/provider.spec.ts +++ b/src/providers/provider.spec.ts @@ -80,7 +80,7 @@ describe('Providers → Provider', () => { assert.ok(actual.followSymbolicLinks); assert.strictEqual(typeof actual.fs, 'object'); assert.ok(!actual.stats); - assert.ok(!actual.throwErrorOnBrokenSymbolicLink); + assert.ok(actual.throwErrorOnBrokenSymbolicLink === false); assert.strictEqual(typeof actual.transform, 'function'); }); diff --git a/src/readers/stream.ts b/src/readers/stream.ts index 00e5e805..800b3a3e 100644 --- a/src/readers/stream.ts +++ b/src/readers/stream.ts @@ -58,7 +58,7 @@ export default class ReaderStream extends Reader { private _getStat(filepath: string): Promise { return new Promise((resolve, reject) => { this._stat(filepath, this._fsStatSettings, (error: NodeJS.ErrnoException | null, stats) => { - return error ? reject(error) : resolve(stats); + return error === null ? resolve(stats) : reject(error); }); }); } diff --git a/src/tests/smoke/smoke.ts b/src/tests/smoke/smoke.ts index ce184990..eff29111 100644 --- a/src/tests/smoke/smoke.ts +++ b/src/tests/smoke/smoke.ts @@ -54,15 +54,15 @@ function getTestCases(tests: Array): SmokeTest[] { function getTestCaseTitle(test: SmokeTest): string { let title = `pattern: '${test.pattern}'`; - if (test.ignore) { + if (test.ignore !== undefined) { title += `, ignore: '${test.ignore}'`; } - if (test.broken) { + if (test.broken !== undefined) { title += ` (broken - ${test.issue})`; } - if (test.correct) { + if (test.correct !== undefined) { title += ' (correct)'; } @@ -70,28 +70,28 @@ function getTestCaseTitle(test: SmokeTest): string { } function getTestCaseMochaDefinition(test: SmokeTest): MochaDefinition { - return test.debug ? it.only : it; + return test.debug === true ? it.only : it; } async function testCaseRunner(test: SmokeTest, func: typeof getFastGlobEntriesSync | typeof getFastGlobEntriesAsync): Promise { const expected = getNodeGlobEntries(test.pattern, test.ignore, test.cwd, test.globOptions); const actual = await func(test.pattern, test.ignore, test.cwd, test.fgOptions); - if (test.debug) { + if (test.debug === true) { const report = generateDebugReport(expected, actual); console.log(report); } - if (test.broken && !test.issue) { + if (test.broken === true && test.issue === undefined) { assert.fail("This test is marked as «broken», but it doesn't have a issue key."); } - if (test.correct && !test.reason) { + if (test.correct === true && test.reason === undefined) { assert.fail("This test is marked as «correct», but it doesn't have a reason."); } - const isInvertedTest = test.broken || test.correct; + const isInvertedTest = test.broken === true || test.correct === true; const assertAction = isInvertedTest ? assert.notDeepStrictEqual : assert.deepStrictEqual; assertAction(actual, expected); @@ -122,8 +122,8 @@ function getTestMarker(items: string[], item: string): DebugCompareTestMarker { function getNodeGlobEntries(pattern: Pattern, ignore?: Pattern, cwd?: string, options?: glob.IOptions): string[] { const entries = glob.sync(pattern, { - cwd: cwd || process.cwd(), - ignore: ignore ? [ignore] : [], + cwd: cwd === undefined ? process.cwd() : cwd, + ignore: ignore === undefined ? [] : [ignore], ...options }); @@ -162,8 +162,8 @@ function getFastGlobEntriesStream(pattern: Pattern, ignore?: Pattern, cwd?: stri function getFastGlobOptions(ignore?: Pattern, cwd?: string, options?: Options): Options { return { - cwd: cwd || process.cwd(), - ignore: ignore ? [ignore] : [], + cwd: cwd === undefined ? process.cwd() : cwd, + ignore: ignore === undefined ? [] : [ignore], onlyFiles: false, ...options }; From abdf0277d32685a73c8181ffc3c0a68e66334bf4 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Tue, 1 Oct 2019 19:20:53 +0300 Subject: [PATCH 27/31] style: fix `no-require-imports` rule --- src/benchmark/index.ts | 4 ++-- src/benchmark/runner.ts | 2 +- src/benchmark/suites/product/async/node-glob.ts | 4 ++-- src/benchmark/suites/product/async/tiny-glob.ts | 2 +- src/benchmark/suites/product/sync/node-glob.ts | 4 ++-- src/benchmark/suites/regression/async/fast-glob-previous.ts | 4 ++-- .../suites/regression/stream/fast-glob-previous.ts | 4 ++-- src/benchmark/suites/regression/sync/fast-glob-previous.ts | 4 ++-- src/benchmark/utils.ts | 2 +- src/tests/smoke/smoke.ts | 5 +++-- src/utils/pattern.ts | 6 +++--- src/utils/stream.ts | 2 +- 12 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/benchmark/index.ts b/src/benchmark/index.ts index c2baa37e..da9e7a83 100644 --- a/src/benchmark/index.ts +++ b/src/benchmark/index.ts @@ -1,9 +1,9 @@ +import * as minimist from 'minimist'; + import * as logger from './logger'; import Runner, { RunnerOptions } from './runner'; import * as utils from './utils'; -import minimist = require('minimist'); - const PROCESS_FIRST_ARGUMENT_INDEX = 2; const DEFAULT_BENCHMARK_LAUNCHES = 10; const DEFAULT_BENCHMARK_MAX_STDEV = 3; diff --git a/src/benchmark/runner.ts b/src/benchmark/runner.ts index b5a8cd99..d60a8c39 100644 --- a/src/benchmark/runner.ts +++ b/src/benchmark/runner.ts @@ -5,7 +5,7 @@ import { Options } from '../settings'; import Reporter from './reporter'; import * as utils from './utils'; -import execa = require('execa'); +import execa = require('execa'); // eslint-disable-line @typescript-eslint/no-require-imports export type RunnerOptions = { type: string; diff --git a/src/benchmark/suites/product/async/node-glob.ts b/src/benchmark/suites/product/async/node-glob.ts index e0e2948f..707bccc5 100644 --- a/src/benchmark/suites/product/async/node-glob.ts +++ b/src/benchmark/suites/product/async/node-glob.ts @@ -1,8 +1,8 @@ import * as path from 'path'; -import * as utils from '../../../utils'; +import * as glob from 'glob'; -import glob = require('glob'); +import * as utils from '../../../utils'; const options: glob.IOptions = { cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string), diff --git a/src/benchmark/suites/product/async/tiny-glob.ts b/src/benchmark/suites/product/async/tiny-glob.ts index b9b37d01..a10628fa 100644 --- a/src/benchmark/suites/product/async/tiny-glob.ts +++ b/src/benchmark/suites/product/async/tiny-glob.ts @@ -2,7 +2,7 @@ import * as path from 'path'; import * as utils from '../../../utils'; -import glob = require('tiny-glob'); +import glob = require('tiny-glob'); // eslint-disable-line @typescript-eslint/no-require-imports const options = { cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string), diff --git a/src/benchmark/suites/product/sync/node-glob.ts b/src/benchmark/suites/product/sync/node-glob.ts index 232bb4cd..24e6c593 100644 --- a/src/benchmark/suites/product/sync/node-glob.ts +++ b/src/benchmark/suites/product/sync/node-glob.ts @@ -1,8 +1,8 @@ import * as path from 'path'; -import * as utils from '../../../utils'; +import * as glob from 'glob'; -import glob = require('glob'); +import * as utils from '../../../utils'; const options: glob.IOptions = { cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string), diff --git a/src/benchmark/suites/regression/async/fast-glob-previous.ts b/src/benchmark/suites/regression/async/fast-glob-previous.ts index f25510e0..200f482a 100644 --- a/src/benchmark/suites/regression/async/fast-glob-previous.ts +++ b/src/benchmark/suites/regression/async/fast-glob-previous.ts @@ -1,8 +1,8 @@ import * as path from 'path'; -import * as utils from '../../../utils'; +import * as fg from 'fast-glob'; -import fg = require('fast-glob'); +import * as utils from '../../../utils'; const options: fg.Options = { cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string), diff --git a/src/benchmark/suites/regression/stream/fast-glob-previous.ts b/src/benchmark/suites/regression/stream/fast-glob-previous.ts index 84481088..3f60e384 100644 --- a/src/benchmark/suites/regression/stream/fast-glob-previous.ts +++ b/src/benchmark/suites/regression/stream/fast-glob-previous.ts @@ -1,8 +1,8 @@ import * as path from 'path'; -import * as utils from '../../../utils'; +import * as fg from 'fast-glob'; -import fg = require('fast-glob'); +import * as utils from '../../../utils'; const options: fg.Options = { cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string), diff --git a/src/benchmark/suites/regression/sync/fast-glob-previous.ts b/src/benchmark/suites/regression/sync/fast-glob-previous.ts index ac225d9d..58959371 100644 --- a/src/benchmark/suites/regression/sync/fast-glob-previous.ts +++ b/src/benchmark/suites/regression/sync/fast-glob-previous.ts @@ -1,8 +1,8 @@ import * as path from 'path'; -import * as utils from '../../../utils'; +import * as fg from 'fast-glob'; -import fg = require('fast-glob'); +import * as utils from '../../../utils'; const options: fg.Options = { cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string), diff --git a/src/benchmark/utils.ts b/src/benchmark/utils.ts index 4b4358cf..9a9462e1 100644 --- a/src/benchmark/utils.ts +++ b/src/benchmark/utils.ts @@ -1,6 +1,6 @@ import { SuiteMeasures } from './runner'; -import stdev = require('compute-stdev'); +import stdev = require('compute-stdev'); // eslint-disable-line @typescript-eslint/no-require-imports const NANOSECONDS_IN_SECOND = 1e9; const MICROSECONDS_IN_SECOND = 1e6; diff --git a/src/tests/smoke/smoke.ts b/src/tests/smoke/smoke.ts index eff29111..23371664 100644 --- a/src/tests/smoke/smoke.ts +++ b/src/tests/smoke/smoke.ts @@ -1,11 +1,12 @@ import * as assert from 'assert'; +import * as glob from 'glob'; + import * as fg from '../..'; import { Options } from '../../settings'; import { Pattern } from '../../types'; -import Table = require('easy-table'); -import glob = require('glob'); +import Table = require('easy-table'); // eslint-disable-line @typescript-eslint/no-require-imports export type SmokeTest = { pattern: Pattern; diff --git a/src/utils/pattern.ts b/src/utils/pattern.ts index 1a343b49..6be520a3 100644 --- a/src/utils/pattern.ts +++ b/src/utils/pattern.ts @@ -1,9 +1,9 @@ import * as path from 'path'; -import { MicromatchOptions, Pattern, PatternRe } from '../types'; +import * as globParent from 'glob-parent'; +import * as micromatch from 'micromatch'; -import globParent = require('glob-parent'); -import micromatch = require('micromatch'); +import { MicromatchOptions, Pattern, PatternRe } from '../types'; const GLOBSTAR = '**'; const ESCAPE_SYMBOL = '\\'; diff --git a/src/utils/stream.ts b/src/utils/stream.ts index c76d226f..70bbd28d 100644 --- a/src/utils/stream.ts +++ b/src/utils/stream.ts @@ -1,4 +1,4 @@ -import merge2 = require('merge2'); +import * as merge2 from 'merge2'; export function merge(streams: NodeJS.ReadableStream[]): NodeJS.ReadableStream { const mergedStream = merge2(streams); From c59673df4143c8d127c8695d8d5deaf5e8b3fa6a Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Tue, 1 Oct 2019 20:09:21 +0300 Subject: [PATCH 28/31] style: fix `no-misused-promises` rule --- src/tests/smoke/smoke.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/smoke/smoke.ts b/src/tests/smoke/smoke.ts index 23371664..b24bb37c 100644 --- a/src/tests/smoke/smoke.ts +++ b/src/tests/smoke/smoke.ts @@ -30,7 +30,7 @@ export type SmokeTest = { reason?: string; }; -type MochaDefinition = (desc: string, cb: (this: Mocha.Context) => void) => void; +type MochaDefinition = Mocha.TestFunction | Mocha.ExclusiveTestFunction; type DebugCompareTestMarker = '+' | '-'; export function suite(name: string, tests: Array): void { From ced18d326c9e07dbbd3be6372bef1a04a6164b2e Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Tue, 1 Oct 2019 20:20:44 +0300 Subject: [PATCH 29/31] build(package): bump dependencies --- package.json | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 338768e2..52cca8f3 100644 --- a/package.json +++ b/package.json @@ -20,38 +20,37 @@ "implementation" ], "devDependencies": { - "@nodelib/fs.macchiato": "^1.0.0", + "@nodelib/fs.macchiato": "^1.0.1", "@types/compute-stdev": "^1.0.0", "@types/easy-table": "^0.0.32", - "@types/execa": "^0.9.0", "@types/glob": "^7.1.1", "@types/glob-parent": "^5.1.0", "@types/merge2": "^1.1.4", "@types/micromatch": "^3.1.0", "@types/minimist": "^1.2.0", "@types/mocha": "^5.2.7", - "@types/node": "^12.0.10", + "@types/node": "^12.7.8", "@types/rimraf": "^2.0.2", - "@types/sinon": "^7.0.13", + "@types/sinon": "^7.5.0", "compute-stdev": "^1.0.0", "easy-table": "^1.1.1", - "eslint": "^6.3.0", - "eslint-config-mrmlnc": "^1.0.0", - "execa": "^1.0.0", - "fast-glob": "^3.0.2", + "eslint": "^6.5.1", + "eslint-config-mrmlnc": "^1.0.1", + "execa": "^2.0.4", + "fast-glob": "^3.0.4", "glob": "^7.1.4", "minimist": "^1.2.0", - "mocha": "^6.1.4", - "rimraf": "^2.6.3", - "sinon": "^7.3.2", + "mocha": "^6.2.1", + "rimraf": "^3.0.0", + "sinon": "^7.5.0", "tiny-glob": "^0.2.6", - "typescript": "^3.5.3" + "typescript": "^3.6.3" }, "dependencies": { - "@nodelib/fs.stat": "^2.0.1", - "@nodelib/fs.walk": "^1.2.1", + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", "glob-parent": "^5.1.0", - "merge2": "^1.2.3", + "merge2": "^1.3.0", "micromatch": "^4.0.2" }, "scripts": { From 85cb7876981fb72ce8a578ee4c92bcbcc2a790bd Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Tue, 1 Oct 2019 23:27:16 +0300 Subject: [PATCH 30/31] refactor(benchmark): use an array directly --- src/benchmark/suites/product/stream/fast-glob.ts | 2 +- src/benchmark/suites/regression/stream/fast-glob-current.ts | 2 +- src/benchmark/suites/regression/stream/fast-glob-previous.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/benchmark/suites/product/stream/fast-glob.ts b/src/benchmark/suites/product/stream/fast-glob.ts index bd55d29a..b91ee179 100644 --- a/src/benchmark/suites/product/stream/fast-glob.ts +++ b/src/benchmark/suites/product/stream/fast-glob.ts @@ -20,7 +20,7 @@ stream.on('data', (entry: string) => entries.push(entry)); stream.once('end', () => { const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.formatMeasures([...entries].length, time, memory); + const measures = utils.formatMeasures(entries.length, time, memory); console.info(measures); }); diff --git a/src/benchmark/suites/regression/stream/fast-glob-current.ts b/src/benchmark/suites/regression/stream/fast-glob-current.ts index 85ce0ab5..286fab4c 100644 --- a/src/benchmark/suites/regression/stream/fast-glob-current.ts +++ b/src/benchmark/suites/regression/stream/fast-glob-current.ts @@ -20,7 +20,7 @@ stream.on('data', (entry: string) => entries.push(entry)); stream.once('end', () => { const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.formatMeasures([...entries].length, time, memory); + const measures = utils.formatMeasures(entries.length, time, memory); console.info(measures); }); diff --git a/src/benchmark/suites/regression/stream/fast-glob-previous.ts b/src/benchmark/suites/regression/stream/fast-glob-previous.ts index 3f60e384..0f18c51e 100644 --- a/src/benchmark/suites/regression/stream/fast-glob-previous.ts +++ b/src/benchmark/suites/regression/stream/fast-glob-previous.ts @@ -21,7 +21,7 @@ stream.on('data', (entry: string) => entries.push(entry)); stream.once('end', () => { const memory = utils.getMemory(); const time = utils.timeEnd(timeStart); - const measures = utils.formatMeasures([...entries].length, time, memory); + const measures = utils.formatMeasures(entries.length, time, memory); console.info(measures); }); From 1e0d0c02f1c22c762ee608d57b2bfbed93bef93c Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Wed, 2 Oct 2019 09:58:42 +0300 Subject: [PATCH 31/31] style: fix some style issues after review --- src/benchmark/index.ts | 4 ++-- src/benchmark/reporter.ts | 8 +++++--- src/benchmark/runner.ts | 2 +- src/index.spec.ts | 8 ++++---- src/types/index.ts | 4 ++-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/benchmark/index.ts b/src/benchmark/index.ts index da9e7a83..676db3fe 100644 --- a/src/benchmark/index.ts +++ b/src/benchmark/index.ts @@ -9,9 +9,9 @@ const DEFAULT_BENCHMARK_LAUNCHES = 10; const DEFAULT_BENCHMARK_MAX_STDEV = 3; const DEFAULT_BENCHMARK_RETRIES = 5; -type Arguments = { +type Arguments = RunnerOptions & { basedir: string; -} & RunnerOptions; +}; const defaultArgv: Arguments = { basedir: '.', diff --git a/src/benchmark/reporter.ts b/src/benchmark/reporter.ts index 30d013d1..9c3ca1c7 100644 --- a/src/benchmark/reporter.ts +++ b/src/benchmark/reporter.ts @@ -1,4 +1,4 @@ -import { SuitePackResult } from './runner'; +import { SuitePackResult, SuitePackMeasures } from './runner'; const FRACTION_DIGITS = 3; @@ -22,10 +22,12 @@ export default class Reporter { } private _formatMeasures(): string { - return Object.keys(this._results.measures).map(this._formatMeasure, this).join(' | '); + const keys = Object.keys(this._results.measures) as Array; + + return keys.map(this._formatMeasure, this).join(' | '); } - private _formatMeasure(name: string): string { + private _formatMeasure(name: keyof SuitePackMeasures): string { const data = this._results.measures[name]; return [ diff --git a/src/benchmark/runner.ts b/src/benchmark/runner.ts index d60a8c39..beac14d0 100644 --- a/src/benchmark/runner.ts +++ b/src/benchmark/runner.ts @@ -33,7 +33,7 @@ export type Measure = { export type SuitePackMeasures = { time: Measure; memory: Measure; -} & Record; +}; export type SuitePackResult = { name: string; diff --git a/src/index.spec.ts b/src/index.spec.ts index 18a646fb..82ab376d 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -7,7 +7,7 @@ import * as pkg from '.'; describe('Package', () => { describe('.sync', () => { it('should throw an error when input values can not pass validation', () => { - /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any assert.throws(() => pkg.sync(null as any), /TypeError: Patterns must be a string or an array of strings/); }); @@ -50,7 +50,7 @@ describe('Package', () => { describe('.async', () => { it('should throw an error when input values can not pass validation', async () => { try { - /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any await pkg(null as any); throw new Error('An unexpected error was found.'); } catch (error) { @@ -96,7 +96,7 @@ describe('Package', () => { describe('.stream', () => { it('should throw an error when input values can not pass validation', () => { - /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any assert.throws(() => pkg.stream(null as any), /TypeError: Patterns must be a string or an array of strings/); }); @@ -152,7 +152,7 @@ describe('Package', () => { describe('.generateTasks', () => { it('should throw an error when input values can not pass validation', () => { - /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any assert.throws(() => pkg.generateTasks(null as any), /TypeError: Patterns must be a string or an array of strings/); }); diff --git a/src/types/index.ts b/src/types/index.ts index eea108ef..646ed42e 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -9,14 +9,14 @@ export type Pattern = string; export type PatternRe = RegExp; export type PatternsGroup = Record; -export type ReaderOptions = { +export type ReaderOptions = fsWalk.Options & { transform(entry: Entry): EntryItem; deepFilter: DeepFilterFunction; entryFilter: EntryFilterFunction; errorFilter: ErrorFilterFunction; fs: FileSystemAdapter; stats: boolean; -} & fsWalk.Options; +}; export type ErrorFilterFunction = fsWalk.ErrorFilterFunction; export type EntryFilterFunction = fsWalk.EntryFilterFunction;