Skip to content

Commit

Permalink
Merge dd1a631 into 228975f
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Apr 24, 2023
2 parents 228975f + dd1a631 commit 4172019
Show file tree
Hide file tree
Showing 32 changed files with 596 additions and 1,361 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { readFileSync } from 'fs';
import { join as pathJoin } from 'path';
import { createSyncFn } from 'synckit';

import type { Issue, SpellCheckSyncFn } from '../worker/spellCheck.mjs';
import type { Issue, SpellCheckSyncFn } from '../worker/types';
import { normalizeOptions } from './defaultCheckOptions';

const optionsSchema = JSON.parse(readFileSync(pathJoin(__dirname, '../../assets/options.schema.json'), 'utf8'));
Expand Down Expand Up @@ -99,13 +99,14 @@ function create(context: Rule.RuleContext): Rule.RuleListener {

log('Suggestions: %o', issue.suggestions);

const fixable = issue.suggestions?.filter((sug) => !!sug.isPreferred);
const issueSuggestions = issue.suggestions;
const fixable = issueSuggestions?.filter((sug) => !!sug.isPreferred);
const canFix = fixable?.length === 1;
const preferredSuggestion = autoFix && canFix && fixable[0];
const fix = preferredSuggestion
? fixFactory(preferredSuggestion.wordAdjustedToMatchCase || preferredSuggestion.word)
: nullFix;
const suggestions: Rule.ReportDescriptorOptions['suggest'] = issue.suggestions?.map((sug) => createSug(sug));
const suggestions: Rule.ReportDescriptorOptions['suggest'] = issueSuggestions?.map((sug) => createSug(sug));
const suggest = suggestions;

const des: Rule.ReportDescriptor = {
Expand Down
18 changes: 2 additions & 16 deletions packages/cspell-eslint-plugin/src/worker/spellCheck.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,10 @@ import * as path from 'path';
import { format } from 'util';

import type { CustomWordListFile, WorkerOptions } from '../common/options.js';
import type { ASTNode, JSXText, NodeType } from './ASTNode.mjs';
import type { ASTNode, JSXText, NodeType } from './ASTNode.js';
import type { Issue, Suggestions } from './types.js';
import { walkTree } from './walkTree.mjs';

type Suggestions = ValidationIssue['suggestionsEx'];

export interface Issue {
start: number;
end: number;
word: string;
severity: 'Forbidden' | 'Unknown' | 'Hint';
suggestions: Suggestions;
nodeType: NodeType;
}

const defaultSettings: CSpellSettings = {
patterns: [
// @todo: be able to use cooked / transformed strings.
Expand All @@ -39,10 +29,6 @@ function log(...args: Parameters<typeof console.log>) {
console.log(...args);
}

type SpellCheckFn = typeof spellCheck;

export type SpellCheckSyncFn = (...p: Parameters<SpellCheckFn>) => Awaited<ReturnType<SpellCheckFn>>;

export async function spellCheck(filename: string, text: string, root: Node, options: WorkerOptions): Promise<Issue[]> {
const toIgnore = new Set<string>();
const importedIdentifiers = new Set<string>();
Expand Down
34 changes: 34 additions & 0 deletions packages/cspell-eslint-plugin/src/worker/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { Node } from 'estree';

import type { WorkerOptions } from '../common/options.js';
import type { NodeType } from './ASTNode.js';

interface ExtendedSuggestion {
/**
* The suggestion.
*/
word: string;
/**
* The word is preferred above others, except other "preferred" words.
*/
isPreferred?: boolean;
/**
* The suggested word adjusted to match the original case.
*/
wordAdjustedToMatchCase?: string;
}

export type Suggestions = ExtendedSuggestion[] | undefined;

export interface Issue {
start: number;
end: number;
word: string;
severity: 'Forbidden' | 'Unknown' | 'Hint';
suggestions: Suggestions;
nodeType: NodeType;
}

type SpellCheckFn = (filename: string, text: string, root: Node, options: WorkerOptions) => Promise<Issue[]>;

export type SpellCheckSyncFn = (...p: Parameters<SpellCheckFn>) => Awaited<ReturnType<SpellCheckFn>>;
2 changes: 1 addition & 1 deletion packages/cspell-eslint-plugin/src/worker/walkTree.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Node } from 'estree-walker';
import { walk } from 'estree-walker';

import type { ASTNode } from './ASTNode.mjs';
import type { ASTNode } from './ASTNode.js';

type Key = string | number | symbol | null | undefined;

Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-eslint-plugin/src/worker/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/**
* @typedef {import('estree').Node} Node
* @typedef {import('./spellCheck.mjs').Issue} Issue
* @typedef {import('./types.js').Issue} Issue
* @typedef {import('../common/options.js').WorkerOptions} WorkerOptions
*/

Expand Down
22 changes: 11 additions & 11 deletions packages/cspell-lib/api/api.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference types="node" />
import { Glob, CSpellSettingsWithSourceTrace, TextOffset, TextDocumentOffset, AdvancedCSpellSettingsWithSourceTrace, Parser, DictionaryDefinitionInline, DictionaryDefinitionPreferred, DictionaryDefinitionAugmented, DictionaryDefinitionCustom, PnPSettings, ImportFileRef, CSpellUserSettings, Issue, LocaleId, CSpellSettings, MappedText, ParsedText } from '@cspell/cspell-types';
import { Glob, CSpellSettingsWithSourceTrace, TextOffset, TextDocumentOffset, PnPSettings, AdvancedCSpellSettingsWithSourceTrace, Parser, DictionaryDefinitionInline, DictionaryDefinitionPreferred, DictionaryDefinitionAugmented, DictionaryDefinitionCustom, ImportFileRef, CSpellUserSettings, Issue, LocaleId, CSpellSettings, MappedText, ParsedText } from '@cspell/cspell-types';
export * from '@cspell/cspell-types';
import { WeightMap } from 'cspell-trie-lib';
export { CompoundWordsMethod } from 'cspell-trie-lib';
Expand Down Expand Up @@ -90,7 +90,7 @@ interface ResolveSettingsResult {
settings: CSpellSettingsWithSourceTrace;
}

//# sourceMappingURL=index.link.d.ts.map
//# sourceMappingURL=index.link.d.mts.map

type index_link_d_AddPathsToGlobalImportsResults = AddPathsToGlobalImportsResults;
type index_link_d_ListGlobalImportsResult = ListGlobalImportsResult;
Expand Down Expand Up @@ -366,6 +366,13 @@ declare function getLanguagesForBasename(basename: string): string[];
declare const currentSettingsFileVersion = "0.2";
declare const ENV_CSPELL_GLOB_ROOT = "CSPELL_GLOB_ROOT";

declare class ImportError extends Error {
readonly cause: Error | undefined;
constructor(msg: string, cause?: Error | unknown);
}

type LoaderResult = Uri | undefined;

/**
* The keys of an object where the values cannot be undefined.
*/
Expand All @@ -379,6 +386,8 @@ type OptionalOrUndefined<T> = {
[P in keyof T]: P extends OptionalKeys<T> ? T[P] | undefined : T[P];
};

type PnPSettingsOptional = OptionalOrUndefined<PnPSettings>;

declare const SymbolCSpellSettingsInternal: unique symbol;
interface CSpellSettingsInternal extends Omit<AdvancedCSpellSettingsWithSourceTrace, 'dictionaryDefinitions'> {
[SymbolCSpellSettingsInternal]: true;
Expand All @@ -405,15 +414,6 @@ interface DictionaryFileDefinitionInternal extends Readonly<DictionaryDefinition
readonly __source?: string | undefined;
}

declare class ImportError extends Error {
readonly cause: Error | undefined;
constructor(msg: string, cause?: Error | unknown);
}

type LoaderResult = Uri | undefined;

type PnPSettingsOptional = OptionalOrUndefined<PnPSettings>;

type CSpellSettingsWST$1 = CSpellSettingsWithSourceTrace;
type CSpellSettingsI$1 = CSpellSettingsInternal;

Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-lib/api/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import dts from 'rollup-plugin-dts';

const config = [
{
input: './dist/cjs/index.d.ts',
input: './dist/esm/index.d.mts',
output: [{ file: './api/api.d.ts', format: 'es' }],
plugins: [dts()],
},
Expand Down
25 changes: 12 additions & 13 deletions packages/cspell-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
"name": "cspell-lib",
"version": "7.0.0-alpha.1",
"description": "A library of useful functions used across various cspell tools.",
"type": "commonjs",
"main": "dist/cjs/index.js",
"types": "dist/cjs/index.d.ts",
"type": "module",
"types": "dist/api/api.d.ts",
"module": "dist/esm/index.mjs",
"exports": {
".": {
"import": "./dist/esm/index.mjs"
}
},
"files": [
"dist",
"!dist/esm/**/*.js",
Expand All @@ -23,7 +27,6 @@
"clean-build": "pnpm clean && pnpm build",
"build": "tsc -b . && ts2mjs dist/esm && pnpm run build:api",
"build:api": "rollup -c api/rollup.config.mjs",
"build:cjs": "tsc -b tsconfig.cjs.json",
"build:esm": "tsc -b tsconfig.esm.json",
"build:esm:ts2mjs": "tsc -b tsconfig.esm.json && ts2mjs dist/esm",
"build:lib": "tsc -b src/lib/tsconfig.json",
Expand Down Expand Up @@ -63,15 +66,15 @@
"@cspell/strong-weak-map": "workspace:*",
"clear-module": "^4.1.2",
"comment-json": "^4.2.3",
"configstore": "^5.0.1",
"configstore": "^6.0.0",
"cosmiconfig": "8.0.0",
"cspell-dictionary": "workspace:*",
"cspell-glob": "workspace:*",
"cspell-grammar": "workspace:*",
"cspell-io": "workspace:*",
"cspell-trie-lib": "workspace:*",
"fast-equals": "^4.0.3",
"find-up": "^5.0.0",
"fast-equals": "^5.0.1",
"find-up": "^6.3.0",
"gensequence": "^5.0.2",
"import-fresh": "^3.3.0",
"resolve-from": "^5.0.0",
Expand All @@ -91,12 +94,8 @@
"@cspell/dict-html": "^4.0.3",
"@cspell/dict-nl-nl": "^2.2.8",
"@cspell/dict-python": "^4.0.3",
"@types/configstore": "^5.0.1",
"@types/jest": "^29.5.1",
"@types/configstore": "^6.0.0",
"cspell-dict-nl-nl": "^1.1.2",
"expect": "^29.5.0",
"jest": "^29.5.0",
"lorem-ipsum": "^2.0.8",
"ts-jest": "^29.1.0"
"lorem-ipsum": "^2.0.8"
}
}
3 changes: 3 additions & 0 deletions packages/cspell-lib/samples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
4 changes: 2 additions & 2 deletions packages/cspell-lib/src/lib/Settings/Controller/pnpLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Handles loading of `.pnp.js` and `.pnp.js` files.
*/
import clearModule from 'clear-module';
import findUp from 'find-up';
import { findUp, findUpSync } from 'find-up';
import importFresh from 'import-fresh';

import type { Uri } from '../../util/Uri.js';
Expand Down Expand Up @@ -103,7 +103,7 @@ async function findPnpAndLoad(uriDirectory: Uri, pnpFiles: string[]): Promise<Lo
* @param uriDirectory - directory to start at.
*/
function findPnpAndLoadSync(uriDirectory: Uri, pnpFiles: string[]): LoaderResult {
const found = findUp.sync(pnpFiles, { cwd: uriToFilePath(uriDirectory) });
const found = findUpSync(pnpFiles, { cwd: uriToFilePath(uriDirectory) });
return loadPnpIfNeeded(found);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { SpellingDictionary } from 'cspell-dictionary';
import { createCollection, createSpellingDictionary, createSuggestDictionary } from 'cspell-dictionary';
import { describe, expect, test } from 'vitest';

import { textValidatorFactory } from './lineValidatorFactory';
import { textValidatorFactory } from './lineValidatorFactory.js';

const oc = expect.objectContaining;

Expand Down
4 changes: 3 additions & 1 deletion packages/cspell-lib/src/lib/util/Uri.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import assert from 'assert';
import { URI, Utils } from 'vscode-uri';
import * as vscodeUriPkg from 'vscode-uri';

const { URI, Utils } = vscodeUriPkg;

export interface Uri {
readonly scheme: string;
Expand Down
14 changes: 0 additions & 14 deletions packages/cspell-lib/tsconfig.cjs.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/cspell-lib/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"sourceMap": false,
"types": ["node"]
},
"include": ["src/lib"],
"include": ["src/lib", "src/lib-cjs/vscode-uri.cts"],
"references": [{ "path": "./src/lib-cjs" }, { "path": "./src/test-util" }]
}
7 changes: 1 addition & 6 deletions packages/cspell-lib/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"files": [],
"references": [
{ "path": "./tsconfig.cjs.json" },
{ "path": "./tsconfig.esm.json" },
{ "path": "./src/lib-cjs" },
{ "path": "./src/test-util" }
]
"references": [{ "path": "./tsconfig.esm.json" }, { "path": "./src/lib-cjs" }, { "path": "./src/test-util" }]
}
1 change: 0 additions & 1 deletion packages/cspell/jest.config.js

This file was deleted.

14 changes: 0 additions & 14 deletions packages/cspell/tsconfig.cjs.json

This file was deleted.

Loading

0 comments on commit 4172019

Please sign in to comment.