Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Oct 13, 2023
1 parent 4bde9ad commit 6ebed63
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 19 deletions.
25 changes: 16 additions & 9 deletions packages/cspell-lib/src/lib/Settings/DictionarySettings.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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 @@ -14,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 @@ -37,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 @@ -50,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
2 changes: 1 addition & 1 deletion packages/cspell-lib/src/lib/Settings/GlobalSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import type { CSpellSettings, CSpellSettingsWithSourceTrace } from '@cspell/cspell-types';
import { format } from 'util';

Expand All @@ -12,6 +11,7 @@ export interface GlobalSettingsWithSource extends Partial<GlobalCSpellSettings>
source: CSpellSettingsWithSourceTrace['source'];
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface GlobalCSpellSettings extends Required<Pick<CSpellSettings, 'import'>> {}

export function getRawGlobalSettings(): GlobalSettingsWithSource {
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell-lib/src/lib/Settings/LanguageSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,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
2 changes: 1 addition & 1 deletion packages/cspell-lib/src/lib/textValidation/checkText.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import type { CSpellUserSettings } from '@cspell/cspell-types';
import assert from 'assert';

Expand Down Expand Up @@ -69,6 +68,7 @@ export enum IncludeExcludeFlag {
EXCLUDE = 'E',
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface CheckTextOptions extends DocumentValidatorOptions {}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-lib/src/lib/util/wordSplitter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import type { TextOffset } from '@cspell/cspell-types';

import { PairingHeap } from './PairingHeap.js';
Expand Down Expand Up @@ -41,6 +40,7 @@ export interface TextOffsetWithValid extends TextOffset {
isFound: boolean;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface SplitOptions extends WordBreakOptions {}

export function split(
Expand Down
1 change: 1 addition & 0 deletions packages/cspell-trie-lib/src/lib/TrieNode/trie-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export function countWords(root: TrieNode): number {

function walk(n: TrieNode) {
if (visited.has(n)) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return visited.get(n)!;
}

Expand Down
1 change: 1 addition & 0 deletions packages/cspell-trie-lib/src/lib/convertToTrieRefNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export function convertToTrieRefNodes(root: TrieNode): IterableIterator<TrieRefN
function* walkByRollup(n: TrieNode): IterableIterator<TrieRefNode> {
if (cached.has(n)) return;
if (n.f && !n.c) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
cached.set(n, cached.get(eow)!);
return;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/cspell-trie-lib/src/lib/utils/secondChanceCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class SecondChanceCache<Key, Value> {
public has(key: Key) {
if (this.map0.has(key)) return true;
if (this.map1.has(key)) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.set(key, this.get1(key)!);
return true;
}
Expand Down Expand Up @@ -46,6 +47,7 @@ export class SecondChanceCache<Key, Value> {

private get1(key: Key): Value | undefined {
if (this.map1.has(key)) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const v = this.map1.get(key)!;
this.map1.delete(key);
this.map0.set(key, v);
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,

node: c[letter]!,
node: c[letter],
hintOffset: hintOffset + 1,
}));
// We don't want to suggest the compound character.
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell-types/src/features.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-interface */

/**
* These are experimental features and are subject to change or removal without notice.
*/
Expand All @@ -13,12 +11,14 @@ export interface FeaturesExperimental {
/**
* These are the current set of active features
*/
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface FeaturesActive {}

/**
* These are feature settings that have been deprecated or moved elsewhere they will have no
* effect on the code but are here to prevent schema errors. The will get cleaned out on major versions.
*/
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface FeaturesDeprecated {}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/hunspell-reader/src/aff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export function processRules(affInfo: AffInfo): Map<string, Rule> {
.map((pfx) => ({ id: pfx.id, type: 'pfx', pfx }));
const flagRules: Sequence<Rule> = GS.sequenceFromObject(affInfo as AffTransformFlags)
.filter(([key, value]) => !!affFlag[key] && !!value)

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
.map(([key, value]) => ({ id: value!, type: 'flag', flags: affFlag[key] }));

const rules = sfxRules
Expand Down

0 comments on commit 6ebed63

Please sign in to comment.