Skip to content

Commit

Permalink
馃敡 Enable strict mode in tsconfig (#1521)
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Feb 17, 2021
1 parent 36e9be5 commit e67d542
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/check/arbitrary/AsyncSchedulerArbitrary.ts
Expand Up @@ -281,7 +281,7 @@ class SchedulerImplem<TMetaData> implements Scheduler<TMetaData> {
);
}

scheduleSequence(sequenceBuilders: SchedulerSequenceItem[]) {
scheduleSequence(sequenceBuilders: SchedulerSequenceItem<TMetaData>[]) {
// We run all the builders sequencially
// BUT we allow tasks scheduled outside of this sequence
// to be called between two of our builders
Expand Down
3 changes: 2 additions & 1 deletion src/check/arbitrary/RecordArbitrary.ts
Expand Up @@ -154,7 +154,8 @@ function record<T>(
if (requiredKeys.indexOf(k) !== -1) updatedRecordModel[k] = requiredArbitrary;
else updatedRecordModel[k] = option(requiredArbitrary);
}
return rawRecord(updatedRecordModel as any).map((obj: { [K in keyof T]: { value: T[keyof T] } | null }) => {
return rawRecord(updatedRecordModel as any).map((rawObj) => {
const obj = rawObj as { [K in keyof T]: { value: T[keyof T] } | null };
const nobj: { [K in keyof T]?: T[keyof T] } = {};
for (let index = 0; index !== keys.length; ++index) {
const k = keys[index];
Expand Down
2 changes: 1 addition & 1 deletion src/check/arbitrary/SubarrayArbitrary.ts
Expand Up @@ -37,7 +37,7 @@ class SubarrayArbitrary<T> extends Arbitrary<T[]> {
);
}
generate(mrng: Random): Shrinkable<T[]> {
const remainingElements = this.originalArray.map((v, idx) => idx);
const remainingElements = this.originalArray.map((_v, idx) => idx);
const size = this.lengthArb.generate(mrng).value;
const ids: number[] = [];
for (let idx = 0; idx !== size; ++idx) {
Expand Down
2 changes: 1 addition & 1 deletion src/check/model/ModelRunner.ts
Expand Up @@ -54,7 +54,7 @@ const internalModelRun = <Model extends object, Real>(
s: ModelRunSetup<Model, Real>,
cmds: Iterable<Command<Model, Real>>
): void => {
const then = (p: undefined, c: () => undefined) => c();
const then = (_p: undefined, c: () => undefined) => c();
const setupProducer: SetupProducer<Model, Real, undefined> = {
then: (fun: SetupFun<Model, Real, void>) => {
fun(s());
Expand Down
5 changes: 2 additions & 3 deletions src/check/runner/Runner.ts
Expand Up @@ -119,7 +119,7 @@ function check<Ts>(rawProperty: IRawProperty<Ts>, params?: Parameters<Ts>): unkn
if (rawProperty.run == null)
throw new Error('Invalid property encountered, please use a valid property not an arbitrary');
const qParams: QualifiedParameters<Ts> = QualifiedParameters.read<Ts>({
...readConfigureGlobal(),
...(readConfigureGlobal() as Parameters<Ts>),
...params,
});
if (qParams.reporter !== null && qParams.asyncReporter !== null)
Expand All @@ -135,12 +135,11 @@ function check<Ts>(rawProperty: IRawProperty<Ts>, params?: Parameters<Ts>): unkn
const sourceValues = new SourceValuesIterator(initialValues, maxInitialIterations, maxSkips);
return property.isAsync()
? asyncRunIt(property, sourceValues, qParams.verbose, qParams.markInterruptAsFailure).then((e) =>
e.toRunDetails(qParams.seed, qParams.path, qParams.numRuns, maxSkips, qParams)
e.toRunDetails(qParams.seed, qParams.path, maxSkips, qParams)
)
: runIt(property, sourceValues, qParams.verbose, qParams.markInterruptAsFailure).toRunDetails(
qParams.seed,
qParams.path,
qParams.numRuns,
maxSkips,
qParams
);
Expand Down
8 changes: 4 additions & 4 deletions src/check/runner/Sampler.ts
Expand Up @@ -28,8 +28,8 @@ function streamSample<Ts>(
): IterableIterator<Ts> {
const extendedParams =
typeof params === 'number'
? { ...readConfigureGlobal(), numRuns: params }
: { ...readConfigureGlobal(), ...params };
? { ...(readConfigureGlobal() as Parameters<Ts>), numRuns: params }
: { ...(readConfigureGlobal() as Parameters<Ts>), ...params };
const qParams: QualifiedParameters<Ts> = QualifiedParameters.read<Ts>(extendedParams);
const tossedValues: Stream<() => Shrinkable<Ts>> = stream(
toss(toProperty(generator, qParams), qParams.seed, qParams.randomType, qParams.examples)
Expand Down Expand Up @@ -97,8 +97,8 @@ function statistics<Ts>(
): void {
const extendedParams =
typeof params === 'number'
? { ...readConfigureGlobal(), numRuns: params }
: { ...readConfigureGlobal(), ...params };
? { ...(readConfigureGlobal() as Parameters<Ts>), numRuns: params }
: { ...(readConfigureGlobal() as Parameters<Ts>), ...params };
const qParams: QualifiedParameters<Ts> = QualifiedParameters.read<Ts>(extendedParams);
const recorded: { [key: string]: number } = {};
for (const g of streamSample(generator, params)) {
Expand Down
8 changes: 1 addition & 7 deletions src/check/runner/reporter/RunExecution.ts
Expand Up @@ -92,13 +92,7 @@ export class RunExecution<Ts> {
return [...offsetItems.slice(0, offsetItems.length - 1), `${middle}`, ...remainingItems.slice(1)].join(':');
};

toRunDetails(
seed: number,
basePath: string,
numRuns: number,
maxSkips: number,
qParams: QualifiedParameters<Ts>
): RunDetails<Ts> {
toRunDetails(seed: number, basePath: string, maxSkips: number, qParams: QualifiedParameters<Ts>): RunDetails<Ts> {
if (!this.isSuccess()) {
// encountered a property failure
return {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/Shadows.spec.ts
Expand Up @@ -151,7 +151,7 @@ const SpaceArbitrary = fc
.map(({ w, h, cx, cy, sx, sy }) =>
new SpaceBuilder().withDimension(w, h).withSolution(cx, cy).withCurrent(sx, sy).build()
)
.map((space: Space) => [space, Math.ceil(Math.log(Math.max(space.dimX, space.dimY)) / Math.log(2))]);
.map((space: Space): [Space, number] => [space, Math.ceil(Math.log(Math.max(space.dimX, space.dimY)) / Math.log(2))]);

// Test

Expand Down
Expand Up @@ -31,7 +31,7 @@ const validSparseArrayConstraints = () =>

describe('SparseArrayArbitrary', () => {
describe('sparseArray', () => {
genericHelper.isValidArbitrary((ct: SparseArrayConstraints) => sparseArray(nat(), ct), {
genericHelper.isValidArbitrary((ct: SparseArrayConstraints | undefined) => sparseArray(nat(), ct), {
seedGenerator: fc.option(validSparseArrayConstraints(), { nil: undefined }),
isEqual: (g1, g2) => {
// WARNING: Very long loops in Jest when comparing two very large sparse arrays
Expand Down
2 changes: 1 addition & 1 deletion test/unit/check/arbitrary/UuidArbitrary.itest.spec.ts
Expand Up @@ -11,7 +11,7 @@ describe('UuidArbitrary', () => {
});
describe('uuidV', () => {
genericHelper.isValidArbitrary((constraint: 1 | 2 | 3 | 4 | 5) => uuidV(constraint), {
seedGenerator: fc.constantFrom(1, 2, 3, 4, 5),
seedGenerator: fc.constantFrom(...([1, 2, 3, 4, 5] as const)),
isValidValue: (g: string, constraint: 1 | 2 | 3 | 4 | 5) =>
/[0-9a-f]{8}-[0-9a-f]{4}-[12345][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/.test(g) &&
g[14] === String(constraint),
Expand Down
10 changes: 5 additions & 5 deletions test/unit/check/arbitrary/generic/GenericArbitraryHelper.ts
Expand Up @@ -145,19 +145,19 @@ export const isValidArbitrary = function <U, T>(
},
parameters?: fc.Parameters<unknown>
): void {
const seedGenerator = settings.seedGenerator || fc.constant(undefined);
const seedGenerator = settings.seedGenerator || fc.constant((undefined as unknown) as U);

const biasedSeedGenerator = fc.tuple(fc.option(fc.integer(2, 100), { freq: 2 }), seedGenerator);
const biasedArbitraryBuilder = ([biasedFactor, u]: [number | null, U]) => {
return biasedFactor != null ? arbitraryBuilder(u).withBias(biasedFactor) : arbitraryBuilder(u);
};
const biasedIsValidValue = (g: T, [_biasedFactor, u]: [number | null, U]) => {
return settings.isValidValue(g, u);
return settings.isValidValue(g, u!);
};

const assertEquality = (v1: T, v2: T, [, seed]: [number, U]) => {
const assertEquality = (v1: T, v2: T, [, seed]: [number | null, U]) => {
if (settings.isEqual) {
if (!settings.isEqual(v1, v2, seed)) {
if (!settings.isEqual(v1, v2, seed!)) {
throw new Error(`Expect: ${fc.stringify(v1)} to be equal to ${fc.stringify(v2)}`);
}
} else expect(v1).toStrictEqual(v2);
Expand All @@ -167,7 +167,7 @@ export const isValidArbitrary = function <U, T>(
if (settings.isStrictlySmallerValue != null) {
const isStrictlySmallerValue = settings.isStrictlySmallerValue;
const biasedIsStrictlySmallerValue = (g1: T, g2: T, [_biasedFactor, u]: [number | null, U]) => {
return isStrictlySmallerValue(g1, g2, u);
return isStrictlySmallerValue(g1, g2, u!);
};
testShrinkPathStrictlyDecreasing(
biasedSeedGenerator,
Expand Down
14 changes: 4 additions & 10 deletions test/unit/check/runner/reporter/RunExecution.spec.ts
Expand Up @@ -30,7 +30,7 @@ describe('RunExecution', () => {
}
// Assert the value
const lastFailure = failuresDesc[failuresDesc.length - 1];
const details = run.toRunDetails(seed, '', 42, 10000, QualifiedParameters.read({}));
const details = run.toRunDetails(seed, '', 10000, QualifiedParameters.read({}));
expect(details.failed).toBe(true);
expect(details.interrupted).toBe(false);
expect(details.counterexamplePath).not.toBe(null);
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('RunExecution', () => {
run.fail(42, failureId, 'Failed');
}
// Assert the value
expect(run.toRunDetails(seed, '', 42, 10000, QualifiedParameters.read({})).counterexamplePath).toEqual(
expect(run.toRunDetails(seed, '', 10000, QualifiedParameters.read({})).counterexamplePath).toEqual(
path.join(':')
);
})
Expand All @@ -89,7 +89,7 @@ describe('RunExecution', () => {
joinedPath[offsetPath.length - 1] += addedPath[0];
// Assert the value
expect(
run.toRunDetails(seed, offsetPath.join(':'), 42, 10000, QualifiedParameters.read({})).counterexamplePath
run.toRunDetails(seed, offsetPath.join(':'), 10000, QualifiedParameters.read({})).counterexamplePath
).toEqual(joinedPath.join(':'));
}
)
Expand Down Expand Up @@ -123,13 +123,7 @@ describe('RunExecution', () => {
break;
}
}
const details = run.toRunDetails(
0,
'',
executionStatuses.length + 1,
executionStatuses.length + 1,
QualifiedParameters.read({})
);
const details = run.toRunDetails(0, '', executionStatuses.length + 1, QualifiedParameters.read({}));
let currentExecutionTrees = details.executionSummary;
for (let idx = 0, idxInTrees = 0; idx !== executionStatuses.length; ++idx, ++idxInTrees) {
// Ordered like execution: same value and status
Expand Down
19 changes: 8 additions & 11 deletions tsconfig.json
@@ -1,22 +1,19 @@
{
"compilerOptions": {
"incremental": true,
"declaration": true,
"sourceMap": true,
"alwaysStrict": true,
"noImplicitAny": true,
"noImplicitThis": true,
"importHelpers": false,
"incremental": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"removeComments": false,
"preserveConstEnums": true,
"strictNullChecks": true,
"removeComments": false,
"sourceMap": true,
"strict": true,
"stripInternal": true,
"downlevelIteration": true,
"importHelpers": false,
"lib": ["es2017", "es2019.Symbol"],
"module": "commonjs",
"target": "es2017",
"lib": ["es2017", "es2019.Symbol"],
"outDir": "lib/"
"outDir": "lib/",
},
"include": [
"src/**/*"
Expand Down

0 comments on commit e67d542

Please sign in to comment.