Skip to content

Commit

Permalink
fix: remove vscode-uri shim (#4902)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Oct 13, 2023
1 parent 333c2e5 commit 93f055e
Show file tree
Hide file tree
Showing 19 changed files with 625 additions and 228 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jest": "^27.4.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-unicorn": "^48.0.1",
Expand Down
7 changes: 4 additions & 3 deletions packages/cspell-eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@
"@types/eslint": "^8.44.3",
"@types/estree": "^1.0.2",
"@types/mocha": "^10.0.2",
"@typescript-eslint/parser": "^5.62.0",
"@typescript-eslint/types": "^6.7.4",
"@typescript-eslint/typescript-estree": "^6.7.4",
"@typescript-eslint/eslint-plugin": "^6.7.5",
"@typescript-eslint/parser": "^6.7.5",
"@typescript-eslint/types": "^6.7.5",
"@typescript-eslint/typescript-estree": "^6.7.5",
"eslint": "^8.51.0",
"eslint-plugin-react": "^7.33.2",
"mocha": "^10.2.0",
Expand Down
9 changes: 7 additions & 2 deletions packages/cspell-eslint-plugin/src/plugin/index.test.cts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const root = path.resolve(__dirname, '../..');
const fixturesDir = path.join(root, 'fixtures');

const parsers: Record<string, string | undefined> = {
'.ts': resolveFromMonoRepo('node_modules/@typescript-eslint/parser'),
// Note: it is possible for @typescript-eslint/parser to break the path
'.ts': resolveFromMonoRepo('@typescript-eslint/parser'),
};

type ValidTestCase = RuleTester.ValidTestCase;
Expand Down Expand Up @@ -204,7 +205,11 @@ ruleTesterReact.run('cspell with React', Rule.rules.spellchecker, {
});

function resolveFromMonoRepo(file: string): string {
return path.resolve(root, file);
const packagePath = require.resolve(file, {
paths: [root],
});
// console.error('resolveFromMonoRepo %o', packagePath);
return packagePath;
}

function resolveFix(filename: string): string {
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-lib/src/lib-cjs/tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"outDir": "../../dist/lib-cjs",
"types": ["node"]
},
"files": ["index.cts", "pkg-info.cts", "vscodeUri.cts"]
"files": ["index.cts", "pkg-info.cts"]
}
3 changes: 0 additions & 3 deletions packages/cspell-lib/src/lib-cjs/vscodeUri.cts

This file was deleted.

26 changes: 16 additions & 10 deletions packages/cspell-lib/src/lib/Settings/DictionarySettings.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import type { DictionaryDefinition, DictionaryDefinitionLegacy } from '@cspell/cspell-types';
import assert from 'assert';
import * as fsp from 'fs/promises';
import * as os from 'os';
import * as path from 'path';
import { describe, expect, test } from 'vitest';

import { isDictionaryDefinitionInlineInternal } from '../Models/CSpellSettingsInternalDef.js';
import { isDefined } from '../util/util.js';
import { getDefaultBundledSettings } from './DefaultSettings.js';
import { createDictionaryReferenceCollection as createRefCol } from './DictionaryReferenceCollection.js';
import * as DictSettings from './DictionarySettings.js';
Expand All @@ -15,11 +16,12 @@ const oc = expect.objectContaining;

