Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove unused node:path #3449

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/_server/src/config/configTargetsHelper.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { DictionaryDefinitionCustom } from '@cspell/cspell-types';
import { toFileUri, toUri } from '@internal/common-utils/uriHelper';
import { capitalize } from '@internal/common-utils/util';
import * as Path from 'path';

import type { WorkspaceConfigForDocument } from '../api.js';
import type {
Expand Down Expand Up @@ -70,12 +69,16 @@ function* workspaceConfigToTargets(workspaceConfig: WorkspaceConfigForDocument):
}
}

function basename(path: string): string {
return path.split(/[/\\]/g).slice(-1).join('');
}

function cspellToTargets(sources: CSpellSettingsWithFileSource[]): ConfigTargetCSpell[] {
function toTarget(cfg: CSpellSettingsWithFileSource, index: number): ConfigTargetCSpell {
return {
kind: ConfigKinds.Cspell,
scope: ConfigScopes.Unknown,
name: cfg.name || Path.basename(cfg.source.filename),
name: cfg.name || basename(cfg.source.filename),
configUri: toUri(cfg.source.filename).toString(),
has: {
words: cfg.words && true,
Expand Down
8 changes: 0 additions & 8 deletions packages/_server/src/config/documentSettings.mts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import {
mergeSettings,
searchForConfig,
} from 'cspell-lib';
import * as os from 'os';
import * as path from 'path';
import { pathToFileURL } from 'url';
import type { DisposableClassic } from 'utils-disposables';
import type { Connection, WorkspaceFolder } from 'vscode-languageserver/node.js';
Expand Down Expand Up @@ -541,11 +539,6 @@ export class DocumentSettings {
}
}

function resolvePath(...parts: string[]): string {
const normalizedParts = parts.map((part) => (part[0] === '~' ? os.homedir() + part.slice(1) : part));
return path.resolve(...normalizedParts);
}

export function isUriAllowedBySettings(uri: string, settings: CSpellUserSettings): boolean {
const schemes = extractEnabledSchemes(settings);
return doesUriMatchAnyScheme(uri, schemes);
Expand Down Expand Up @@ -641,7 +634,6 @@ export function stringifyPatterns(settings: CSpellUserSettings | undefined): CSp
export const debugExports = {
fixRegEx: fixRegPattern,
fixPattern,
resolvePath,
filterConfigFilesToMatchInheritedPathOfFile,
};

Expand Down
6 changes: 0 additions & 6 deletions packages/_server/src/config/documentSettings.test.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Pattern } from 'cspell-lib';
import * as cspell from 'cspell-lib';
import { getDefaultSettings } from 'cspell-lib';
import * as os from 'os';
import * as Path from 'path';
import { beforeEach, describe, expect, test, vi } from 'vitest';
import type { ConfigurationItem, Connection, WorkspaceFolder } from 'vscode-languageserver/node.js';
Expand Down Expand Up @@ -452,11 +451,6 @@ describe('Validate DocumentSettings', () => {
expect(result.map((f) => f.toString().toLowerCase())).toEqual(expected.map((u) => filePathToUri(u).toString().toLowerCase()));
});

test('resolvePath', () => {
expect(debugExports.resolvePath(__dirname)).toBe(__dirname);
expect(debugExports.resolvePath('~')).toBe(os.homedir());
});

function newDocumentSettings(defaultSettings: CSpellUserSettings = {}) {
const connection = createMockConnection();
const mockWorkspaceGetConfiguration = vi.mocked(connection.workspace.getConfiguration);
Expand Down