Skip to content

Commit ba68539

Browse files
committed
lint: handling lint of all packages
1 parent b716282 commit ba68539

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+272
-234
lines changed

.eslintrc.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ module.exports = {
3232
},
3333
},
3434
{
35-
files: ['*.ts'],
36-
excludedFiles: ['*__tests__/**/*.(t|j)s', './**/testUtils/**/*'],
35+
excludedFiles: ['__tests__/**/*.(t|j)s', './**/testUtils/**/*'],
3736
extends: [
3837
'plugin:@typescript-eslint/eslint-recommended',
3938
'plugin:@typescript-eslint/recommended',
4039
'plugin:import/typescript',
4140
],
41+
files: ['*.ts'],
42+
rules: {
43+
'@typescript-eslint/no-explicit-any': 'off',
44+
'@typescript-eslint/explicit-module-boundary-types': 'off',
45+
},
4246
},
4347
],
4448
parser: '@typescript-eslint/parser',
@@ -58,7 +62,16 @@ module.exports = {
5862
order: 'asc',
5963
},
6064
'newlines-between': 'always',
61-
pathGroupsExcludedImportTypes: ['builtin'],
65+
pathGroups: [
66+
{
67+
pattern: '^vx',
68+
group: 'external',
69+
},
70+
{
71+
pattern: './vx',
72+
group: 'external',
73+
},
74+
],
6275
},
6376
],
6477
'jest/expect-expect': 0,
@@ -96,7 +109,7 @@ module.exports = {
96109
},
97110
'import/resolver': {
98111
typescript: {
99-
project: 'packages/*/tsconfig.json',
112+
project: './tsconfig.json',
100113
},
101114
},
102115
},

