From 060b2c2ce1b45b778175ab280fe88552ff5d5841 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Wed, 20 Nov 2024 00:52:22 +0300 Subject: [PATCH 1/2] build: update dependencies --- package.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 71182b2a..2a795766 100644 --- a/package.json +++ b/package.json @@ -29,32 +29,32 @@ "@nodelib/fs.macchiato": "^2.0.0", "@types/glob-parent": "^5.1.3", "@types/merge2": "^1.4.4", - "@types/micromatch": "^4.0.5", - "@types/mocha": "^10.0.4", + "@types/micromatch": "^4.0.9", + "@types/mocha": "^10.0.9", "@types/node": "^16.18.61", - "@types/picomatch": "^2.3.3", - "@types/sinon": "^17.0.1", + "@types/picomatch": "^3.0.1", + "@types/sinon": "^17.0.3", "bencho": "^0.1.1", - "esbuild": "^0.19.5", + "esbuild": "^0.24.0", "eslint": "^8.53.0", "eslint-config-mrmlnc": "^4.1.0", "execa": "^7.2.0", "fast-glob": "^3.3.2", - "fdir": "^6.1.1", + "fdir": "^6.4.2", "glob": "^11.0.0", - "hereby": "^1.8.8", - "mocha": "^10.2.0", + "hereby": "^1.10.0", + "mocha": "^10.8.2", "rimraf": "^6.0.1", - "sinon": "^17.0.1", + "sinon": "^19.0.2", "snap-shot-it": "^7.9.10", - "typescript": "^5.2.2" + "typescript": "^5.6.3" }, "dependencies": { "@nodelib/fs.stat": "^3.0.0", "@nodelib/fs.walk": "^2.0.0", "glob-parent": "^6.0.2", "merge2": "^1.4.1", - "micromatch": "^4.0.7" + "micromatch": "^4.0.8" }, "scripts": { "clean": "rimraf out build", From 14a1f6c2905c55f6486048ba605b67b9b98a243f Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Wed, 20 Nov 2024 01:03:03 +0300 Subject: [PATCH 2/2] build: update eslint --- .github/workflows/main.yml | 1 + __snapshots__/absolute.e2e.js | 3 + __snapshots__/regular.e2e.js | 3 + eslint.config.mjs | 8 ++ package.json | 4 +- src/benchmark/suites/product/stream.ts | 4 +- src/benchmark/suites/regression/stream.ts | 4 +- src/index.spec.ts | 32 +++--- src/managers/tasks.spec.ts | 2 + src/providers/async.spec.ts | 1 + src/providers/filters/deep.spec.ts | 2 + src/providers/filters/entry.spec.ts | 2 + src/providers/filters/error.spec.ts | 2 + src/providers/matchers/matcher.spec.ts | 2 + src/providers/matchers/partial.spec.ts | 2 + src/providers/provider.spec.ts | 4 +- src/providers/stream.spec.ts | 1 + src/providers/sync.spec.ts | 1 + src/providers/transformers/entry.spec.ts | 2 + src/readers/async.spec.ts | 1 + src/readers/reader.spec.ts | 1 + src/readers/stream.spec.ts | 1 + src/readers/sync.spec.ts | 1 + src/settings.spec.ts | 2 + src/tests/e2e/runner.ts | 8 +- src/types/index.ts | 4 +- src/utils/array.spec.ts | 2 + src/utils/errno.spec.ts | 2 + src/utils/fs.spec.ts | 1 + src/utils/fs.ts | 2 +- src/utils/path.spec.ts | 116 +++++++++++----------- src/utils/path.ts | 4 +- src/utils/pattern.spec.ts | 8 +- src/utils/stream.spec.ts | 2 + src/utils/string.spec.ts | 2 + 35 files changed, 147 insertions(+), 90 deletions(-) create mode 100644 eslint.config.mjs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7c42c234..1e4fac31 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,6 +35,7 @@ jobs: run: npm install - name: Run Hygiene Checks run: npm run lint + if: ${{ matrix.node_version >= 18 }} - name: Prepare bundle run: npm run bundle - name: Run unit tests diff --git a/__snapshots__/absolute.e2e.js b/__snapshots__/absolute.e2e.js index bd140f5b..5dad3665 100644 --- a/__snapshots__/absolute.e2e.js +++ b/__snapshots__/absolute.e2e.js @@ -89,6 +89,7 @@ exports['Options Absolute {"pattern":"fixtures/**/*","options":{"absolute":true} ] exports['Options Absolute {"pattern":"fixtures/../*","options":{"absolute":true}} (sync) 1'] = [ + "/eslint.config.mjs", "/herebyfile.mjs", "/LICENSE", "/package.json", @@ -97,6 +98,7 @@ exports['Options Absolute {"pattern":"fixtures/../*","options":{"absolute":true} ] exports['Options Absolute {"pattern":"fixtures/../*","options":{"absolute":true}} (async) 1'] = [ + "/eslint.config.mjs", "/herebyfile.mjs", "/LICENSE", "/package.json", @@ -105,6 +107,7 @@ exports['Options Absolute {"pattern":"fixtures/../*","options":{"absolute":true} ] exports['Options Absolute {"pattern":"fixtures/../*","options":{"absolute":true}} (stream) 1'] = [ + "/eslint.config.mjs", "/herebyfile.mjs", "/LICENSE", "/package.json", diff --git a/__snapshots__/regular.e2e.js b/__snapshots__/regular.e2e.js index c1d936bd..b53f44b6 100644 --- a/__snapshots__/regular.e2e.js +++ b/__snapshots__/regular.e2e.js @@ -5492,6 +5492,7 @@ exports['Patterns Regular (segmented lists) {"pattern":"{book.xml,library/**/a/b ] exports['Patterns Regular (relative) {"pattern":"./*","options":{}} (sync) 1'] = [ + "eslint.config.mjs", "herebyfile.mjs", "LICENSE", "package.json", @@ -5500,6 +5501,7 @@ exports['Patterns Regular (relative) {"pattern":"./*","options":{}} (sync) 1'] = ] exports['Patterns Regular (relative) {"pattern":"./*","options":{}} (async) 1'] = [ + "eslint.config.mjs", "herebyfile.mjs", "LICENSE", "package.json", @@ -5508,6 +5510,7 @@ exports['Patterns Regular (relative) {"pattern":"./*","options":{}} (async) 1'] ] exports['Patterns Regular (relative) {"pattern":"./*","options":{}} (stream) 1'] = [ + "eslint.config.mjs", "herebyfile.mjs", "LICENSE", "package.json", diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 00000000..51a373d5 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,8 @@ +import cfg from 'eslint-config-mrmlnc'; + +/** @type {import('eslint').Linter.Config[]} */ +const overrides = [ + ...cfg.build({}), +]; + +export default overrides; diff --git a/package.json b/package.json index 2a795766..b54ff0d9 100644 --- a/package.json +++ b/package.json @@ -36,8 +36,8 @@ "@types/sinon": "^17.0.3", "bencho": "^0.1.1", "esbuild": "^0.24.0", - "eslint": "^8.53.0", - "eslint-config-mrmlnc": "^4.1.0", + "eslint": "9.14.0", + "eslint-config-mrmlnc": "^5.0.0", "execa": "^7.2.0", "fast-glob": "^3.3.2", "fdir": "^6.4.2", diff --git a/src/benchmark/suites/product/stream.ts b/src/benchmark/suites/product/stream.ts index 490b1384..f57aae99 100644 --- a/src/benchmark/suites/product/stream.ts +++ b/src/benchmark/suites/product/stream.ts @@ -29,7 +29,7 @@ class Glob { const action = new Promise((resolve, reject) => { stream.on('error', (error) => { - reject(error); + reject(error as Error); }); stream.on('data', (entry: string) => entries.push(entry)); stream.on('end', () => { @@ -52,7 +52,7 @@ class Glob { }); const action = new Promise((resolve, reject) => { - stream.once('error', (error) => { + stream.once('error', (error: Error) => { reject(error); }); stream.on('data', (entry: string) => entries.push(entry)); diff --git a/src/benchmark/suites/regression/stream.ts b/src/benchmark/suites/regression/stream.ts index d22fdeb0..25d3f1b8 100644 --- a/src/benchmark/suites/regression/stream.ts +++ b/src/benchmark/suites/regression/stream.ts @@ -8,7 +8,7 @@ import type * as fastGlobCurrent from '../../..'; type GlobImplementation = 'current' | 'previous'; // eslint-disable-next-line @typescript-eslint/no-explicit-any -type GlobImplFunction = (...args: any[]) => ReturnType; +type GlobImplFunction = (...args: any[]) => ReturnType; type GlobOptions = fastGlobCurrent.Options; class Glob { @@ -45,7 +45,7 @@ class Glob { await new Promise((resolve, reject) => { const stream = function_(); - stream.once('error', (error) => { + stream.once('error', (error: Error) => { reject(error); }); stream.on('data', (entry: string) => entries.push(entry)); diff --git a/src/index.spec.ts b/src/index.spec.ts index 98882d4c..3ff3c7df 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -1,5 +1,7 @@ import * as assert from 'node:assert'; +import { describe, it } from 'mocha'; + import * as tests from './tests'; import * as fg from '.'; @@ -57,7 +59,7 @@ describe('Package', () => { describe('.sync', () => { it('should be an alias for the .globSync method', () => { - // eslint-disable-next-line import/no-deprecated + // eslint-disable-next-line import/no-deprecated, @typescript-eslint/no-deprecated assert.strictEqual(fg.sync, fg.globSync); }); }); @@ -110,7 +112,7 @@ describe('Package', () => { describe('.async', () => { it('should be an alias for the .glob method', () => { - // eslint-disable-next-line import/no-deprecated + // eslint-disable-next-line import/no-deprecated, @typescript-eslint/no-deprecated assert.strictEqual(fg.async, fg.glob); }); }); @@ -177,7 +179,7 @@ describe('Package', () => { describe('.stream', () => { it('should be an alias for the .globStream method', () => { - // eslint-disable-next-line import/no-deprecated + // eslint-disable-next-line import/no-deprecated, @typescript-eslint/no-deprecated assert.strictEqual(fg.stream, fg.globStream); }); }); @@ -234,7 +236,7 @@ describe('Package', () => { describe('.escapePath', () => { it('should return escaped path', () => { - const expected = 'C:/Program Files \\(x86\\)'; + const expected = String.raw`C:/Program Files \(x86\)`; const actual = fg.escapePath('C:/Program Files (x86)'); @@ -245,11 +247,11 @@ describe('Package', () => { describe('.convertPathToPattern', () => { it('should return a pattern', () => { // In posix system \\ is a escaping character and it will be escaped before non-special characters. - const posix = 'C:\\\\Program Files \\(x86\\)\\*\\*\\*'; - const windows = 'C:/Program Files \\(x86\\)/**/*'; + const posix = String.raw`C:\\Program Files \(x86\)\*\*\*`; + const windows = String.raw`C:/Program Files \(x86\)/**/*`; const expected = tests.platform.isWindows() ? windows : posix; - const actual = fg.convertPathToPattern('C:\\Program Files (x86)\\**\\*'); + const actual = fg.convertPathToPattern(String.raw`C:\Program Files (x86)\**\*`); assert.strictEqual(actual, expected); }); @@ -258,9 +260,9 @@ describe('Package', () => { describe('posix', () => { describe('.escapePath', () => { it('should return escaped path', () => { - const expected = '/directory/\\*\\*/\\*'; + const expected = String.raw`/directory/\*\*/\*`; - const actual = fg.posix.escapePath('/directory/*\\*/*'); + const actual = fg.posix.escapePath(String.raw`/directory/*\*/*`); assert.strictEqual(actual, expected); }); @@ -268,9 +270,9 @@ describe('Package', () => { describe('.convertPathToPattern', () => { it('should return a pattern', () => { - const expected = 'a\\*.txt'; + const expected = String.raw`a\*.txt`; - const actual = fg.posix.convertPathToPattern('a\\*.txt'); + const actual = fg.posix.convertPathToPattern(String.raw`a\*.txt`); assert.strictEqual(actual, expected); }); @@ -280,9 +282,9 @@ describe('Package', () => { describe('win32', () => { describe('.escapePath', () => { it('should return escaped path', () => { - const expected = 'C:\\Program Files \\(x86\\)\\**\\*'; + const expected = String.raw`C:\Program Files \(x86\)\**\*`; - const actual = fg.win32.escapePath('C:\\Program Files (x86)\\**\\*'); + const actual = fg.win32.escapePath(String.raw`C:\Program Files (x86)\**\*`); assert.strictEqual(actual, expected); }); @@ -290,9 +292,9 @@ describe('Package', () => { describe('.convertPathToPattern', () => { it('should return a pattern', () => { - const expected = 'C:/Program Files \\(x86\\)/**/*'; + const expected = String.raw`C:/Program Files \(x86\)/**/*`; - const actual = fg.win32.convertPathToPattern('C:\\Program Files (x86)\\**\\*'); + const actual = fg.win32.convertPathToPattern(String.raw`C:\Program Files (x86)\**\*`); assert.strictEqual(actual, expected); }); diff --git a/src/managers/tasks.spec.ts b/src/managers/tasks.spec.ts index 7033b921..49081971 100644 --- a/src/managers/tasks.spec.ts +++ b/src/managers/tasks.spec.ts @@ -1,5 +1,7 @@ import * as assert from 'node:assert'; +import { describe, it } from 'mocha'; + import Settings from '../settings'; import * as tests from '../tests'; import * as manager from './tasks'; diff --git a/src/providers/async.spec.ts b/src/providers/async.spec.ts index d8a69349..3f58c7fe 100644 --- a/src/providers/async.spec.ts +++ b/src/providers/async.spec.ts @@ -1,6 +1,7 @@ import * as assert from 'node:assert'; import * as sinon from 'sinon'; +import { describe, it } from 'mocha'; import Settings from '../settings'; import * as tests from '../tests'; diff --git a/src/providers/filters/deep.spec.ts b/src/providers/filters/deep.spec.ts index dd399af9..ec5049b1 100644 --- a/src/providers/filters/deep.spec.ts +++ b/src/providers/filters/deep.spec.ts @@ -1,5 +1,7 @@ import * as assert from 'node:assert'; +import { describe, it } from 'mocha'; + import Settings from '../../settings'; import * as tests from '../../tests'; import DeepFilter from './deep'; diff --git a/src/providers/filters/entry.spec.ts b/src/providers/filters/entry.spec.ts index 10e1eb79..c504a0e1 100644 --- a/src/providers/filters/entry.spec.ts +++ b/src/providers/filters/entry.spec.ts @@ -1,6 +1,8 @@ import * as assert from 'node:assert'; import * as path from 'node:path'; +import { describe, it } from 'mocha'; + import Settings from '../../settings'; import * as tests from '../../tests'; import EntryFilter from './entry'; diff --git a/src/providers/filters/error.spec.ts b/src/providers/filters/error.spec.ts index ea367531..2079b55a 100644 --- a/src/providers/filters/error.spec.ts +++ b/src/providers/filters/error.spec.ts @@ -1,5 +1,7 @@ import * as assert from 'node:assert'; +import { describe, it } from 'mocha'; + import Settings from '../../settings'; import * as tests from '../../tests'; import ErrorFilter from './error'; diff --git a/src/providers/matchers/matcher.spec.ts b/src/providers/matchers/matcher.spec.ts index b8fcacc7..4a9aa2d0 100644 --- a/src/providers/matchers/matcher.spec.ts +++ b/src/providers/matchers/matcher.spec.ts @@ -1,5 +1,7 @@ import * as assert from 'node:assert'; +import { describe, it } from 'mocha'; + import * as tests from '../../tests'; import Settings from '../../settings'; import Matcher from './matcher'; diff --git a/src/providers/matchers/partial.spec.ts b/src/providers/matchers/partial.spec.ts index 211236c4..d6c76d66 100644 --- a/src/providers/matchers/partial.spec.ts +++ b/src/providers/matchers/partial.spec.ts @@ -1,5 +1,7 @@ import * as assert from 'node:assert'; +import { describe, it } from 'mocha'; + import Settings from '../../settings'; import Matcher from './partial'; diff --git a/src/providers/provider.spec.ts b/src/providers/provider.spec.ts index bfbaa25e..fd2f8b7c 100644 --- a/src/providers/provider.spec.ts +++ b/src/providers/provider.spec.ts @@ -1,6 +1,8 @@ import * as assert from 'node:assert'; import * as path from 'node:path'; +import { describe, it } from 'mocha'; + import Settings from '../settings'; import * as tests from '../tests'; import { Provider } from './provider'; @@ -78,7 +80,7 @@ describe('Providers → Provider', () => { assert.strictEqual(typeof actual.deepFilter, 'function'); assert.strictEqual(typeof actual.entryFilter, 'function'); assert.strictEqual(typeof actual.errorFilter, 'function'); - assert.ok(actual.followSymbolicLinks); + assert.strictEqual(actual.followSymbolicLinks, true); assert.strictEqual(typeof actual.fs, 'object'); assert.ok(!actual.stats); assert.ok(actual.throwErrorOnBrokenSymbolicLink === false); diff --git a/src/providers/stream.spec.ts b/src/providers/stream.spec.ts index 8ac0199d..20438ff9 100644 --- a/src/providers/stream.spec.ts +++ b/src/providers/stream.spec.ts @@ -2,6 +2,7 @@ import * as assert from 'node:assert'; import { PassThrough } from 'node:stream'; import * as sinon from 'sinon'; +import { describe, it } from 'mocha'; import Settings from '../settings'; import * as tests from '../tests'; diff --git a/src/providers/sync.spec.ts b/src/providers/sync.spec.ts index 557dbfea..ed1ffb2c 100644 --- a/src/providers/sync.spec.ts +++ b/src/providers/sync.spec.ts @@ -1,6 +1,7 @@ import * as assert from 'node:assert'; import * as sinon from 'sinon'; +import { describe, it } from 'mocha'; import { ReaderSync } from '../readers'; import Settings from '../settings'; diff --git a/src/providers/transformers/entry.spec.ts b/src/providers/transformers/entry.spec.ts index a976d3a4..445fd561 100644 --- a/src/providers/transformers/entry.spec.ts +++ b/src/providers/transformers/entry.spec.ts @@ -1,6 +1,8 @@ import * as assert from 'node:assert'; import * as path from 'node:path'; +import { describe, it } from 'mocha'; + import Settings from '../../settings'; import * as tests from '../../tests'; import EntryTransformer from './entry'; diff --git a/src/readers/async.spec.ts b/src/readers/async.spec.ts index 6171d7c6..9a020cee 100644 --- a/src/readers/async.spec.ts +++ b/src/readers/async.spec.ts @@ -2,6 +2,7 @@ import * as assert from 'node:assert'; import { PassThrough } from 'node:stream'; import * as sinon from 'sinon'; +import { describe, it } from 'mocha'; import Settings from '../settings'; import * as tests from '../tests'; diff --git a/src/readers/reader.spec.ts b/src/readers/reader.spec.ts index f3794d62..211d95e5 100644 --- a/src/readers/reader.spec.ts +++ b/src/readers/reader.spec.ts @@ -2,6 +2,7 @@ import * as assert from 'node:assert'; import * as path from 'node:path'; import { Stats, StatsMode } from '@nodelib/fs.macchiato'; +import { describe, it } from 'mocha'; import Settings from '../settings'; import { Reader } from './reader'; diff --git a/src/readers/stream.spec.ts b/src/readers/stream.spec.ts index b23178ee..1a08aa69 100644 --- a/src/readers/stream.spec.ts +++ b/src/readers/stream.spec.ts @@ -2,6 +2,7 @@ import * as assert from 'node:assert'; import { Stats } from '@nodelib/fs.macchiato'; import * as sinon from 'sinon'; +import { describe, it } from 'mocha'; import Settings from '../settings'; import * as tests from '../tests'; diff --git a/src/readers/sync.spec.ts b/src/readers/sync.spec.ts index 0723f909..92d7ef8f 100644 --- a/src/readers/sync.spec.ts +++ b/src/readers/sync.spec.ts @@ -2,6 +2,7 @@ import * as assert from 'node:assert'; import { Stats } from '@nodelib/fs.macchiato'; import * as sinon from 'sinon'; +import { describe, it } from 'mocha'; import Settings from '../settings'; import * as tests from '../tests'; diff --git a/src/settings.spec.ts b/src/settings.spec.ts index 40b61298..e707138c 100644 --- a/src/settings.spec.ts +++ b/src/settings.spec.ts @@ -1,5 +1,7 @@ import * as assert from 'node:assert'; +import { describe, it } from 'mocha'; + import Settings, { DEFAULT_FILE_SYSTEM_ADAPTER } from './settings'; describe('Settings', () => { diff --git a/src/tests/e2e/runner.ts b/src/tests/e2e/runner.ts index eb45caf1..b0707430 100644 --- a/src/tests/e2e/runner.ts +++ b/src/tests/e2e/runner.ts @@ -1,6 +1,8 @@ +/* eslint-disable mocha/no-setup-in-describe */ import * as assert from 'node:assert'; import snapshotIt from 'snap-shot-it'; +import { describe, it } from 'mocha'; import * as fg from '../..'; @@ -15,7 +17,7 @@ interface Suite { /** * Allow to run only one test case with debug information. */ - debug?: fg.Options | boolean; + debug?: boolean | fg.Options; /** * The ability to conditionally run the test. */ @@ -29,7 +31,7 @@ interface Test { /** * Allow to run only one test case with debug information. */ - debug?: fg.Options | boolean; + debug?: boolean | fg.Options; /** * The ability to conditionally run the test. */ @@ -38,7 +40,7 @@ interface Test { /** * The issue related to this test. */ - issue?: number[] | number; + issue?: number | number[]; expected?: () => string[]; } diff --git a/src/types/index.ts b/src/types/index.ts index 24d0f900..25d97676 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -14,14 +14,14 @@ export type Pattern = string; export type PatternRe = RegExp; export type PatternsGroup = Dictionary; -export type ReaderOptions = 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; diff --git a/src/utils/array.spec.ts b/src/utils/array.spec.ts index 925d5005..669efcb8 100644 --- a/src/utils/array.spec.ts +++ b/src/utils/array.spec.ts @@ -1,5 +1,7 @@ import * as assert from 'node:assert'; +import { describe, it } from 'mocha'; + import * as util from './array'; describe('Utils → Array', () => { diff --git a/src/utils/errno.spec.ts b/src/utils/errno.spec.ts index dd642b82..2c9937c7 100644 --- a/src/utils/errno.spec.ts +++ b/src/utils/errno.spec.ts @@ -1,5 +1,7 @@ import * as assert from 'node:assert'; +import { describe, it } from 'mocha'; + import * as tests from '../tests'; import * as util from './errno'; diff --git a/src/utils/fs.spec.ts b/src/utils/fs.spec.ts index 99a15a35..45745d0d 100644 --- a/src/utils/fs.spec.ts +++ b/src/utils/fs.spec.ts @@ -1,6 +1,7 @@ import * as assert from 'node:assert'; import { Stats, StatsMode } from '@nodelib/fs.macchiato'; +import { describe, it } from 'mocha'; import * as util from './fs'; diff --git a/src/utils/fs.ts b/src/utils/fs.ts index f3c1758b..957314ff 100644 --- a/src/utils/fs.ts +++ b/src/utils/fs.ts @@ -21,7 +21,7 @@ export class DirentFromStats extends fs.Dirent { } for (const key of Reflect.ownKeys(fs.Dirent.prototype)) { - const name = key as DirentStatsKeysIntersection | 'constructor'; + const name = key as 'constructor' | DirentStatsKeysIntersection; if (name === 'constructor') { continue; diff --git a/src/utils/path.spec.ts b/src/utils/path.spec.ts index 661786ce..28c39dd0 100644 --- a/src/utils/path.spec.ts +++ b/src/utils/path.spec.ts @@ -1,6 +1,8 @@ import * as assert from 'node:assert'; import * as path from 'node:path'; +import { describe, it } from 'mocha'; + import * as util from './path'; describe('Utils → Path', () => { @@ -16,9 +18,9 @@ describe('Utils → Path', () => { describe('.escape', () => { it('should return pattern without additional escape characters', () => { - assert.strictEqual(util.escape('\\!abc'), '\\!abc'); - assert.strictEqual(util.escape('\\*'), '\\*'); - assert.strictEqual(util.escape('\\!\\('), '\\!\\('); + assert.strictEqual(util.escape(String.raw`\!abc`), String.raw`\!abc`); + assert.strictEqual(util.escape(String.raw`\*`), String.raw`\*`); + assert.strictEqual(util.escape(String.raw`\!\(`), String.raw`\!\(`); }); it('should return pattern without escape characters', () => { @@ -33,30 +35,30 @@ describe('Utils → Path', () => { describe('.escapePosixPattern', () => { it('should return pattern with escaped glob symbols', () => { - assert.strictEqual(util.escapePosixPath('!abc'), '\\!abc'); - assert.strictEqual(util.escapePosixPath('*'), '\\*'); - assert.strictEqual(util.escapePosixPath('?'), '\\?'); + assert.strictEqual(util.escapePosixPath('!abc'), String.raw`\!abc`); + assert.strictEqual(util.escapePosixPath('*'), String.raw`\*`); + assert.strictEqual(util.escapePosixPath('?'), String.raw`\?`); assert.strictEqual(util.escapePosixPath('\\'), '\\\\'); - assert.strictEqual(util.escapePosixPath('()'), '\\(\\)'); - assert.strictEqual(util.escapePosixPath('{}'), '\\{\\}'); - assert.strictEqual(util.escapePosixPath('[]'), '\\[\\]'); - assert.strictEqual(util.escapePosixPath('@('), '\\@\\('); - assert.strictEqual(util.escapePosixPath('!('), '\\!\\('); - assert.strictEqual(util.escapePosixPath('*('), '\\*\\('); - assert.strictEqual(util.escapePosixPath('?('), '\\?\\('); - assert.strictEqual(util.escapePosixPath('+('), '\\+\\('); + assert.strictEqual(util.escapePosixPath('()'), String.raw`\(\)`); + assert.strictEqual(util.escapePosixPath('{}'), String.raw`\{\}`); + assert.strictEqual(util.escapePosixPath('[]'), String.raw`\[\]`); + assert.strictEqual(util.escapePosixPath('@('), String.raw`\@\(`); + assert.strictEqual(util.escapePosixPath('!('), String.raw`\!\(`); + assert.strictEqual(util.escapePosixPath('*('), String.raw`\*\(`); + assert.strictEqual(util.escapePosixPath('?('), String.raw`\?\(`); + assert.strictEqual(util.escapePosixPath('+('), String.raw`\+\(`); }); }); describe('.escapeWindowsPattern', () => { it('should return pattern with escaped glob symbols', () => { - assert.strictEqual(util.escapeWindowsPath('!abc'), '\\!abc'); - assert.strictEqual(util.escapeWindowsPath('()'), '\\(\\)'); - assert.strictEqual(util.escapeWindowsPath('{}'), '\\{\\}'); - assert.strictEqual(util.escapeWindowsPath('[]'), '\\[\\]'); - assert.strictEqual(util.escapeWindowsPath('@('), '\\@\\('); - assert.strictEqual(util.escapeWindowsPath('!('), '\\!\\('); - assert.strictEqual(util.escapeWindowsPath('+('), '\\+\\('); + assert.strictEqual(util.escapeWindowsPath('!abc'), String.raw`\!abc`); + assert.strictEqual(util.escapeWindowsPath('()'), String.raw`\(\)`); + assert.strictEqual(util.escapeWindowsPath('{}'), String.raw`\{\}`); + assert.strictEqual(util.escapeWindowsPath('[]'), String.raw`\[\]`); + assert.strictEqual(util.escapeWindowsPath('@('), String.raw`\@\(`); + assert.strictEqual(util.escapeWindowsPath('!('), String.raw`\!\(`); + assert.strictEqual(util.escapeWindowsPath('+('), String.raw`\+\(`); }); }); @@ -67,76 +69,76 @@ describe('Utils → Path', () => { assert.strictEqual(util.removeLeadingDotSegment('/a/b'), '/a/b'); assert.strictEqual(util.removeLeadingDotSegment('a/b'), 'a/b'); - assert.strictEqual(util.removeLeadingDotSegment('..\\a\\b'), '..\\a\\b'); - assert.strictEqual(util.removeLeadingDotSegment('~\\a\\b'), '~\\a\\b'); - assert.strictEqual(util.removeLeadingDotSegment('\\a\\b'), '\\a\\b'); - assert.strictEqual(util.removeLeadingDotSegment('a\\b'), 'a\\b'); + assert.strictEqual(util.removeLeadingDotSegment(String.raw`..\a\b`), String.raw`..\a\b`); + assert.strictEqual(util.removeLeadingDotSegment(String.raw`~\a\b`), String.raw`~\a\b`); + assert.strictEqual(util.removeLeadingDotSegment(String.raw`\a\b`), String.raw`\a\b`); + assert.strictEqual(util.removeLeadingDotSegment(String.raw`a\b`), String.raw`a\b`); }); it('should return path without leading dit characters', () => { assert.strictEqual(util.removeLeadingDotSegment('./a/b'), 'a/b'); - assert.strictEqual(util.removeLeadingDotSegment('.\\a\\b'), 'a\\b'); + assert.strictEqual(util.removeLeadingDotSegment(String.raw`.\a\b`), String.raw`a\b`); }); }); describe('.convertPathToPattern', () => { it('should return a pattern', () => { - assert.strictEqual(util.convertPathToPattern('.{directory}'), '.\\{directory\\}'); + assert.strictEqual(util.convertPathToPattern('.{directory}'), String.raw`.\{directory\}`); }); }); describe('.convertPosixPathToPattern', () => { it('should escape special characters', () => { - assert.strictEqual(util.convertPosixPathToPattern('./**\\*'), './\\*\\*\\*'); + assert.strictEqual(util.convertPosixPathToPattern(String.raw`./**\*`), String.raw`./\*\*\*`); }); }); describe('.convertWindowsPathToPattern', () => { it('should escape special characters', () => { - assert.strictEqual(util.convertPosixPathToPattern('.{directory}'), '.\\{directory\\}'); + assert.strictEqual(util.convertPosixPathToPattern('.{directory}'), String.raw`.\{directory\}`); }); it('should do nothing with escaped glob symbols', () => { - assert.strictEqual(util.convertWindowsPathToPattern('\\!\\'), '\\!/'); - assert.strictEqual(util.convertWindowsPathToPattern('\\+\\'), '\\+/'); - assert.strictEqual(util.convertWindowsPathToPattern('\\@\\'), '\\@/'); - assert.strictEqual(util.convertWindowsPathToPattern('\\(\\'), '\\(/'); - assert.strictEqual(util.convertWindowsPathToPattern('\\)\\'), '\\)/'); - assert.strictEqual(util.convertWindowsPathToPattern('\\{\\'), '\\{/'); - assert.strictEqual(util.convertWindowsPathToPattern('\\}\\'), '\\}/'); - assert.strictEqual(util.convertWindowsPathToPattern('\\[\\'), '\\[/'); - assert.strictEqual(util.convertWindowsPathToPattern('\\]\\'), '\\]/'); + assert.strictEqual(util.convertWindowsPathToPattern('\\!\\'), String.raw`\!/`); + assert.strictEqual(util.convertWindowsPathToPattern('\\+\\'), String.raw`\+/`); + assert.strictEqual(util.convertWindowsPathToPattern('\\@\\'), String.raw`\@/`); + assert.strictEqual(util.convertWindowsPathToPattern('\\(\\'), String.raw`\(/`); + assert.strictEqual(util.convertWindowsPathToPattern('\\)\\'), String.raw`\)/`); + assert.strictEqual(util.convertWindowsPathToPattern('\\{\\'), String.raw`\{/`); + assert.strictEqual(util.convertWindowsPathToPattern('\\}\\'), String.raw`\}/`); + assert.strictEqual(util.convertWindowsPathToPattern('\\[\\'), String.raw`\[/`); + assert.strictEqual(util.convertWindowsPathToPattern('\\]\\'), String.raw`\]/`); - assert.strictEqual(util.convertWindowsPathToPattern('.\\*'), './*'); - assert.strictEqual(util.convertWindowsPathToPattern('.\\**'), './**'); - assert.strictEqual(util.convertWindowsPathToPattern('.\\**\\*'), './**/*'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`.\*`), './*'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`.\**`), './**'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`.\**\*`), './**/*'); - assert.strictEqual(util.convertWindowsPathToPattern('a\\{b,c\\d,{b,c}}'), 'a\\{b,c/d,\\{b,c\\}\\}'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`a\{b,c\d,{b,c}}`), String.raw`a\{b,c/d,\{b,c\}\}`); }); it('should convert slashes', () => { assert.strictEqual(util.convertWindowsPathToPattern('/'), '/'); assert.strictEqual(util.convertWindowsPathToPattern('\\'), '/'); assert.strictEqual(util.convertWindowsPathToPattern('\\\\'), '//'); - assert.strictEqual(util.convertWindowsPathToPattern('\\/'), '//'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`\/`), '//'); assert.strictEqual(util.convertWindowsPathToPattern('\\/\\'), '///'); }); it('should convert relative paths', () => { assert.strictEqual(util.convertWindowsPathToPattern('file.txt'), 'file.txt'); assert.strictEqual(util.convertWindowsPathToPattern('./file.txt'), './file.txt'); - assert.strictEqual(util.convertWindowsPathToPattern('.\\file.txt'), './file.txt'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`.\file.txt`), './file.txt'); assert.strictEqual(util.convertWindowsPathToPattern('../file.txt'), '../file.txt'); - assert.strictEqual(util.convertWindowsPathToPattern('..\\file.txt'), '../file.txt'); - assert.strictEqual(util.convertWindowsPathToPattern('.\\file.txt'), './file.txt'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`..\file.txt`), '../file.txt'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`.\file.txt`), './file.txt'); }); it('should convert absolute paths', () => { assert.strictEqual(util.convertWindowsPathToPattern('/.file.txt'), '/.file.txt'); assert.strictEqual(util.convertWindowsPathToPattern('/root/.file.txt'), '/root/.file.txt'); - assert.strictEqual(util.convertWindowsPathToPattern('\\.file.txt'), '/.file.txt'); - assert.strictEqual(util.convertWindowsPathToPattern('\\root\\.file.txt'), '/root/.file.txt'); - assert.strictEqual(util.convertWindowsPathToPattern('\\root/.file.txt'), '/root/.file.txt'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`\.file.txt`), '/.file.txt'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`\root\.file.txt`), '/root/.file.txt'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`\root/.file.txt`), '/root/.file.txt'); }); it('should convert traditional DOS paths', () => { @@ -144,20 +146,20 @@ describe('Utils → Path', () => { assert.strictEqual(util.convertWindowsPathToPattern('D:/ShipId.txt'), 'D:/ShipId.txt'); assert.strictEqual(util.convertWindowsPathToPattern('D://ShipId.txt'), 'D://ShipId.txt'); - assert.strictEqual(util.convertWindowsPathToPattern('D:\\ShipId.txt'), 'D:/ShipId.txt'); - assert.strictEqual(util.convertWindowsPathToPattern('D:\\\\ShipId.txt'), 'D://ShipId.txt'); - assert.strictEqual(util.convertWindowsPathToPattern('D:\\/ShipId.txt'), 'D://ShipId.txt'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`D:\ShipId.txt`), 'D:/ShipId.txt'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`D:\\ShipId.txt`), 'D://ShipId.txt'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`D:\/ShipId.txt`), 'D://ShipId.txt'); }); it('should convert UNC paths', () => { assert.strictEqual(util.convertWindowsPathToPattern('\\\\system07\\'), '//system07/'); assert.strictEqual(util.convertWindowsPathToPattern('\\\\system07\\c$\\'), '//system07/c$/'); - assert.strictEqual(util.convertWindowsPathToPattern('\\\\Server02\\Share\\Foo.txt'), '//Server02/Share/Foo.txt'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`\\Server02\Share\Foo.txt`), '//Server02/Share/Foo.txt'); - assert.strictEqual(util.convertWindowsPathToPattern('\\\\127.0.0.1\\c$\\File.txt'), '//127.0.0.1/c$/File.txt'); - assert.strictEqual(util.convertWindowsPathToPattern('\\\\.\\c:\\File.txt'), '//./c:/File.txt'); - assert.strictEqual(util.convertWindowsPathToPattern('\\\\?\\c:\\File.txt'), '//?/c:/File.txt'); - assert.strictEqual(util.convertWindowsPathToPattern('\\\\.\\UNC\\LOCALHOST\\c$\\File.txt'), '//./UNC/LOCALHOST/c$/File.txt'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`\\127.0.0.1\c$\File.txt`), '//127.0.0.1/c$/File.txt'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`\\.\c:\File.txt`), '//./c:/File.txt'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`\\?\c:\File.txt`), '//?/c:/File.txt'); + assert.strictEqual(util.convertWindowsPathToPattern(String.raw`\\.\UNC\LOCALHOST\c$\File.txt`), '//./UNC/LOCALHOST/c$/File.txt'); }); }); }); diff --git a/src/utils/path.ts b/src/utils/path.ts index e9f6dd0b..5ac8f837 100644 --- a/src/utils/path.ts +++ b/src/utils/path.ts @@ -45,11 +45,11 @@ export function removeLeadingDotSegment(entry: string): string { export const escape = IS_WINDOWS_PLATFORM ? escapeWindowsPath : escapePosixPath; export function escapeWindowsPath(pattern: Pattern): Pattern { - return pattern.replaceAll(WINDOWS_UNESCAPED_GLOB_SYMBOLS_RE, '\\$2'); + return pattern.replaceAll(WINDOWS_UNESCAPED_GLOB_SYMBOLS_RE, String.raw`\$2`); } export function escapePosixPath(pattern: Pattern): Pattern { - return pattern.replaceAll(POSIX_UNESCAPED_GLOB_SYMBOLS_RE, '\\$2'); + return pattern.replaceAll(POSIX_UNESCAPED_GLOB_SYMBOLS_RE, String.raw`\$2`); } export const convertPathToPattern = IS_WINDOWS_PLATFORM ? convertWindowsPathToPattern : convertPosixPathToPattern; diff --git a/src/utils/pattern.spec.ts b/src/utils/pattern.spec.ts index beea2977..8ef3e80e 100644 --- a/src/utils/pattern.spec.ts +++ b/src/utils/pattern.spec.ts @@ -1,5 +1,7 @@ import * as assert from 'node:assert'; +import { describe, it } from 'mocha'; + import * as util from './pattern'; import type { Pattern } from '../types'; @@ -337,7 +339,7 @@ describe('Utils → Pattern', () => { it('should returns base directory without slash transformation', () => { const expected = '.'; - const actual = util.getBaseDirectory('file-\\(suffix\\).md'); + const actual = util.getBaseDirectory(String.raw`file-\(suffix\).md`); assert.strictEqual(actual, expected); }); @@ -433,9 +435,9 @@ describe('Utils → Pattern', () => { }); it('should keep escaping after expansion', () => { - const expected = ['foo@(\\\\)/**/*.a', 'foo@(\\\\)/**/*.b']; + const expected = [String.raw`foo@(\\)/**/*.a`, String.raw`foo@(\\)/**/*.b`]; - const actual = util.expandBraceExpansion('foo@(\\\\)/**/{*.a,*.b}'); + const actual = util.expandBraceExpansion(String.raw`foo@(\\)/**/{*.a,*.b}`); assert.deepStrictEqual(actual, expected); }); diff --git a/src/utils/stream.spec.ts b/src/utils/stream.spec.ts index 00900717..0525e818 100644 --- a/src/utils/stream.spec.ts +++ b/src/utils/stream.spec.ts @@ -1,6 +1,8 @@ import * as assert from 'node:assert'; import * as stream from 'node:stream'; +import { describe, it } from 'mocha'; + import * as util from './stream'; describe('Utils → Stream', () => { diff --git a/src/utils/string.spec.ts b/src/utils/string.spec.ts index c1e886bd..cfd2ee34 100644 --- a/src/utils/string.spec.ts +++ b/src/utils/string.spec.ts @@ -1,5 +1,7 @@ import * as assert from 'node:assert'; +import { describe, it } from 'mocha'; + import * as util from './string'; describe('Utils → String', () => {