Skip to content

Commit

Permalink
lint: handling lint of all packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Nov 10, 2021
1 parent b716282 commit ba68539
Show file tree
Hide file tree
Showing 55 changed files with 272 additions and 234 deletions.
21 changes: 17 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ module.exports = {
},
},
{
files: ['*.ts'],
excludedFiles: ['*__tests__/**/*.(t|j)s', './**/testUtils/**/*'],
excludedFiles: ['__tests__/**/*.(t|j)s', './**/testUtils/**/*'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/typescript',
],
files: ['*.ts'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
},
],
parser: '@typescript-eslint/parser',
Expand All @@ -58,7 +62,16 @@ module.exports = {
order: 'asc',
},
'newlines-between': 'always',
pathGroupsExcludedImportTypes: ['builtin'],
pathGroups: [
{
pattern: '^vx',
group: 'external',
},
{
pattern: './vx',
group: 'external',
},
],
},
],
'jest/expect-expect': 0,
Expand Down Expand Up @@ -96,7 +109,7 @@ module.exports = {
},
'import/resolver': {
typescript: {
project: 'packages/*/tsconfig.json',
project: './tsconfig.json',
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/anyone/src/exports/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import run from 'runAnyoneMethods';
/**
* Checks that at all passed arguments evaluate to a truthy value.
*/
export default function all(...args: any[]): boolean {
export default function all(...args: unknown[]): boolean {
return args.every(run);
}
2 changes: 1 addition & 1 deletion packages/anyone/src/exports/any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import run from 'runAnyoneMethods';
/**
* Checks that at least one passed argument evaluates to a truthy value.
*/
export default function any(...args: any[]): boolean {
export default function any(...args: unknown[]): boolean {
return args.some(run);
}
2 changes: 1 addition & 1 deletion packages/anyone/src/exports/none.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import run from 'runAnyoneMethods';
/**
* Checks that at none of the passed arguments evaluate to a truthy value.
*/
export default function none(...args: any[]): boolean {
export default function none(...args: unknown[]): boolean {
return args.every(bindNot(run));
}
2 changes: 1 addition & 1 deletion packages/anyone/src/exports/one.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import run from 'runAnyoneMethods';
/**
* Checks that at only one passed argument evaluates to a truthy value.
*/
export default function one(...args: any[]): boolean {
export default function one(...args: unknown[]): boolean {
let count = 0;

for (let i = 0; i < args.length; i++) {
Expand Down
5 changes: 3 additions & 2 deletions packages/anyone/src/runner/runAnyoneMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import isFunction from 'isFunction';
/**
* Accepts a value or a function, and coerces it into a boolean value
*/
export default function run(arg: any): boolean {
export default function run(arg: unknown): boolean {
if (isFunction(arg)) {
try {
return check(arg());
Expand All @@ -15,6 +15,7 @@ export default function run(arg: any): boolean {
return check(arg);
}

function check(value: any): boolean {
function check(value: unknown): boolean {
// We use abstract equality intentionally here. This enables falsy valueOf support.
return Array.isArray(value) ? true : value != false && Boolean(value); // eslint-disable-line
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ Object {
"bind": [Function],
"run": [Function],
"use": [Function],
"useX": [Function],
}
`;
30 changes: 22 additions & 8 deletions packages/context/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
import throwError from 'throwError';

export default function createContext<T extends Record<string, unknown>>(
init?: (ctxRef: T, parentContext: T | void) => T | null
init?: (ctxRef: Partial<T>, parentContext: T | void) => T | null
): {
run: <R>(ctxRef: T, fn: (context: T) => R) => R;
bind: <Fn extends (...args: any[]) => any>(ctxRef: T, fn: Fn) => Fn;
run: <R>(ctxRef: Partial<T>, fn: (context: T) => R) => R;
bind: <Fn extends (...args: any[]) => any>(ctxRef: Partial<T>, fn: Fn) => Fn;
use: () => T | undefined;
useX: (errorMessage?: string) => T;
} {
const storage: { ctx?: T; ancestry: T[] } = { ancestry: [] };

return {
run,
bind,
run,
use,
useX,
};

function run<R>(ctxRef: T, fn: (context: T) => R): R {
function useX(errorMessage?: string): T {
return (
storage.ctx ??
throwError(errorMessage ?? 'Context was used after it was closed')
);
}

function run<R>(ctxRef: Partial<T>, fn: (context: T) => R): R {
const parentContext = use();

const out = {
...(parentContext ? parentContext : {}),
...(init?.(ctxRef, parentContext) ?? ctxRef),
};
} as T;

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

function bind<Fn extends (...args: any[]) => any>(ctxRef: T, fn: Fn) {
// @ts-ignore - this one's pretty hard to get
function bind<Fn extends (...args: any[]) => any>(
ctxRef: Partial<T>,
fn: Fn
) {
// @ts-ignore - this one's pretty hard to get right
const returnedFn: Fn = function (...runTimeArgs: Parameters<Fn>) {
return run<ReturnType<Fn>>(ctxRef, function () {
return fn(...runTimeArgs);
Expand Down
7 changes: 5 additions & 2 deletions packages/n4s/src/lib/transformResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ function validateResult(result: TRuleReturn): void {
return;
}

// FIXME: Better error message
throwError('Incorrect return value for rule');
if (__DEV__) {
throwError('Incorrect return value for rule: ' + JSON.stringify(result));
} else {
throwError();
}
}

function getDefaultResult(value: TRuleValue): {
Expand Down
3 changes: 2 additions & 1 deletion packages/n4s/src/rules.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { isArray, isNotArray } from 'isArray';

import { endsWith, doesNotEndWith } from 'endsWith';
import { equals, notEquals } from 'equals';
import { greaterThan } from 'greaterThan';
import { greaterThanOrEquals } from 'greaterThanOrEquals';
import { inside, notInside } from 'inside';
import { isArray, isNotArray } from 'isArrayValue';
import { isBetween, isNotBetween } from 'isBetween';
import { isBlank, isNotBlank } from 'isBlank';
import { isBoolean, isNotBoolean } from 'isBoolean';
Expand All @@ -30,6 +30,7 @@ import { shorterThan } from 'shorterThan';
import { shorterThanOrEquals } from 'shorterThanOrEquals';
import { startsWith, doesNotStartWith } from 'startsWith';

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export default function rules() {
return {
doesNotEndWith,
Expand Down
2 changes: 1 addition & 1 deletion packages/n4s/src/rules/__tests__/isArray.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isArray } from 'isArray';
import { isArray } from 'isArrayValue';

describe('Tests isArray rule', () => {
it('Should return true for an empty array', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import bindNot from 'bindNot';

// The module is named "isArrayValue" since it
// is conflicting with a nested npm dependency.
// We may need to revisit this in the future.

export function isArray(value: unknown): value is Array<unknown> {
return Boolean(Array.isArray(value));
}
Expand Down
3 changes: 2 additions & 1 deletion packages/n4s/src/rules/isEven.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { isNumeric } from 'isNumeric';
import type { TRuleValue } from 'runtimeRules';

/**
* Validates that a given value is an even number
*/
export const isEven = (value: any): boolean => {
export const isEven = (value: TRuleValue): boolean => {
if (isNumeric(value)) {
return value % 2 === 0;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/n4s/src/rules/isOdd.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { isNumeric } from 'isNumeric';

import type { TRuleValue } from 'runtimeRules';
/**
* Validates that a given value is an odd number
*/
export const isOdd = (value: any): boolean => {
export const isOdd = (value: TRuleValue): boolean => {
if (isNumeric(value)) {
return value % 2 !== 0;
}
Expand Down
8 changes: 5 additions & 3 deletions packages/n4s/src/runtime/runtimeRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ export type TRule = Record<string, TRuleBase>;

const baseRules = rules();

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

export { baseRules, compounds, getRule };
8 changes: 4 additions & 4 deletions packages/shared/src/cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { isNotNull } from 'isNull';
import { lengthEquals } from 'lengthEquals';

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

/**
* @param {Any[]} deps dependency array.
* @param {any[]} deps dependency array.
* @param {Function} cache action function.
*/
const cache = <T>(
Expand All @@ -20,7 +19,8 @@ export default function createCache(maxSize = 10): {
): T => {
const cacheHit = cache.get(deps);

if (isNotNull(cacheHit)) {
// cache hit is not null
if (cacheHit) {
return cacheHit[1];
}

Expand All @@ -39,7 +39,7 @@ export default function createCache(maxSize = 10): {
* Retrieves an item from the cache.
* @param {deps} deps Dependency array
*/
cache.get = (deps: unknown[]): any =>
cache.get = (deps: unknown[]): [unknown[], any] | null =>
cacheStorage[
cacheStorage.findIndex(
([cachedDeps]) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/callEach.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function callEach(arr: Function[]): void {
export default function callEach(arr: ((...args: any[]) => any)[]): void {
return arr.forEach(fn => fn());
}
3 changes: 1 addition & 2 deletions packages/shared/src/isPromise.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import isFunction from 'isFunction';

export default function isPromise(value: unknown): value is Promise<unknown> {
// @ts-ignore - wasting time on something that works. I'll get back to it.
export default function isPromise(value: any): value is Promise<unknown> {
return value && isFunction(value.then);
}
2 changes: 1 addition & 1 deletion packages/shared/src/throwError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Throws a timed out error.
*/
export default function throwError(
message: string,
message?: string,
type: ErrorConstructor = Error
): never {
throw new type(message);
Expand Down
5 changes: 4 additions & 1 deletion packages/vast/src/vast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import optionalFunctionValue from 'optionalFunctionValue';

type TStateInput<S> = S | (() => S);
type TSetStateInput<S> = S | ((prevState: S) => S);
type TStateHandlerReturn<S> = [S, (nextState: TSetStateInput<S>) => void];
export type TStateHandlerReturn<S> = [
S,
(nextState: TSetStateInput<S>) => void
];

type TCreateStateReturn = {
reset: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function genValidate({ create, test, enforce, ...vest }) {
test('field_2', 'field_statement_2', () => {
enforce(2).equals(3);
});
test('field_3', 'field_statement_3', () => {});
test('field_3', 'field_statement_3', jest.fn());
test('field_4', 'field_statement_4', () => {
vest.warn();
throw new Error();
Expand Down
2 changes: 1 addition & 1 deletion packages/vest/src/__tests__/integration.base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const suite = ({ create, test, ...vest }) =>
test('field_2', 'field_statement_2', () => {
expect(2).toBe(3);
});
test('field_3', 'field_statement_3', () => {});
test('field_3', 'field_statement_3', jest.fn());
test('field_4', 'field_statement_4', () => {
vest.warn();
throw new Error();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { dummyTest } from '../../testUtils/testDummy';





const suite = ({ create, ...vest }) =>
create(({ skip, skipGroup }) => {
vest.skip(skip);
Expand Down
2 changes: 1 addition & 1 deletion packages/vest/src/core/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default createContext<CTXType>((ctxRef, parentContext) =>

type CTXType = {
stateRef?: ReturnType<typeof createStateRef>;
exclusion?: {
exclusion: {
tests: Record<string, boolean>;
groups: Record<string, boolean>;
};
Expand Down
5 changes: 2 additions & 3 deletions packages/vest/src/core/state/createStateRef.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import createState from 'vast';

import VestTest from 'VestTest';
Expand All @@ -13,9 +14,7 @@ export default function createStateRef(
optionalFields: state.registerStateKey<Record<string, boolean>>(() => ({})),
pending: state.registerStateKey<VestTest[]>(() => []),
skippedTests: state.registerStateKey<VestTest[]>(() => []),
suiteId: state.registerStateKey<{ id: string }>(() => ({
id: suiteId,
})),
suiteId: state.registerStateKey<string>(() => suiteId),
testCallbacks: state.registerStateKey<{
fieldCallbacks: Record<string, Array<(res: TDraftResult) => void>>;
doneCallbacks: Array<(res: TDraftResult) => void>;
Expand Down
Loading

0 comments on commit ba68539

Please sign in to comment.