packages/anyone/src/exports/all.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import run from 'runAnyoneMethods';
33
/**
44
* Checks that at all passed arguments evaluate to a truthy value.
55
*/
6-
export default function all(...args: any[]): boolean {
6+
export default function all(...args: unknown[]): boolean {
77
return args.every(run);
88
}

packages/anyone/src/exports/any.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import run from 'runAnyoneMethods';
33
/**
44
* Checks that at least one passed argument evaluates to a truthy value.
55
*/
6-
export default function any(...args: any[]): boolean {
6+
export default function any(...args: unknown[]): boolean {
77
return args.some(run);
88
}

packages/anyone/src/exports/none.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import run from 'runAnyoneMethods';
55
/**
66
* Checks that at none of the passed arguments evaluate to a truthy value.
77
*/
8-
export default function none(...args: any[]): boolean {
8+
export default function none(...args: unknown[]): boolean {
99
return args.every(bindNot(run));
1010
}

packages/anyone/src/exports/one.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import run from 'runAnyoneMethods';
33
/**
44
* Checks that at only one passed argument evaluates to a truthy value.
55
*/
6-
export default function one(...args: any[]): boolean {
6+
export default function one(...args: unknown[]): boolean {
77
let count = 0;
88

99
for (let i = 0; i < args.length; i++) {

packages/anyone/src/runner/runAnyoneMethods.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import isFunction from 'isFunction';
33
/**
44
* Accepts a value or a function, and coerces it into a boolean value
55
*/
6-
export default function run(arg: any): boolean {
6+
export default function run(arg: unknown): boolean {
77
if (isFunction(arg)) {
88
try {
99
return check(arg());
@@ -15,6 +15,7 @@ export default function run(arg: any): boolean {
1515
return check(arg);
1616
}
1717

18-
function check(value: any): boolean {
18+
function check(value: unknown): boolean {
19+
// We use abstract equality intentionally here. This enables falsy valueOf support.
1920
return Array.isArray(value) ? true : value != false && Boolean(value); // eslint-disable-line
2021
}

packages/context/src/__tests__/__snapshots__/context.spec.ts.snap

+1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ Object {
1818
"bind": [Function],
1919
"run": [Function],
2020
"use": [Function],
21+
"useX": [Function],
2122
}
2223
`;

packages/context/src/context.ts

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
1+
import throwError from 'throwError';
2+
13
export default function createContext<T extends Record<string, unknown>>(
2-
init?: (ctxRef: T, parentContext: T | void) => T | null
4+
init?: (ctxRef: Partial<T>, parentContext: T | void) => T | null
35
): {
4-
run: <R>(ctxRef: T, fn: (context: T) => R) => R;
5-
bind: <Fn extends (...args: any[]) => any>(ctxRef: T, fn: Fn) => Fn;
6+
run: <R>(ctxRef: Partial<T>, fn: (context: T) => R) => R;
7+
bind: <Fn extends (...args: any[]) => any>(ctxRef: Partial<T>, fn: Fn) => Fn;
68
use: () => T | undefined;
9+
useX: (errorMessage?: string) => T;
710
} {
811
const storage: { ctx?: T; ancestry: T[] } = { ancestry: [] };
912

1013
return {
11-
run,
1214
bind,
15+
run,
1316
use,
17+
useX,
1418
};
1519

16-
function run<R>(ctxRef: T, fn: (context: T) => R): R {
20+
function useX(errorMessage?: string): T {
21+
return (
22+
storage.ctx ??
23+
throwError(errorMessage ?? 'Context was used after it was closed')
24+
);
25+
}
26+
27+
function run<R>(ctxRef: Partial<T>, fn: (context: T) => R): R {
1728
const parentContext = use();
1829

1930
const out = {
2031
...(parentContext ? parentContext : {}),
2132
...(init?.(ctxRef, parentContext) ?? ctxRef),
22-
};
33+
} as T;
2334

2435
const ctx = set(Object.freeze(out));
2536
storage.ancestry.unshift(ctx);
@@ -29,8 +40,11 @@ export default function createContext<T extends Record<string, unknown>>(
2940
return res;
3041
}
3142

32-
function bind<Fn extends (...args: any[]) => any>(ctxRef: T, fn: Fn) {
33-
// @ts-ignore - this one's pretty hard to get
43+
function bind<Fn extends (...args: any[]) => any>(
44+
ctxRef: Partial<T>,
45+
fn: Fn
46+
) {
47+
// @ts-ignore - this one's pretty hard to get right
3448
const returnedFn: Fn = function (...runTimeArgs: Parameters<Fn>) {
3549
return run<ReturnType<Fn>>(ctxRef, function () {
3650
return fn(...runTimeArgs);

packages/n4s/src/lib/transformResult.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ function validateResult(result: TRuleReturn): void {
4444
return;
4545
}
4646

47-
// FIXME: Better error message
48-
throwError('Incorrect return value for rule');
47+
if (__DEV__) {
48+
throwError('Incorrect return value for rule: ' + JSON.stringify(result));
49+
} else {
50+
throwError();
51+
}
4952
}
5053

5154
function getDefaultResult(value: TRuleValue): {

packages/n4s/src/rules.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { isArray, isNotArray } from 'isArray';
21

32
import { endsWith, doesNotEndWith } from 'endsWith';
43
import { equals, notEquals } from 'equals';
54
import { greaterThan } from 'greaterThan';
65
import { greaterThanOrEquals } from 'greaterThanOrEquals';
76
import { inside, notInside } from 'inside';
7+
import { isArray, isNotArray } from 'isArrayValue';
88
import { isBetween, isNotBetween } from 'isBetween';
99
import { isBlank, isNotBlank } from 'isBlank';
1010
import { isBoolean, isNotBoolean } from 'isBoolean';
@@ -30,6 +30,7 @@ import { shorterThan } from 'shorterThan';
3030
import { shorterThanOrEquals } from 'shorterThanOrEquals';
3131
import { startsWith, doesNotStartWith } from 'startsWith';
3232

33+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
3334
export default function rules() {
3435
return {
3536
doesNotEndWith,

packages/n4s/src/rules/__tests__/isArray.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isArray } from 'isArray';
1+
import { isArray } from 'isArrayValue';
22

33
describe('Tests isArray rule', () => {
44
it('Should return true for an empty array', () => {

packages/n4s/src/rules/isArray.ts renamed to packages/n4s/src/rules/isArrayValue.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import bindNot from 'bindNot';
22

3+
// The module is named "isArrayValue" since it
4+
// is conflicting with a nested npm dependency.
5+
// We may need to revisit this in the future.
6+
37
export function isArray(value: unknown): value is Array<unknown> {
48
return Boolean(Array.isArray(value));
59
}

packages/n4s/src/rules/isEven.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { isNumeric } from 'isNumeric';
2+
import type { TRuleValue } from 'runtimeRules';
23

34
/**
45
* Validates that a given value is an even number
56
*/
6-
export const isEven = (value: any): boolean => {
7+
export const isEven = (value: TRuleValue): boolean => {
78
if (isNumeric(value)) {
89
return value % 2 === 0;
910
}

packages/n4s/src/rules/isOdd.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { isNumeric } from 'isNumeric';
2-
2+
import type { TRuleValue } from 'runtimeRules';
33
/**
44
* Validates that a given value is an odd number
55
*/
6-
export const isOdd = (value: any): boolean => {
6+
export const isOdd = (value: TRuleValue): boolean => {
77
if (isNumeric(value)) {
88
return value % 2 !== 0;
99
}

packages/n4s/src/runtime/runtimeRules.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ export type TRule = Record<string, TRuleBase>;
1212

1313
const baseRules = rules();
1414

15-
function getRule(ruleName: string) {
16-
// @ts-ignore - this should actually be fine
17-
return baseRules[ruleName] || compounds[ruleName];
15+
function getRule(ruleName: string): TRuleBase {
16+
return (
17+
baseRules[ruleName as keyof typeof baseRules] ??
18+
compounds[ruleName as keyof typeof compounds] // eslint-disable-line import/namespace
19+
);
1820
}
1921

2022
export { baseRules, compounds, getRule };

packages/shared/src/cache.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { isNotNull } from 'isNull';
21
import { lengthEquals } from 'lengthEquals';
32

43
/**
@@ -11,7 +10,7 @@ export default function createCache(maxSize = 10): {
1110
const cacheStorage: Array<[unknown[], any]> = [];
1211

1312
/**
14-
* @param {Any[]} deps dependency array.
13+
* @param {any[]} deps dependency array.
1514
* @param {Function} cache action function.
1615
*/
1716
const cache = <T>(
@@ -20,7 +19,8 @@ export default function createCache(maxSize = 10): {
2019
): T => {
2120
const cacheHit = cache.get(deps);
2221

23-
if (isNotNull(cacheHit)) {
22+
// cache hit is not null
23+
if (cacheHit) {
2424
return cacheHit[1];
2525
}
2626

@@ -39,7 +39,7 @@ export default function createCache(maxSize = 10): {
3939
* Retrieves an item from the cache.
4040
* @param {deps} deps Dependency array
4141
*/
42-
cache.get = (deps: unknown[]): any =>
42+
cache.get = (deps: unknown[]): [unknown[], any] | null =>
4343
cacheStorage[
4444
cacheStorage.findIndex(
4545
([cachedDeps]) =>

packages/shared/src/callEach.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export default function callEach(arr: Function[]): void {
1+
export default function callEach(arr: ((...args: any[]) => any)[]): void {
22
return arr.forEach(fn => fn());
33
}

packages/shared/src/isPromise.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import isFunction from 'isFunction';
22

3-
export default function isPromise(value: unknown): value is Promise<unknown> {
4-
// @ts-ignore - wasting time on something that works. I'll get back to it.
3+
export default function isPromise(value: any): value is Promise<unknown> {
54
return value && isFunction(value.then);
65
}

packages/shared/src/throwError.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Throws a timed out error.
33
*/
44
export default function throwError(
5-
message: string,
5+
message?: string,
66
type: ErrorConstructor = Error
77
): never {
88
throw new type(message);

packages/vast/src/vast.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import optionalFunctionValue from 'optionalFunctionValue';
33

44
type TStateInput<S> = S | (() => S);
55
type TSetStateInput<S> = S | ((prevState: S) => S);
6-
type TStateHandlerReturn<S> = [S, (nextState: TSetStateInput<S>) => void];
6+
export type TStateHandlerReturn<S> = [
7+
S,
8+
(nextState: TSetStateInput<S>) => void
9+
];
710

811
type TCreateStateReturn = {
912
reset: () => void;

packages/vest/src/__tests__/integration.async-tests.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function genValidate({ create, test, enforce, ...vest }) {
66
test('field_2', 'field_statement_2', () => {
77
enforce(2).equals(3);
88
});
9-
test('field_3', 'field_statement_3', () => {});
9+
test('field_3', 'field_statement_3', jest.fn());
1010
test('field_4', 'field_statement_4', () => {
1111
vest.warn();
1212
throw new Error();

packages/vest/src/__tests__/integration.base.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const suite = ({ create, test, ...vest }) =>
77
test('field_2', 'field_statement_2', () => {
88
expect(2).toBe(3);
99
});
10-
test('field_3', 'field_statement_3', () => {});
10+
test('field_3', 'field_statement_3', jest.fn());
1111
test('field_4', 'field_statement_4', () => {
1212
vest.warn();
1313
throw new Error();

packages/vest/src/__tests__/integration.stateful-async.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { dummyTest } from '../../testUtils/testDummy';
44

55

66

7+
8+
79
const suite = ({ create, ...vest }) =>
810
create(({ skip, skipGroup }) => {
911
vest.skip(skip);

packages/vest/src/core/ctx.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default createContext<CTXType>((ctxRef, parentContext) =>
2020

2121
type CTXType = {
2222
stateRef?: ReturnType<typeof createStateRef>;
23-
exclusion?: {
23+
exclusion: {
2424
tests: Record<string, boolean>;
2525
groups: Record<string, boolean>;
2626
};

packages/vest/src/core/state/createStateRef.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import createState from 'vast';
23

34
import VestTest from 'VestTest';
@@ -13,9 +14,7 @@ export default function createStateRef(
1314
optionalFields: state.registerStateKey<Record<string, boolean>>(() => ({})),
1415
pending: state.registerStateKey<VestTest[]>(() => []),
1516
skippedTests: state.registerStateKey<VestTest[]>(() => []),
16-
suiteId: state.registerStateKey<{ id: string }>(() => ({
17-
id: suiteId,
18-
})),
17+
suiteId: state.registerStateKey<string>(() => suiteId),
1918
testCallbacks: state.registerStateKey<{
2019
fieldCallbacks: Record<string, Array<(res: TDraftResult) => void>>;
2120
doneCallbacks: Array<(res: TDraftResult) => void>;

0 commit comments

Comments
 (0)