Skip to content

Commit

Permalink
more rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Apr 18, 2024
1 parent 43ebdcc commit 13774e6
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 78 deletions.
60 changes: 30 additions & 30 deletions eslint.config.mjs
Expand Up @@ -26,35 +26,36 @@ export default tsEslint.config(
// Disable these rules
'unicorn/catch-error-name': 'off',
'unicorn/consistent-function-scoping': 'off',
'unicorn/explicit-length-check': 'off',
'unicorn/filename-case': 'off',
'unicorn/import-style': 'off',
'unicorn/no-array-callback-reference': 'off',
'unicorn/prevent-abbreviations': 'off',
'unicorn/no-array-reduce': 'off',
'unicorn/explicit-length-check': 'off',
'unicorn/no-nested-ternary': 'off',
'unicorn/no-await-expression-member': 'off',
'unicorn/no-nested-ternary': 'off',
'unicorn/no-new-array': 'off', // new Array(size) is 10x faster than Array.from({length: size})
'unicorn/no-useless-spread': 'off', // makes dangerous fixes
'unicorn/no-useless-undefined': 'off', // Breaks return types and other things
'unicorn/no-zero-fractions': 'off',
'unicorn/number-literal-case': 'off', // doesn't fix anything, might conflict with other rules.
'unicorn/prefer-event-target': 'off', // It is broken
'unicorn/prefer-logical-operator-over-ternary': 'off', // single line ternary is fine
'unicorn/prefer-math-trunc': 'off', // incorrectly sets Enums.
'unicorn/prefer-native-coercion-functions': 'off', // Makes some strange choices
'unicorn/number-literal-case': 'off', // doesn't fix anything, might conflict with other rules.
'unicorn/no-useless-undefined': 'off', // Breaks return types and other things
'unicorn/prefer-event-target': 'off', // It is broken
'unicorn/no-useless-spread': 'off', // makes dangerous fixes
'unicorn/no-new-array': 'off', // new Array(size) is 10x faster than Array.from({length: size})
'unicorn/no-zero-fractions': 'off',
'unicorn/prefer-string-slice': 'off', // substring is used where it make the most sense.
'unicorn/prefer-top-level-await': 'off', // it will be possible to require a module that does not use top level await.
'unicorn/prevent-abbreviations': 'off',

// Maybe later
'unicorn/no-array-for-each': 'off',
'unicorn/prefer-at': 'off',
'unicorn/no-for-loop': 'off',
'unicorn/new-for-builtins': 'off',
'unicorn/better-regex': 'off', // Not sure if it is an improvement.
'unicorn/new-for-builtins': 'off',
'unicorn/no-array-for-each': 'off',
'unicorn/no-array-method-this-argument': 'off', // Too many false positives
'unicorn/no-for-loop': 'off',
'unicorn/no-negated-condition': 'off', // Too picky - works against implying the most common branch.
'unicorn/prefer-at': 'off',

// Enable these rules to help with on boarding eslint.
'unicorn/no-instanceof-array': 'error',
'unicorn/numeric-separators-style': [
'error',
{
Expand All @@ -64,11 +65,6 @@ export default tsEslint.config(
},
},
],
'unicorn/prefer-array-flat': 'error',
'unicorn/prefer-module': 'error',
'unicorn/prefer-node-protocol': 'error',
'unicorn/prefer-spread': 'error',
'unicorn/prefer-string-replace-all': 'error',
'unicorn/empty-brace-spaces': 'error',
'unicorn/error-message': 'error',
'unicorn/escape-case': 'error',
Expand All @@ -81,6 +77,7 @@ export default tsEslint.config(
'unicorn/no-document-cookie': 'error',
'unicorn/no-empty-file': 'error',
'unicorn/no-hex-escape': 'error',
'unicorn/no-instanceof-array': 'error',
'unicorn/no-invalid-remove-event-listener': 'error',
'unicorn/no-lonely-if': 'error',
'unicorn/no-new-buffer': 'error',
Expand All @@ -103,25 +100,25 @@ export default tsEslint.config(
'unicorn/prefer-add-event-listener': 'error',
'unicorn/prefer-array-find': 'error',
'unicorn/prefer-array-flat-map': 'error',
'unicorn/prefer-array-flat': 'error',
'unicorn/prefer-array-index-of': 'error',
'unicorn/prefer-array-some': 'error',
'unicorn/prefer-blob-reading-methods': 'error',
'unicorn/prefer-code-point': 'error',
'unicorn/prefer-date-now': 'error',
'unicorn/prefer-default-parameters': 'error',
'unicorn/prefer-dom-node-append': 'error',
'unicorn/prefer-dom-node-dataset': 'error',
'unicorn/prefer-dom-node-remove': 'error',
'unicorn/prefer-dom-node-text-content': 'error',
'unicorn/prefer-export-from': 'error',
'unicorn/prefer-code-point': 'error',
'unicorn/prefer-includes': 'error',
'unicorn/prefer-keyboard-event-key': 'error',
'unicorn/prefer-modern-dom-apis': 'error',
'unicorn/prefer-modern-math-apis': 'error',
'unicorn/prefer-module': 'error',
'unicorn/prefer-negative-index': 'error',

// To be evaluated

'unicorn/prefer-node-protocol': 'error',
'unicorn/prefer-number-properties': 'error',
'unicorn/prefer-object-from-entries': 'error',
'unicorn/prefer-optional-catch-binding': 'error',
Expand All @@ -131,13 +128,16 @@ export default tsEslint.config(
'unicorn/prefer-regexp-test': 'error',
'unicorn/prefer-set-has': 'error',
'unicorn/prefer-set-size': 'error',
// 'unicorn/prefer-string-slice': 'error',
// 'unicorn/prefer-string-starts-ends-with': 'error',
// 'unicorn/prefer-string-trim-start-end': 'error',
// 'unicorn/prefer-switch': 'error',
// 'unicorn/prefer-ternary': 'error',
// 'unicorn/prefer-top-level-await': 'error',
// 'unicorn/prefer-type-error': 'error',
'unicorn/prefer-spread': 'error',
'unicorn/prefer-string-replace-all': 'error',
'unicorn/prefer-string-starts-ends-with': 'error',
'unicorn/prefer-string-trim-start-end': 'error',
'unicorn/prefer-switch': 'error',
'unicorn/prefer-ternary': 'error',
'unicorn/prefer-type-error': 'error',

// To be evaluated

// 'unicorn/relative-url-style': 'error',
// 'unicorn/require-array-join-separator': 'error',
// 'unicorn/require-number-to-fixed-digits-argument': 'error',
Expand Down
Expand Up @@ -28,7 +28,7 @@ export function parseCSpellConfigFilePackageJson(file: TextFile): CSpellConfigFi
packageJson['cspell'] = packageJson['cspell'] || {};
const cspell = packageJson['cspell'];
if (typeof cspell !== 'object' || Array.isArray(cspell)) {
throw new Error(`Unable to parse ${url}`);
throw new TypeError(`Unable to parse ${url}`);
}

const indent = detectIndent(content);
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-lib/src/test-util/test.matchers.mts
Expand Up @@ -8,7 +8,7 @@ export function extendExpect(e: typeof expect): AsymmetricMatchers {
e.extend({
toEqualCaseInsensitive(actual, expected) {
if (typeof actual !== 'string' || typeof expected !== 'string') {
throw new Error('These must be of type number!');
throw new TypeError('These must be of type number!');
}

const pass = actual.toLowerCase() === expected.toLowerCase();
Expand Down
8 changes: 3 additions & 5 deletions packages/cspell-tools/src/compiler/wordListParser.ts
Expand Up @@ -196,11 +196,9 @@ export function createParseFileLineMapper(options?: Partial<ParseFileOptions>):
}
if (split) {
const words = splitLine(line);
if (!allowedSplitWords.size) {
yield* words;
} else {
yield* words.flatMap((word) => splitCamelCaseIfAllowed(word, allowedSplitWords, keepCase));
}
yield* !allowedSplitWords.size
? words
: words.flatMap((word) => splitCamelCaseIfAllowed(word, allowedSplitWords, keepCase));
if (!splitKeepBoth) continue;
}
yield line.replaceAll(/["]/g, '');
Expand Down
6 changes: 1 addition & 5 deletions packages/cspell-trie/src/app.test.ts
Expand Up @@ -53,11 +53,7 @@ describe('Validate App', () => {
vi.spyOn(console, 'warn').mockImplementation(out.warn);

const result = app.run(commander, argv(...args));
if (errorResult) {
await expect(result).rejects.toThrow(errorResult);
} else {
await expect(result).resolves.not.toThrow();
}
await (errorResult ? expect(result).rejects.toThrow(errorResult) : expect(result).resolves.not.toThrow());
expect(out.getText()).toMatchSnapshot();
});
});
Expand Down
30 changes: 5 additions & 25 deletions packages/cspell/src/app/app.test.ts
Expand Up @@ -198,11 +198,7 @@ describe('Validate cli', () => {
const commander = getCommander();
const args = argv(...testArgs);
const result = app.run(commander, args);
if (!errorCheck) {
await expect(result).resolves.toBeUndefined();
} else {
await expect(result).rejects.toThrow(errorCheck);
}
await (!errorCheck ? expect(result).resolves.toBeUndefined() : expect(result).rejects.toThrow(errorCheck));

eError ? expect(error).toHaveBeenCalled() : expect(error).not.toHaveBeenCalled();

Expand All @@ -223,11 +219,7 @@ describe('Validate cli', () => {
const commander = getCommander();
const args = argv(...testArgs);
const result = app.run(commander, args);
if (!errorCheck) {
await expect(result).resolves.toBeUndefined();
} else {
await expect(result).rejects.toThrow(errorCheck);
}
await (!errorCheck ? expect(result).resolves.toBeUndefined() : expect(result).rejects.toThrow(errorCheck));

eError ? expect(error).toHaveBeenCalled() : expect(error).not.toHaveBeenCalled();

Expand Down Expand Up @@ -255,11 +247,7 @@ describe('Validate cli', () => {
const commander = getCommander();
const args = argv(...testArgs);
const result = app.run(commander, args);
if (!errorCheck) {
await expect(result).resolves.toBeUndefined();
} else {
await expect(result).rejects.toThrow(errorCheck);
}
await (!errorCheck ? expect(result).resolves.toBeUndefined() : expect(result).rejects.toThrow(errorCheck));

eError ? expect(error).toHaveBeenCalled() : expect(error).not.toHaveBeenCalled();

Expand Down Expand Up @@ -300,11 +288,7 @@ describe('Validate cli', () => {
const commander = getCommander();
const args = argv(...testArgs);
const result = app.run(commander, args);
if (!errorCheck) {
await expect(result).resolves.toBeUndefined();
} else {
await expect(result).rejects.toThrow(errorCheck);
}
await (!errorCheck ? expect(result).resolves.toBeUndefined() : expect(result).rejects.toThrow(errorCheck));

eError ? expect(error).toHaveBeenCalled() : expect(error).not.toHaveBeenCalled();

Expand Down Expand Up @@ -339,11 +323,7 @@ describe('Validate cli', () => {
const commander = getCommander();
const args = argv(...testArgs);
const result = app.run(commander, args);
if (!errorCheck) {
await expect(result).resolves.toBeUndefined();
} else {
await expect(result).rejects.toThrow(errorCheck);
}
await (!errorCheck ? expect(result).resolves.toBeUndefined() : expect(result).rejects.toThrow(errorCheck));
expect(captureStdout.text).toMatchSnapshot();
expect(log.mock.calls.join('\n')).toMatchSnapshot();
expect(error.mock.calls.join('\n')).toMatchSnapshot();
Expand Down
15 changes: 4 additions & 11 deletions packages/hunspell-reader/src/aff.ts
Expand Up @@ -105,12 +105,7 @@ export class Aff {
const { flags } = affWord;
const subRules = this.affData.getRulesForAffSubstitution(sub);
const rules = joinRules(affWord.rules, subRules);
let word: string;
if (sub.type === 'S') {
word = stripped + sub.attach;
} else {
word = sub.attach + stripped;
}
const word = sub.type === 'S' ? stripped + sub.attach : sub.attach + stripped;
return this.affData.toAffixWord(affWord, word, flags, rules);
}

Expand Down Expand Up @@ -467,11 +462,9 @@ class AffData {
const fx = sfx || pfx;
if (fx) {
const affFx = this.#mapFx(fx);
if (affFx.type === 'P') {
return { id, idx: index, type: 'P', flags: 0, fx: affFx };
} else {
return { id, idx: index, type: 'S', flags: 0, fx: affFx };
}
return affFx.type === 'P'
? { id, idx: index, type: 'P', flags: 0, fx: affFx }
: { id, idx: index, type: 'S', flags: 0, fx: affFx };
}
return { id, idx: index, type: 'F', flags: flags || 0 };
}
Expand Down

0 comments on commit 13774e6

Please sign in to comment.