describe('Validate DictionarySettings', () => {
test('expects default to not be empty', () => {
assert(defaultSettings.dictionaryDefinitions);
const mapDefs = DictSettings.filterDictDefsToLoad(
createRefCol(['php', 'wordsEn', 'unknown', 'en_us']),
defaultSettings.dictionaryDefinitions!,
defaultSettings.dictionaryDefinitions,
);
const files = mapDefs.map((def) => def.name!);
const files = mapDefs.map((def) => def.name);
expect(mapDefs).toHaveLength(2);
expect(files.filter((a) => a.includes('php'))).toHaveLength(1);
expect(files.filter((a) => a.includes('wordsEn'))).toHaveLength(0);
Expand All @@ -38,8 +40,9 @@ describe('Validate DictionarySettings', () => {
'en_us',
];
const expected = ['php', 'en_us'].sort();
const mapDefs = DictSettings.filterDictDefsToLoad(createRefCol(ids), defaultSettings.dictionaryDefinitions!);
const dicts = mapDefs.map((def) => def.name!).sort();
assert(defaultSettings.dictionaryDefinitions);
const mapDefs = DictSettings.filterDictDefsToLoad(createRefCol(ids), defaultSettings.dictionaryDefinitions);
const dicts = mapDefs.map((def) => def.name).sort();
expect(dicts).toEqual(expected);
});

Expand All @@ -51,18 +54,21 @@ describe('Validate DictionarySettings', () => {
`('validate dictionary exclusions $ids', ({ ids, expected }: { ids: string; expected: string }) => {
const dictIds = createRefCol(ids.split(','));
const expectedIds = expected.split(',').map((id) => id.trim());
const mapDefs = DictSettings.filterDictDefsToLoad(dictIds, defaultSettings.dictionaryDefinitions!);
const dicts = mapDefs.map((def) => def.name!).sort();
assert(defaultSettings.dictionaryDefinitions);
const mapDefs = DictSettings.filterDictDefsToLoad(dictIds, defaultSettings.dictionaryDefinitions);
const dicts = mapDefs.map((def) => def.name).sort();
expect(dicts).toEqual(expectedIds);
});

test('tests that the files exist', () => {
const defaultDicts = defaultSettings.dictionaryDefinitions!;
assert(defaultSettings.dictionaryDefinitions);
const defaultDicts = defaultSettings.dictionaryDefinitions;
const dictIds = createRefCol(defaultDicts.map((def) => def.name));
const mapDefs = DictSettings.filterDictDefsToLoad(dictIds, defaultSettings.dictionaryDefinitions!);
const mapDefs = DictSettings.filterDictDefsToLoad(dictIds, defaultSettings.dictionaryDefinitions);
const access = mapDefs
.filter((def) => !isDictionaryDefinitionInlineInternal(def))
.map((def) => def.path!)
.map((def) => def.path)
.filter(isDefined)
.map((path) => fsp.access(path));
expect(mapDefs.length).toBeGreaterThan(0);
return Promise.all(access);
Expand Down
5 changes: 2 additions & 3 deletions packages/cspell-lib/src/lib/Settings/LanguageSettings.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import type { CSpellUserSettings } from '@cspell/cspell-types';
import { describe, expect, test } from 'vitest';

Expand Down Expand Up @@ -37,12 +36,12 @@ describe('Validate LanguageSettings', () => {
const sPython = calcSettingsForLanguage(languageSettings, 'python', 'en');
expect(sPython.allowCompoundWords).toBeUndefined();
expect(sPython.dictionaries).not.toHaveLength(0);
expect(sPython.dictionaries!).toEqual(expect.arrayContaining(['en_us', 'python', 'django']));
expect(sPython.dictionaries).toEqual(expect.arrayContaining(['en_us', 'python', 'django']));

const sPhp = calcSettingsForLanguage(languageSettings, 'php', 'en-gb');
expect(sPhp.allowCompoundWords).toBeUndefined();
expect(sPhp.dictionaries).not.toHaveLength(0);
expect(sPhp.dictionaries!).toEqual(
expect(sPhp.dictionaries).toEqual(
expect.arrayContaining(['en-gb', 'php', 'html', 'npm', 'fonts', 'css', 'typescript', 'fullstack']),
);
});
Expand Down
3 changes: 1 addition & 2 deletions packages/cspell-lib/src/lib/util/Uri.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import assert from 'assert';

import { URI, Utils } from '../../lib-cjs/vscodeUri.cjs';
import { URI, Utils } from 'vscode-uri';

export interface Uri {
readonly scheme: string;
Expand Down
3 changes: 1 addition & 2 deletions packages/cspell-trie-lib/src/lib/walker/hintedWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ function* hintedWalkerNext(
.filter((a) => a in c)
.map((letter) => ({
letter,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
node: c[letter]!,
node: c[letter],
hintOffset: hintOffset + 1,
}));
// We don't want to suggest the compound character.
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell/src/app/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import * as readline from 'readline';
import stripAnsi from 'strip-ansi';
import * as Util from 'util';
import { afterEach, beforeEach, type Constructable, describe, expect, test, vi } from 'vitest';
import { URI } from 'vscode-uri';

import { URI } from '../lib/uri.cjs';
import * as app from './app.js';
import * as Link from './link.js';
import { pathPackageRoot } from './test/test.helper.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell/src/app/cli-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import chalkTemplate from 'chalk-template';
import type { ImportError, SpellingDictionaryLoadError } from 'cspell-lib';
import { isSpellingDictionaryLoadError } from 'cspell-lib';
import * as path from 'path';
import { URI } from 'vscode-uri';

import { URI } from '../lib/uri.cjs';
import type { LinterCliOptions } from './options.js';
import type { FinalizedReporter } from './util/reporters.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/cspell/src/app/lint/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import type { Logger, ValidationIssue } from 'cspell-lib';
import * as cspell from 'cspell-lib';
import * as path from 'path';
import { format } from 'util';
import { URI } from 'vscode-uri';

import { npmPackage } from '../../lib/pkgInfo.cjs';
import { URI } from '../../lib/uri.cjs';
import { getFeatureFlags } from '../featureFlags/index.js';
import type { CreateCacheSettings, CSpellLintResultCache } from '../util/cache/index.js';
import { calcCacheSettings, createCache } from '../util/cache/index.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell/src/app/util/fileHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { promises as fsp } from 'fs';
import getStdin from 'get-stdin';
import * as path from 'path';
import { fileURLToPath, pathToFileURL } from 'url';
import { URI } from 'vscode-uri';

import { URI } from '../../lib/uri.cjs';
import { asyncAwait, asyncFlatten, asyncMap, asyncPipe, mergeAsyncIterables } from './async.js';
import { FileProtocol, STDIN, STDINProtocol, UTF8 } from './constants.js';
import { IOError, toApplicationError, toError } from './errors.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell/src/lib/tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"outDir": "../../dist/lib",
"types": ["node"]
},
"files": ["./pkgInfo.cts", "./uri.cts", "file-entry-cache.cts"]
"files": ["./pkgInfo.cts", "file-entry-cache.cts"]
}
1 change: 0 additions & 1 deletion packages/cspell/src/lib/uri.cts

This file was deleted.

Loading

0 comments on commit 93f055e

Please sign in to comment.